From 3cedac620fd42f06c032ae3a34afb36b421aa05d Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 2 Oct 2017 21:43:43 +0200 Subject: [PATCH] smoke: fix dataloss tests --- test/smoke/src/areas/editor/editor.ts | 60 +++++++++++-------- .../src/areas/workbench/data-loss.test.ts | 29 ++++----- .../areas/workbench/data-migration.test.ts | 12 ++-- 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/test/smoke/src/areas/editor/editor.ts b/test/smoke/src/areas/editor/editor.ts index e79fc5a3011..5c81f8f47bd 100644 --- a/test/smoke/src/areas/editor/editor.ts +++ b/test/smoke/src/areas/editor/editor.ts @@ -93,6 +93,18 @@ export class Editor { await this.spectron.client.waitAndClick(selector); } + public async waitForTypeInEditor(filename: string, text: string): Promise { + const editor = `.monaco-editor[data-uri$="${filename}"]`; + await this.spectron.client.waitAndClick(editor); + + const textarea = `${editor} textarea`; + await this.spectron.client.waitForActiveElement(textarea); + + await this.spectron.client.type(text); + + await this.waitForEditorContents(filename, c => c.indexOf(text) > -1); + } + public async waitForEditorContents(filename: string, accept: (contents: string) => boolean): Promise { const selector = `.monaco-editor[data-uri$="${filename}"] .view-lines`; return this.spectron.client.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' '))); @@ -103,35 +115,35 @@ export class Editor { return this.spectron.client.waitForActiveElement(selector); } - public async waitForActiveEditorFirstLineText(filename: string): Promise { - const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`; - const result = await this.spectron.client.waitFor( - () => this.spectron.client.spectron.client.execute(s => { - if (!document.activeElement.matches(s)) { - return undefined; - } + // public async waitForActiveEditorFirstLineText(filename: string): Promise { + // const selector = `.editor-container .monaco-editor[data-uri$="${filename}"] textarea`; + // const result = await this.spectron.client.waitFor( + // () => this.spectron.client.spectron.client.execute(s => { + // if (!document.activeElement.matches(s)) { + // return undefined; + // } - let element: Element | null = document.activeElement; - while (element && !/monaco-editor/.test(element.className) && element !== document.body) { - element = element.parentElement; - } + // let element: Element | null = document.activeElement; + // while (element && !/monaco-editor/.test(element.className) && element !== document.body) { + // element = element.parentElement; + // } - if (element && /monaco-editor/.test(element.className)) { - const firstLine = element.querySelector('.view-lines span span:nth-child(1)'); + // if (element && /monaco-editor/.test(element.className)) { + // const firstLine = element.querySelector('.view-lines span span:nth-child(1)'); - if (firstLine) { - return (firstLine.textContent || '').replace(/\u00a0/g, ' '); // DAMN - } - } + // if (firstLine) { + // return (firstLine.textContent || '').replace(/\u00a0/g, ' '); // DAMN + // } + // } - return undefined; - }, selector), - r => typeof r.value === 'string', - `wait for active editor first line: ${selector}` - ); + // return undefined; + // }, selector), + // r => typeof r.value === 'string', + // `wait for active editor first line: ${selector}` + // ); - return result.value; - } + // return result.value; + // } private async getClassSelectors(term: string, viewline: number): Promise { const result: { text: string, className: string }[] = await this.spectron.webclient.selectorExecute(`${Editor.VIEW_LINES}>:nth-child(${viewline}) span span`, diff --git a/test/smoke/src/areas/workbench/data-loss.test.ts b/test/smoke/src/areas/workbench/data-loss.test.ts index aa33283753e..d270deaeef7 100644 --- a/test/smoke/src/areas/workbench/data-loss.test.ts +++ b/test/smoke/src/areas/workbench/data-loss.test.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; import { SpectronApplication } from '../../spectron/application'; describe('Dataloss', () => { @@ -13,27 +12,29 @@ describe('Dataloss', () => { beforeEach(function () { app.screenCapturer.testName = this.currentTest.title; }); it(`verifies that 'hot exit' works for dirty files`, async function () { - const textToType = 'Hello, Code', textToTypeInUntitled = 'Hello, Unitled Code', fileName = 'readme.md', untitled = 'Untitled-1'; await app.workbench.newUntitledFile(); - await app.client.type(textToTypeInUntitled); + + const untitled = 'Untitled-1'; + const textToTypeInUntitled = 'Hello, Unitled Code'; + await app.workbench.editor.waitForTypeInEditor(untitled, textToTypeInUntitled); await app.screenCapturer.capture('Untitled file before reload'); - await app.workbench.explorer.openFile(fileName); - await app.client.type(textToType); - await app.screenCapturer.capture(`${fileName} before reload`); - await app.screenCapturer.capture('Before reload'); + + const readmeMd = 'readme.md'; + const textToType = 'Hello, Code'; + await app.workbench.explorer.openFile(readmeMd); + await app.workbench.editor.waitForTypeInEditor(readmeMd, textToType); + await app.screenCapturer.capture(`${readmeMd} before reload`); await app.reload(); await app.screenCapturer.capture('After reload'); - await app.workbench.waitForActiveTab(fileName, true); - await app.screenCapturer.capture(`${fileName} after reload`); - let actual = await app.workbench.editor.waitForActiveEditorFirstLineText(fileName); - assert.ok(actual.startsWith(textToType), `'${actual}' did not start with '${textToType}'`); + await app.workbench.waitForActiveTab(readmeMd, true); + await app.screenCapturer.capture(`${readmeMd} after reload`); + await app.workbench.editor.waitForEditorContents(readmeMd, c => c.indexOf(textToType) > -1); await app.workbench.waitForTab(untitled, true); - await app.workbench.selectTab('Untitled-1', true); + await app.workbench.selectTab(untitled, true); await app.screenCapturer.capture('Untitled file after reload'); - actual = await app.workbench.editor.waitForActiveEditorFirstLineText('Untitled-1'); - assert.ok(actual.startsWith(textToTypeInUntitled), `'${actual}' did not start with '${textToTypeInUntitled}'`); + await app.workbench.editor.waitForEditorContents(untitled, c => c.indexOf(textToTypeInUntitled) > -1); }); }); \ No newline at end of file diff --git a/test/smoke/src/areas/workbench/data-migration.test.ts b/test/smoke/src/areas/workbench/data-migration.test.ts index 3e2c44674f7..ad8a0a8460c 100644 --- a/test/smoke/src/areas/workbench/data-migration.test.ts +++ b/test/smoke/src/areas/workbench/data-migration.test.ts @@ -19,14 +19,14 @@ describe('Data Migration', () => { it('checks if the Untitled file is restored migrating from stable to latest', async function () { const textToType = 'Very dirty file'; - console.log(STABLE_PATH); + // Setting up stable version let app = new SpectronApplication(STABLE_PATH); await app.start('Data Migration'); app.screenCapturer.testName = 'Untitled is restorted'; await app.workbench.newUntitledFile(); - await app.client.type(textToType); + await app.workbench.editor.waitForTypeInEditor('Untitled-1', textToType); await app.stop(); await app.wait(.5); // wait until all resources are released (e.g. locked local storage) @@ -37,9 +37,9 @@ describe('Data Migration', () => { app.screenCapturer.testName = 'Untitled is restorted'; assert.ok(await app.workbench.waitForActiveTab('Untitled-1', true), `Untitled-1 tab is not present after migration.`); - const actual = await app.workbench.editor.waitForActiveEditorFirstLineText('Untitled-1'); + + await app.workbench.editor.waitForEditorContents('Untitled-1', c => c.indexOf(textToType) > -1); await app.screenCapturer.capture('Untitled file text'); - assert.ok(actual.startsWith(textToType), `${actual} did not start with ${textToType}`); }); it('checks if the newly created dirty file is restored migrating from stable to latest', async function () { @@ -67,9 +67,7 @@ describe('Data Migration', () => { const filename = fileName.split('/')[1]; assert.ok(await app.workbench.waitForActiveTab(filename), `Untitled-1 tab is not present after migration.`); - const actual = await app.workbench.editor.waitForActiveEditorFirstLineText(filename); - await app.screenCapturer.capture(fileName + ' text'); - assert.ok(actual.startsWith(firstTextPart.concat(secondTextPart)), `${actual} did not start with ${firstTextPart.concat(secondTextPart)}`); + await app.workbench.editor.waitForEditorContents(filename, c => c.indexOf(firstTextPart + secondTextPart) > -1); await Util.removeFile(`${fileName}`); });