diff --git a/scripts/test-smoke.bat b/scripts/test-smoke.bat new file mode 100644 index 0000000000..f4eb84be87 --- /dev/null +++ b/scripts/test-smoke.bat @@ -0,0 +1,10 @@ +@echo off +setlocal + +pushd "%~dp0\..\test\smoke" + +node test\index.js %* + +popd + +endlocal diff --git a/scripts/test-smoke.sh b/scripts/test-smoke.sh new file mode 100644 index 0000000000..0c60e9c6e0 --- /dev/null +++ b/scripts/test-smoke.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +if [[ "$OSTYPE" == "darwin"* ]]; then + realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; } + ROOT=$(dirname $(dirname $(realpath "$0"))) +else + ROOT=$(dirname $(dirname $(readlink -f $0))) +fi + +cd $ROOT/test/smoke + +node test/index.js "$@" diff --git a/test/smoke/src/areas/workbench/workbench.ts b/test/smoke/src/areas/workbench/workbench.ts index d5fe2e63ef..1c35f4cb2e 100644 --- a/test/smoke/src/areas/workbench/workbench.ts +++ b/test/smoke/src/areas/workbench/workbench.ts @@ -23,6 +23,7 @@ import { Terminal } from '../terminal/terminal'; // {{SQL CARBON EDIT}} import { ConnectionDialog } from '../../sql/connectionDialog/connectionDialog'; import { Profiler } from '../../sql/profiler/profiler'; +import { QueryEditors } from '../../sql/queryEditor/queryEditors'; // {{END}} export interface Commands { @@ -50,6 +51,7 @@ export class Workbench { // {{SQL CARBON EDIT}} readonly connectionDialog: ConnectionDialog; readonly profiler: Profiler; + readonly queryEditors: QueryEditors; // {{END}} constructor(code: Code, userDataPath: string) { @@ -71,6 +73,7 @@ export class Workbench { // {{SQL CARBON EDIT}} this.connectionDialog = new ConnectionDialog(code); this.profiler = new Profiler(code, this.quickopen); + this.queryEditors = new QueryEditors(code, this.quickopen); // {{END}} } } diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index b687c067ba..6d683c4841 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -15,6 +15,8 @@ import { Application, Quality, ApplicationOptions } from './application'; //{{SQL CARBON EDIT}} import { setup as runProfilerTests } from './sql/profiler/profiler.test'; +import { setup as runQueryEditorTests } from './sql/queryEditor/queryEditor.test'; + //Original /* import { setup as setupDataMigrationTests } from './areas/workbench/data-migration.test'; @@ -283,6 +285,7 @@ describe('Running Code', () => { //{{SQL CARBON EDIT}} runProfilerTests(); + runQueryEditorTests(); //Original /* setupDataLossTests(); diff --git a/test/smoke/src/sql/queryEditor/queryEditor.test.ts b/test/smoke/src/sql/queryEditor/queryEditor.test.ts new file mode 100644 index 0000000000..e2b6130234 --- /dev/null +++ b/test/smoke/src/sql/queryEditor/queryEditor.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 { Application } from '../../application'; +import * as fs from 'fs'; +import * as os from 'os'; +import * as path from 'path'; + +export function setup() { + describe('Query Editor Test Suite', () => { + + it('Can open and edit existing file', async function () { + const testFilePath = path.join(os.tmpdir(), 'QueryEditorSmokeTest.sql'); + fs.writeFileSync(testFilePath, ''); + try { + const app = this.app as Application; + await app.workbench.queryEditors.openFile(testFilePath); + const fileBaseName = path.basename(testFilePath); + await app.workbench.editor.waitForTypeInEditor(fileBaseName, 'SELECT * FROM sys.tables'); + } + finally { + fs.unlinkSync(testFilePath); + } + }); + }); +} \ No newline at end of file diff --git a/test/smoke/src/sql/queryEditor/queryEditors.ts b/test/smoke/src/sql/queryEditor/queryEditors.ts new file mode 100644 index 0000000000..72b0fb5f68 --- /dev/null +++ b/test/smoke/src/sql/queryEditor/queryEditors.ts @@ -0,0 +1,54 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Editors } from '../../areas/editor/editors'; +import { QuickOpen } from '../../areas/quickopen/quickopen'; +import { Code } from '../../vscode/code'; +import * as path from 'path'; + +export class QueryEditors extends Editors { + + constructor( + private vsCode: Code, + private quickopen: QuickOpen + ) { + super(vsCode); + } + + /** + * Opens the specified file - this correctly handles SQL files which are opened in a Query Editor window + * @param filePath The full path of the file to open. + */ + async openFile(filePath: string): Promise { + await this.quickopen.openQuickOpen(filePath); + + const fileBaseName = path.basename(filePath); + await this.quickopen.waitForQuickOpenElements(names => names[0] === fileBaseName); + await this.vsCode.dispatchKeybinding('enter'); + await this.waitForEditorFocus(fileBaseName); + } + + /** + * Waits for an active SQL Query Editor tab for the specified file. This is a modification of the editors.waitForActiveTab that + * takes into account the connected status displayed in the title of Query Editors. + * @param fileName The name of the file opened in the editor + * @param isDirty Whether the file is dirty or not + */ + async waitForActiveTab(fileName: string, isDirty: boolean = false): Promise { + // For now assume all opened tabs are disconnected until we have a need to open connected tabs + await this.vsCode.waitForElement(`.tabs-container div.tab.active${isDirty ? '.dirty' : ''}[aria-selected="true"][aria-label="${fileName} - disconnected, tab"]`); + } + + + /** + * Waits for an active Query Editor for the specified file to have focus. This is a modification of the editors.waitForEditorFocus + * that takes into account the connected status displayed in the title of Query Editors. + * @param fileName The name of the file opened in the editor + */ + async waitForEditorFocus(fileName: string): Promise { + await this.waitForActiveTab(fileName); + await super.waitForActiveEditor(fileName); + } +}