diff --git a/test/automation/src/sql/notebook.ts b/test/automation/src/sql/notebook.ts index 729688050f..5aaa257dd1 100644 --- a/test/automation/src/sql/notebook.ts +++ b/test/automation/src/sql/notebook.ts @@ -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 { + async focusSearchResultsView(): Promise { return this.quickAccess.runCommand('Notebooks: Focus on Search Results View'); } + async focusNotebooksView(): Promise { + return this.quickAccess.runCommand('Notebooks: Focus on Notebooks View'); + } + + async focusPinnedNotebooksView(): Promise { + return this.quickAccess.runCommand('Notebooks: Focus on Pinned notebooks View'); + } + async searchInNotebook(expr: string): Promise { 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 { const textArea = `${NotebookView.inputBox} textarea`; await this.code.waitForTypeInEditor(textArea, text); } + + /** + * Helper function + * @returns tree item ids from Notebooks View + */ + async getNotebookTreeItemIds(): Promise { + return (await this.code.waitForElements(NotebookView.notebookTreeItem, false)).map(item => item.attributes['id']); + } + + /** + * Pin the first notebook in the Notebooks View + */ + async pinNotebook(): Promise { + 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 { + 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 { + await this.code.waitForElement(NotebookView.pinnedNotebooksSelector); + } } diff --git a/test/smoke/src/sql/areas/notebook/notebookView.test.ts b/test/smoke/src/sql/areas/notebook/notebookView.test.ts index 7cc536cf5a..ab42ce59c2 100644 --- a/test/smoke/src/sql/areas/notebook/notebookView.test.ts +++ b/test/smoke/src/sql/areas/notebook/notebookView.test.ts @@ -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)); });