Pin and unpin notebook smoke test (#15936)

* add pin/unpin smoketest

* fix simple search query assert
This commit is contained in:
Barbara Valdez
2021-06-30 22:14:18 -07:00
committed by GitHub
parent 7cf7ca5d15
commit a6644333c0
2 changed files with 64 additions and 8 deletions

View File

@@ -316,26 +316,70 @@ export class NotebookToolbar {
export class NotebookView {
private static readonly inputBox = '.notebookExplorer-viewlet .search-widget .input-box';
private static actualResult = '.search-view .result-messages';
private static searchResult = '.search-view .result-messages';
private static notebookTreeItem = '.split-view-view .tree-explorer-viewlet-tree-view .monaco-list-row';
private static selectedItem = '.focused.selected';
private static pinnedNotebooksSelector = '.split-view-view .tree-explorer-viewlet-tree-view .monaco-list[aria-label="Pinned notebooks"] .monaco-list-row';
constructor(private code: Code, private quickAccess: QuickAccess) { }
async focus(): Promise<void> {
async focusSearchResultsView(): Promise<void> {
return this.quickAccess.runCommand('Notebooks: Focus on Search Results View');
}
async focusNotebooksView(): Promise<void> {
return this.quickAccess.runCommand('Notebooks: Focus on Notebooks View');
}
async focusPinnedNotebooksView(): Promise<void> {
return this.quickAccess.runCommand('Notebooks: Focus on Pinned notebooks View');
}
async searchInNotebook(expr: string): Promise<IElement> {
await this.waitForSetSearchValue(expr);
await this.code.dispatchKeybinding('enter');
let selector = `${NotebookView.actualResult} `;
let selector = NotebookView.searchResult;
if (expr) {
selector += '.message';
selector += ' .message';
}
return await this.code.waitForElement(selector, undefined);
return this.code.waitForElement(selector, undefined);
}
async waitForSetSearchValue(text: string): Promise<void> {
const textArea = `${NotebookView.inputBox} textarea`;
await this.code.waitForTypeInEditor(textArea, text);
}
/**
* Helper function
* @returns tree item ids from Notebooks View
*/
async getNotebookTreeItemIds(): Promise<string[]> {
return (await this.code.waitForElements(NotebookView.notebookTreeItem, false)).map(item => item.attributes['id']);
}
/**
* Pin the first notebook in the Notebooks View
*/
async pinNotebook(): Promise<void> {
const notebookIds = await this.getNotebookTreeItemIds();
await this.code.waitAndDoubleClick(`${NotebookView.notebookTreeItem}[id="${notebookIds[0]}"]`);
await this.code.waitAndClick(`${NotebookView.notebookTreeItem}${NotebookView.selectedItem} .codicon-pinned`);
}
/**
* Unpin the only pinned notebook.
* Previously pinned by the pinNotebook method.
*/
async unpinNotebook(): Promise<void> {
await this.code.waitAndClick(NotebookView.pinnedNotebooksSelector);
await this.code.waitAndClick(`${NotebookView.pinnedNotebooksSelector} .actions a[title="Unpin Notebook"]`);
}
/**
* When pinning a notebook, the pinned notebook view will show.
*/
async waitForPinnedNotebookView(): Promise<void> {
await this.code.waitForElement(NotebookView.pinnedNotebooksSelector);
}
}

View File

@@ -8,19 +8,31 @@ import { Application } from '../../../../../automation';
export function setup() {
describe('NotebookView', () => {
it('Pin a notebook', async function () {
const app = this.app as Application;
await app.workbench.sqlNotebook.view.focusNotebooksView();
await app.workbench.sqlNotebook.view.pinNotebook();
await app.workbench.sqlNotebook.view.waitForPinnedNotebookView();
});
it('Unpin Notebook', async function () {
const app = this.app as Application;
await app.workbench.sqlNotebook.view.focusPinnedNotebooksView();
await app.workbench.sqlNotebook.view.unpinNotebook();
});
it('No search results if search query is empty', async function () {
const app = this.app as Application;
await app.workbench.sqlNotebook.view.focus();
await app.workbench.sqlNotebook.view.focusSearchResultsView();
const results = await app.workbench.sqlNotebook.view.searchInNotebook('');
assert(results.children !== undefined && results.children.length === 0);
});
it('Simple query search works correctly', async function () {
const app = this.app as Application;
await app.workbench.sqlNotebook.view.focus();
await app.workbench.sqlNotebook.view.focusSearchResultsView();
// Adding a regex expression to not depend on specific results of files
const regexExpr = /[0-9]+( results in )[0-9]+( files)/;
const regexExpr = /[0-9]+( results? in )[0-9]+( files?)/;
const results = await app.workbench.sqlNotebook.view.searchInNotebook('hello');
assert(results.textContent !== '' && results.textContent.match(regexExpr));
});