From 15f7b12849e012a4a686e9936c22b521b73658a2 Mon Sep 17 00:00:00 2001 From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com> Date: Thu, 25 Mar 2021 12:43:55 -0700 Subject: [PATCH] Search smoke tests (#13469) * Add smoke test * add simple tests for searching in notebooks view * address pr comments * address pr comments * add search smoke tests to separate file * remove span from selector --- test/automation/src/sql/notebook.ts | 28 +++++++++++++++++++ .../sql/areas/notebook/notebookView.test.ts | 28 +++++++++++++++++++ test/smoke/src/sql/main.ts | 2 ++ 3 files changed, 58 insertions(+) create mode 100644 test/smoke/src/sql/areas/notebook/notebookView.test.ts diff --git a/test/automation/src/sql/notebook.ts b/test/automation/src/sql/notebook.ts index 0283c3425a..608efb61b5 100644 --- a/test/automation/src/sql/notebook.ts +++ b/test/automation/src/sql/notebook.ts @@ -14,9 +14,11 @@ const winOrCtrl = process.platform === 'darwin' ? 'ctrl' : 'win'; export class Notebook { public readonly toolbar: NotebookToolbar; + public readonly view: NotebookView; constructor(private code: Code, private quickAccess: QuickAccess, private quickInput: QuickInput, private editors: Editors) { this.toolbar = new NotebookToolbar(code); + this.view = new NotebookView(code, quickAccess); } async openFile(fileName: string): Promise { @@ -194,3 +196,29 @@ export class NotebookToolbar { await this.code.waitForElement(NotebookToolbar.notTrustedButtonSelector); } } + +export class NotebookView { + private static readonly inputBox = '.notebookExplorer-viewlet .search-widget .input-box'; + private static actualResult = '.search-view .result-messages'; + + constructor(private code: Code, private quickAccess: QuickAccess) { } + + async focus(): Promise { + return this.quickAccess.runCommand('Notebooks: Focus on Search Results View'); + } + + async searchInNotebook(expr: string): Promise { + await this.waitForSetSearchValue(expr); + await this.code.dispatchKeybinding('enter'); + let selector = `${NotebookView.actualResult} `; + if (expr) { + selector += '.message'; + } + return await this.code.waitForElement(selector, undefined); + } + + async waitForSetSearchValue(text: string): Promise { + const textArea = `${NotebookView.inputBox} textarea`; + await this.code.waitForTypeInEditor(textArea, text); + } +} diff --git a/test/smoke/src/sql/areas/notebook/notebookView.test.ts b/test/smoke/src/sql/areas/notebook/notebookView.test.ts new file mode 100644 index 0000000000..7cc536cf5a --- /dev/null +++ b/test/smoke/src/sql/areas/notebook/notebookView.test.ts @@ -0,0 +1,28 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { assert } from 'console'; +import { Application } from '../../../../../automation'; + +export function setup() { + describe('NotebookView', () => { + + it('No search results if search query is empty', async function () { + const app = this.app as Application; + await app.workbench.sqlNotebook.view.focus(); + 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(); + // Adding a regex expression to not depend on specific results of 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)); + }); + }); +} diff --git a/test/smoke/src/sql/main.ts b/test/smoke/src/sql/main.ts index 4a2fbe1f54..208167da1a 100644 --- a/test/smoke/src/sql/main.ts +++ b/test/smoke/src/sql/main.ts @@ -5,6 +5,7 @@ import { setup as setupQueryEditorTests, setupWeb as setupQueryEditorWebTests } from './areas/queryEditor/queryEditor.test'; import { setup as setupNotebookTests } from './areas/notebook/notebook.test'; +import { setup as setupNotebookViewTests } from './areas/notebook/notebookView.test'; import { ApplicationOptions } from '../../../automation'; import * as yazl from 'yauzl'; import * as fs from 'fs'; @@ -19,6 +20,7 @@ export function main(isWeb: boolean = false): void { setupQueryEditorTests(); } setupNotebookTests(); + setupNotebookViewTests(); } /* eslint-disable no-sync */