From 0be402be817524441e80d280fb1ab14c43ca3861 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Tue, 13 Mar 2018 23:08:07 +0900 Subject: [PATCH] Rewrite tests with async/await --- test/specs/app_test.js | 110 +++---- test/specs/browser/index_test.js | 218 +++++++------- test/specs/browser/settings_test.js | 429 +++++++++++++--------------- 3 files changed, 349 insertions(+), 408 deletions(-) diff --git a/test/specs/app_test.js b/test/specs/app_test.js index 48fd75ee..2afde4f2 100644 --- a/test/specs/app_test.js +++ b/test/specs/app_test.js @@ -14,99 +14,83 @@ describe('application', function desc() { return this.app.start(); }); - afterEach(() => { + afterEach(async () => { if (this.app && this.app.isRunning()) { - return this.app.stop(); + await this.app.stop(); } - return true; }); - it('should show a window', () => { - return this.app.client. - waitUntilWindowLoaded(). - getWindowCount().then((count) => { - count.should.equal(1); - }). - browserWindow.isDevToolsOpened().then((opened) => { - opened.should.be.false; - }). - browserWindow.isVisible().then((visible) => { - visible.should.be.true; - }); + it('should show a window', async () => { + await this.app.client.waitUntilWindowLoaded(); + const count = await this.app.client.getWindowCount(); + count.should.equal(1); + + const opened = await this.app.browserWindow.isDevToolsOpened(); + opened.should.be.false; + + const visible = await this.app.browserWindow.isVisible(); + visible.should.be.true; }); - it.skip('should restore window bounds', () => { + it.skip('should restore window bounds', async () => { // bounds seems to be incorrectly calculated in some environments // - Windows 10: OK // - CircleCI: NG const expectedBounds = {x: 100, y: 200, width: 300, height: 400}; fs.writeFileSync(env.boundsInfoPath, JSON.stringify(expectedBounds)); - return this.app.restart().then(() => { - return this.app.browserWindow.getBounds(); - }).then((bounds) => { - bounds.should.deep.equal(expectedBounds); - }); + await this.app.restart(); + const bounds = await this.app.browserWindow.getBounds(); + bounds.should.deep.equal(expectedBounds); }); - it('should NOT restore window bounds if the origin is located on outside of viewarea', () => { + it('should NOT restore window bounds if the origin is located on outside of viewarea', async () => { // bounds seems to be incorrectly calculated in some environments (e.g. CircleCI) // - Windows 10: OK // - CircleCI: NG fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: -100000, y: 200, width: 300, height: 400})); - return this.app.restart().then(() => { - return this.app.browserWindow.getBounds(); - }).then((bounds) => { - bounds.x.should.satisfy((x) => (x > -10000)); - }).then(() => { - fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: 100, y: 200000, width: 300, height: 400})); - return this.app.restart(); - }).then(() => { - return this.app.browserWindow.getBounds(); - }).then((bounds) => { - bounds.y.should.satisfy((y) => (y < 10000)); - }); + await this.app.restart(); + let bounds = await this.app.browserWindow.getBounds(); + bounds.x.should.satisfy((x) => (x > -10000)); + + fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: 100, y: 200000, width: 300, height: 400})); + await this.app.restart(); + bounds = await this.app.browserWindow.getBounds(); + bounds.y.should.satisfy((y) => (y < 10000)); }); - it('should show settings.html when there is no config file', () => { - return this.app.client. - waitUntilWindowLoaded(). - getUrl().then((url) => { - url.should.match(/\/settings.html$/); - }). - isExisting('#newServerModal').then((existing) => { - existing.should.equal(true); - }); + it('should show settings.html when there is no config file', async () => { + await this.app.client.waitUntilWindowLoaded(); + const url = await this.app.client.getUrl(); + url.should.match(/\/settings.html$/); + + const existing = await this.app.client.isExisting('#newServerModal'); + existing.should.equal(true); }); - it('should show index.html when there is config file', () => { + it('should show index.html when there is config file', async () => { fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL, })); - return this.app.restart().then(() => { - return this.app.client.waitUntilWindowLoaded(); - }).then(() => { - return this.app.client.getUrl(); - }).then((url) => { - url.should.match(/\/index.html$/); - }); + await this.app.restart(); + await this.app.client.waitUntilWindowLoaded(); + const url = await this.app.client.getUrl(); + url.should.match(/\/index.html$/); }); - it('should upgrade v0 config file', () => { + it('should upgrade v0 config file', async () => { const settings = require('../../src/common/settings'); fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL, })); - return this.app.restart().then(() => { - return this.app.client.waitUntilWindowLoaded(); - }).then(() => { - return this.app.client.getUrl(); - }).then((url) => { - url.should.match(/\/index.html$/); - }).then(() => { - var str = fs.readFileSync(env.configFilePath, 'utf8'); - var config = JSON.parse(str); - config.version.should.equal(settings.version); - }); + await this.app.restart(); + await this.app.client.waitUntilWindowLoaded(); + + const url = await this.app.client.getUrl(); + url.should.match(/\/index.html$/); + + const str = fs.readFileSync(env.configFilePath, 'utf8'); + const config = JSON.parse(str); + config.version.should.equal(settings.version); }); it.skip('should be stopped when the app instance already exists', (done) => { diff --git a/test/specs/browser/index_test.js b/test/specs/browser/index_test.js index dace9384..8215ef66 100644 --- a/test/specs/browser/index_test.js +++ b/test/specs/browser/index_test.js @@ -38,50 +38,48 @@ describe('browser/index.html', function desc() { return this.app.start(); }); - afterEach(() => { + afterEach(async () => { if (this.app && this.app.isRunning()) { - return this.app.stop(); + await this.app.stop(); } - return true; }); after((done) => { this.server.close(done); }); - it('should NOT show tabs when there is one team', () => { + it('should NOT show tabs when there is one team', async () => { fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL, })); - return this.app.restart().then(() => { - return this.app.client.waitUntilWindowLoaded(). - isExisting('#tabBar').then((existing) => { - existing.should.be.false; - }); - }); + await this.app.restart(); + await this.app.client.waitUntilWindowLoaded(); + + const existing = await this.app.client.isExisting('#tabBar'); + existing.should.be.false; }); - it('should set src of webview from config file', () => { - return this.app.client.waitUntilWindowLoaded(). - getAttribute('#mattermostView0', 'src').then((src) => { - src.should.equal(config.teams[0].url); - }). - getAttribute('#mattermostView1', 'src').then((src) => { - src.should.equal(config.teams[1].url); - }). - isExisting('#mattermostView2').then((existing) => { - existing.should.be.false; - }); + it('should set src of webview from config file', async () => { + await this.app.client.waitUntilWindowLoaded(); + + const src0 = await this.app.client.getAttribute('#mattermostView0', 'src'); + src0.should.equal(config.teams[0].url); + + const src1 = await this.app.client.getAttribute('#mattermostView1', 'src'); + src1.should.equal(config.teams[1].url); + + const existing = await this.app.client.isExisting('#mattermostView2'); + existing.should.be.false; }); - it('should set name of tab from config file', () => { - return this.app.client.waitUntilWindowLoaded(). - getText('#teamTabItem0').then((text) => { - text.should.equal(config.teams[0].name); - }). - getText('#teamTabItem1').then((text) => { - text.should.equal(config.teams[1].name); - }); + it('should set name of tab from config file', async () => { + await this.app.client.waitUntilWindowLoaded(); + + const tabName0 = await this.app.client.getText('#teamTabItem0'); + tabName0.should.equal(config.teams[0].name); + + const tabName1 = await this.app.client.getText('#teamTabItem1'); + tabName1.should.equal(config.teams[1].name); }); it('should show only the selected team', () => { @@ -93,7 +91,7 @@ describe('browser/index.html', function desc() { waitForVisible('#mattermostView0', 2000, true); }); - it('should show error when using incorrect URL', () => { + it('should show error when using incorrect URL', async () => { this.timeout(30000); fs.writeFileSync(env.configFilePath, JSON.stringify({ version: 1, @@ -102,13 +100,12 @@ describe('browser/index.html', function desc() { url: 'http://false', }], })); - return this.app.restart().then(() => { - return this.app.client.waitUntilWindowLoaded(). - waitForVisible('#mattermostView0-fail', 20000); - }); + await this.app.restart(); + return this.app.client.waitUntilWindowLoaded(). + waitForVisible('#mattermostView0-fail', 20000); }); - it('should set window title by using webview\'s one', () => { + it('should set window title by using webview\'s one', async () => { fs.writeFileSync(env.configFilePath, JSON.stringify({ version: 1, teams: [{ @@ -116,17 +113,14 @@ describe('browser/index.html', function desc() { url: `http://localhost:${serverPort}`, }], })); - return this.app.restart().then(() => { - return this.app.client.waitUntilWindowLoaded().pause(2000); - }).then(() => { - return this.app.browserWindow.getTitle(); - }).then((title) => { - title.should.equal('Mattermost Desktop testing html'); - }); + await this.app.restart(); + await this.app.client.waitUntilWindowLoaded().pause(2000); + const windowTitle = await this.app.browserWindow.getTitle(); + windowTitle.should.equal('Mattermost Desktop testing html'); }); // Skip because it's very unstable in CI - it.skip('should update window title when the activated tab\'s title is updated', () => { + it.skip('should update window title when the activated tab\'s title is updated', async () => { fs.writeFileSync(env.configFilePath, JSON.stringify({ version: 1, teams: [{ @@ -137,79 +131,73 @@ describe('browser/index.html', function desc() { url: `http://localhost:${serverPort}`, }], })); - return this.app.restart().then(() => { - return this.app.client.waitUntilWindowLoaded().pause(500); - }).then(() => { - // Note: Indices of webview are correct. - // Somehow they are swapped. - return this.app.client. - windowByIndex(2). - execute(() => { - document.title = 'Title 0'; - }). - windowByIndex(0). - pause(500). - browserWindow.getTitle().then((title) => { - title.should.equal('Title 0'); - }). - windowByIndex(1). - execute(() => { - document.title = 'Title 1'; - }). - windowByIndex(0). - pause(500). - browserWindow.getTitle().then((title) => { - title.should.equal('Title 0'); - }); - }); - }); + await this.app.restart(); + await this.app.client.waitUntilWindowLoaded().pause(500); - // Skip because it's very unstable in CI - it.skip('should update window title when a tab is selected', () => { - fs.writeFileSync(env.configFilePath, JSON.stringify({ - version: 1, - teams: [{ - name: 'title_test_0', - url: `http://localhost:${serverPort}`, - }, { - name: 'title_test_1', - url: `http://localhost:${serverPort}`, - }], - })); - return this.app.restart().then(() => { - // Note: Indices of webview are correct. - // Somehow they are swapped. - return this.app.client. - waitUntilWindowLoaded(). - pause(500). - windowByIndex(2). - execute(() => { - document.title = 'Title 0'; - }). - windowByIndex(1). - execute(() => { - document.title = 'Title 1'; - }). - windowByIndex(0). - pause(500). - browserWindow.getTitle().then((title) => { - title.should.equal('Title 0'); - }). - click('#teamTabItem1'). - pause(500). - browserWindow.getTitle().then((title) => { - title.should.equal('Title 1'); - }); - }); - }); - - it('should open the new server prompt after clicking the add button', () => { - // See settings_test for specs that cover the actual prompt - return this.app.client.waitUntilWindowLoaded(). - click('#addServerButton'). - pause(500). - isExisting('#newServerModal').then((existing) => { - existing.should.be.true; + // Note: Indices of webview are correct. + // Somehow they are swapped. + await this.app.client. + windowByIndex(2). + execute(() => { + document.title = 'Title 0'; }); + await this.app.client.windowByIndex(0).pause(500); + let windowTitle = await this.app.browserWindow.getTitle(); + windowTitle.should.equal('Title 0'); + + await this.app.client. + windowByIndex(1). + execute(() => { + document.title = 'Title 1'; + }); + await this.app.client.windowByIndex(0).pause(500); + windowTitle = await this.app.browserWindow.getTitle(); + windowTitle.should.equal('Title 0'); + }); + + // Skip because it's very unstable in CI + it.skip('should update window title when a tab is selected', async () => { + fs.writeFileSync(env.configFilePath, JSON.stringify({ + version: 1, + teams: [{ + name: 'title_test_0', + url: `http://localhost:${serverPort}`, + }, { + name: 'title_test_1', + url: `http://localhost:${serverPort}`, + }], + })); + await this.app.restart(); + + // Note: Indices of webview are correct. + // Somehow they are swapped. + await this.app.client.waitUntilWindowLoaded().pause(500); + + await this.app.client. + windowByIndex(2). + execute(() => { + document.title = 'Title 0'; + }); + await this.app.client. + windowByIndex(1). + execute(() => { + document.title = 'Title 1'; + }); + await this.app.client.windowByIndex(0).pause(500); + + let windowTitle = await this.app.browserWindow.getTitle(); + windowTitle.should.equal('Title 0'); + + await this.app.client.click('#teamTabItem1').pause(500); + windowTitle = await this.app.browserWindow.getTitle(); + windowTitle.should.equal('Title 1'); + }); + + it('should open the new server prompt after clicking the add button', async () => { + // See settings_test for specs that cover the actual prompt + await this.app.client.waitUntilWindowLoaded(); + await this.app.client.click('#addServerButton').pause(500); + const isModalExisting = await this.app.client.isExisting('#newServerModal'); + isModalExisting.should.be.true; }); }); diff --git a/test/specs/browser/settings_test.js b/test/specs/browser/settings_test.js index a17f420a..bd75204b 100644 --- a/test/specs/browser/settings_test.js +++ b/test/specs/browser/settings_test.js @@ -24,57 +24,54 @@ describe('browser/settings.html', function desc() { return this.app.start(); }); - afterEach(() => { + afterEach(async () => { if (this.app && this.app.isRunning()) { - return this.app.stop(); + await this.app.stop(); } - return true; }); - describe('Close button', () => { - it('should show index.html when it\'s clicked', () => { + describe('Close button', async () => { + it('should show index.html when it\'s clicked', async () => { env.addClientCommands(this.app.client); - return this.app.client. + await this.app.client. loadSettingsPage(). click('#btnClose'). - pause(1000). - getUrl().then((url) => { - url.should.match(/\/index.html(\?.+)?$/); - }); + pause(1000); + const url = await this.app.client.getUrl(); + url.should.match(/\/index.html(\?.+)?$/); }); - it('should be disabled when the number of servers is zero', () => { - return this.app.stop().then(() => { - env.cleanTestConfig(); - return this.app.start(); - }).then(() => { - return this.app.client.waitUntilWindowLoaded(). - waitForVisible('#newServerModal'). - click('#cancelNewServerModal'). - isEnabled('#btnClose').then((enabled) => { - enabled.should.equal(false); - }). - waitForVisible('#newServerModal', true). - pause(250). - click('#addNewServer'). - waitForVisible('#newServerModal'). - setValue('#teamNameInput', 'TestTeam'). - setValue('#teamUrlInput', 'http://example.org'). - click('#saveNewServerModal'). - waitForVisible('#newServerModal', true). - waitForVisible('#serversSaveIndicator'). - waitForVisible('#serversSaveIndicator', 10000, true). // at least 2500 ms to disappear - isEnabled('#btnClose').then((enabled) => { - enabled.should.equal(true); - }); - }); + it('should be disabled when the number of servers is zero', async () => { + await this.app.stop(); + env.cleanTestConfig(); + await this.app.start(); + + await this.app.client.waitUntilWindowLoaded(). + waitForVisible('#newServerModal'). + click('#cancelNewServerModal'); + let isCloseButtonEnabled = await this.app.client.isEnabled('#btnClose'); + isCloseButtonEnabled.should.equal(false); + + await this.app.client. + waitForVisible('#newServerModal', true). + pause(250). + click('#addNewServer'). + waitForVisible('#newServerModal'). + setValue('#teamNameInput', 'TestTeam'). + setValue('#teamUrlInput', 'http://example.org'). + click('#saveNewServerModal'). + waitForVisible('#newServerModal', true). + waitForVisible('#serversSaveIndicator'). + waitForVisible('#serversSaveIndicator', 10000, true); // at least 2500 ms to disappear + isCloseButtonEnabled = await this.app.client.isEnabled('#btnClose'); + isCloseButtonEnabled.should.equal(true); }); }); - it('should show NewServerModal after all servers are removed', () => { + it('should show NewServerModal after all servers are removed', async () => { const modalTitleSelector = '.modal-title=Remove Server'; env.addClientCommands(this.app.client); - return this.app.client. + await this.app.client. loadSettingsPage(). click('=Remove'). waitForVisible(modalTitleSelector). @@ -83,228 +80,205 @@ describe('browser/settings.html', function desc() { click('=Remove'). waitForVisible(modalTitleSelector). element('.modal-dialog').click('.btn=Remove'). - pause(500). - isExisting('#newServerModal').then((existing) => { - existing.should.be.true; - }); + pause(500); + const isModalExisting = await this.app.client.isExisting('#newServerModal'); + isModalExisting.should.be.true; }); describe('Server list', () => { - it('should open the corresponding tab when a server list item is clicked', () => { + it('should open the corresponding tab when a server list item is clicked', async () => { env.addClientCommands(this.app.client); - return this.app.client. + await this.app.client. loadSettingsPage(). click('h4=example'). pause(1000). - waitUntilWindowLoaded(). - getUrl().then((url) => { - url.should.match(/\/index.html(\?.+)?$/); - }). - isVisible('#mattermostView0').then((visible) => { - visible.should.be.true; - }). - isVisible('#mattermostView1').then((visible) => { - visible.should.be.false; - }). + waitUntilWindowLoaded(); + let indexURL = await this.app.client.getUrl(); + indexURL.should.match(/\/index.html(\?.+)?$/); + let isView0Visible = await this.app.client.isVisible('#mattermostView0'); + isView0Visible.should.be.true; + + let isView1Visible = await this.app.client.isVisible('#mattermostView1'); + isView1Visible.should.be.false; + + await this.app.client. loadSettingsPage(). click('h4=github'). pause(1000). - waitUntilWindowLoaded(). - getUrl().then((url) => { - url.should.match(/\/index.html(\?.+)?$/); - }). - isVisible('#mattermostView0').then((visible) => { - visible.should.be.false; - }). - isVisible('#mattermostView1').then((visible) => { - visible.should.be.true; - }); + waitUntilWindowLoaded(); + indexURL = await this.app.client.getUrl(); + indexURL.should.match(/\/index.html(\?.+)?$/); + + isView0Visible = await this.app.client.isVisible('#mattermostView0'); + isView0Visible.should.be.false; + + isView1Visible = await this.app.client.isVisible('#mattermostView1'); + isView1Visible.should.be.true; }); }); describe('Options', () => { describe.skip('Hide Menu Bar', () => { - it('should appear on win32 or linux', () => { + it('should appear on win32 or linux', async () => { const expected = (process.platform === 'win32' || process.platform === 'linux'); env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputHideMenuBar').then((existing) => { - existing.should.equal(expected); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputHideMenuBar'); + existing.should.equal(expected); }); [true, false].forEach((v) => { - env.shouldTest(it, env.isOneOf(['win32', 'linux']))(`should be saved and loaded: ${v}`, () => { + env.shouldTest(it, env.isOneOf(['win32', 'linux']))(`should be saved and loaded: ${v}`, async () => { env.addClientCommands(this.app.client); - return this.app.client. + await this.app.client. loadSettingsPage(). - scroll('#inputHideMenuBar'). - isSelected('#inputHideMenuBar').then((isSelected) => { - if (isSelected !== v) { - return this.app.client.click('#inputHideMenuBar'); - } - return true; - }). + scroll('#inputHideMenuBar'); + const isSelected = await this.app.client.isSelected('#inputHideMenuBar'); + if (isSelected !== v) { + await this.app.client.click('#inputHideMenuBar'); + } + + await this.app.client. pause(600). click('#btnClose'). - pause(1000).then(() => { - const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); - savedConfig.hideMenuBar.should.equal(v); - }). - browserWindow.isMenuBarAutoHide().then((autoHide) => { - autoHide.should.equal(v); - }).then(() => { // confirm actual behavior - return this.app.restart(); - }).then(() => { - env.addClientCommands(this.app.client); - return this.app.client. // confirm actual behavior - browserWindow.isMenuBarAutoHide().then((autoHide) => { - autoHide.should.equal(v); - }). - loadSettingsPage(). - isSelected('#inputHideMenuBar').then((autoHide) => { - autoHide.should.equal(v); - }); - }); + pause(1000); + + const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); + savedConfig.hideMenuBar.should.equal(v); + + let autoHide = await this.app.browserWindow.isMenuBarAutoHide(); + autoHide.should.equal(v); + + // confirm actual behavior + await this.app.restart(); + env.addClientCommands(this.app.client); + + autoHide = await this.app.browserWindow.isMenuBarAutoHide(); + autoHide.should.equal(v); + + await this.app.loadSettingsPage(); + autoHide = await this.app.client.isSelected('#inputHideMenuBar'); + autoHide.should.equal(v); }); }); }); describe('Start app on login', () => { - it('should appear on win32 or linux', () => { + it('should appear on win32 or linux', async () => { const expected = (process.platform === 'win32' || process.platform === 'linux'); env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputAutoStart').then((existing) => { - existing.should.equal(expected); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputAutoStart'); + existing.should.equal(expected); }); }); describe('Show icon in menu bar / notification area', () => { - it('should appear on darwin or linux', () => { + it('should appear on darwin or linux', async () => { const expected = (process.platform === 'darwin' || process.platform === 'linux'); env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputShowTrayIcon').then((existing) => { - existing.should.equal(expected); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputShowTrayIcon'); + existing.should.equal(expected); }); describe('Save tray icon setting on mac', () => { - env.shouldTest(it, env.isOneOf(['darwin', 'linux']))('should be saved when it\'s selected', () => { + env.shouldTest(it, env.isOneOf(['darwin', 'linux']))('should be saved when it\'s selected', async () => { env.addClientCommands(this.app.client); - return this.app.client. + await this.app.client. loadSettingsPage(). click('#inputShowTrayIcon'). - waitForAppOptionsAutoSaved(). - then(() => { - const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); - config0.showTrayIcon.should.true; - return this.app.client; - }). + waitForAppOptionsAutoSaved(); + + let config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); + config0.showTrayIcon.should.true; + + await this.app.client. click('#inputShowTrayIcon'). - waitForAppOptionsAutoSaved(). - then(() => { - const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); - config0.showTrayIcon.should.false; - }); + waitForAppOptionsAutoSaved(); + + config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); + config0.showTrayIcon.should.false; }); }); describe('Save tray icon theme on linux', () => { - env.shouldTest(it, process.platform === 'linux')('should be saved when it\'s selected', () => { + env.shouldTest(it, process.platform === 'linux')('should be saved when it\'s selected', async () => { env.addClientCommands(this.app.client); - return this.app.client. + await this.app.client. loadSettingsPage(). click('#inputShowTrayIcon'). click('input[value="light"]'). - pause(700). // wait auto-save - then(() => { - const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); - config0.trayIconTheme.should.equal('light'); - return this.app.client; - }). + pause(700); // wait auto-save + + const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); + config0.trayIconTheme.should.equal('light'); + + await this.app.client. click('input[value="dark"]'). - pause(700). // wait auto-save - then(() => { - const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); - config1.trayIconTheme.should.equal('dark'); - }); + pause(700); // wait auto-save + + const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); + config1.trayIconTheme.should.equal('dark'); }); }); }); describe('Leave app running in notification area when application window is closed', () => { - it('should appear on linux', () => { + it('should appear on linux', async () => { const expected = (process.platform === 'linux'); env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputMinimizeToTray').then((existing) => { - existing.should.equal(expected); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputMinimizeToTray'); + existing.should.equal(expected); }); }); describe.skip('Toggle window visibility when clicking on the tray icon', () => { - it('should appear on win32', () => { + it('should appear on win32', async () => { const expected = (process.platform === 'win32'); env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputToggleWindowOnTrayIconClick').then((existing) => { - existing.should.equal(expected); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputToggleWindowOnTrayIconClick'); + existing.should.equal(expected); }); }); describe('Flash app window and taskbar icon when a new message is received', () => { - it('should appear on win32 and linux', () => { + it('should appear on win32 and linux', async () => { const expected = (process.platform === 'win32' || process.platform === 'linux'); env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputflashWindow').then((existing) => { - existing.should.equal(expected); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputflashWindow'); + existing.should.equal(expected); }); }); describe('Show red badge on taskbar icon to indicate unread messages', () => { - it('should appear on darwin or win32', () => { + it('should appear on darwin or win32', async () => { const expected = (process.platform === 'darwin' || process.platform === 'win32'); env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputShowUnreadBadge').then((existing) => { - existing.should.equal(expected); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputShowUnreadBadge'); + existing.should.equal(expected); }); }); describe('Check spelling', () => { - it('should appear and be selectable', () => { + it('should appear and be selectable', async () => { env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting('#inputSpellChecker').then((existing) => { - existing.should.equal(true); - }). - scroll('#inputSpellChecker'). - isSelected('#inputSpellChecker').then((selected) => { - selected.should.equal(true); - }). - click('#inputSpellChecker'). - pause(700). - then(() => { - const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); - config1.useSpellChecker.should.equal(false); - }); + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting('#inputSpellChecker'); + existing.should.equal(true); + + await this.app.client.scroll('#inputSpellChecker'); + const selected = await this.app.client.isSelected('#inputSpellChecker'); + selected.should.equal(true); + + await this.app.client.click('#inputSpellChecker').pause(700); + const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); + config1.useSpellChecker.should.equal(false); }); }); }); @@ -312,66 +286,64 @@ describe('browser/settings.html', function desc() { describe('RemoveServerModal', () => { const modalTitleSelector = '.modal-title=Remove Server'; - beforeEach(() => { + beforeEach(async () => { env.addClientCommands(this.app.client); - return this.app.client. - loadSettingsPage(). - isExisting(modalTitleSelector).then((existing) => { - existing.should.be.false; - }). - isVisible(modalTitleSelector).then((visible) => { - visible.should.be.false; - }). + await this.app.client.loadSettingsPage(); + const existing = await this.app.client.isExisting(modalTitleSelector); + existing.should.be.false; + + const visible = await this.app.client.isVisible(modalTitleSelector); + visible.should.be.false; + + await this.app.client. click('=Remove'). waitForVisible(modalTitleSelector); }); - it('should remove existing team on click Remove', (done) => { - this.app.client. + it('should remove existing team on click Remove', async () => { + await this.app.client. element('.modal-dialog').click('.btn=Remove'). - pause(500). - isExisting(modalTitleSelector).then((existing) => { - existing.should.be.false; - }). + pause(500); + const existing = await this.app.client.isExisting(modalTitleSelector); + existing.should.be.false; + + await this.app.client. click('#btnClose'). - pause(500).then(() => { - const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); - savedConfig.teams.should.deep.equal(config.teams.slice(1)); - done(); - }); + pause(500); + + const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); + savedConfig.teams.should.deep.equal(config.teams.slice(1)); }); - it('should NOT remove existing team on click Cancel', (done) => { - this.app.client. + it('should NOT remove existing team on click Cancel', async () => { + await this.app.client. element('.modal-dialog').click('.btn=Cancel'). - pause(500). - isExisting(modalTitleSelector).then((existing) => { - existing.should.be.false; - }). + pause(500); + const existing = await this.app.client.isExisting(modalTitleSelector); + existing.should.be.false; + + await this.app.client. click('#btnClose'). - pause(500).then(() => { - const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); - savedConfig.teams.should.deep.equal(config.teams); - done(); - }); + pause(500); + + const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); + savedConfig.teams.should.deep.equal(config.teams); }); - it('should disappear on click Close', () => { - return this.app.client. + it('should disappear on click Close', async () => { + await this.app.client. click('.modal-dialog button.close'). - pause(500). - isExisting(modalTitleSelector).then((existing) => { - existing.should.be.false; - }); + pause(500); + const existing = await this.app.client.isExisting(modalTitleSelector); + existing.should.be.false; }); - it('should disappear on click background', () => { - return this.app.client. + it('should disappear on click background', async () => { + await this.app.client. click('body'). - pause(500). - isExisting(modalTitleSelector).then((existing) => { - existing.should.be.false; - }); + pause(500); + const existing = await this.app.client.isExisting(modalTitleSelector); + existing.should.be.false; }); }); @@ -484,22 +456,19 @@ describe('browser/settings.html', function desc() { }); }); - it('should add the team to the config file', (done) => { - this.app.client. + it('should add the team to the config file', async () => { + await this.app.client. click('#saveNewServerModal'). waitForVisible('#newServerModal', true). waitForVisible('#serversSaveIndicator'). waitForVisible('#serversSaveIndicator', 10000, true). // at least 2500 ms to disappear - waitUntilWindowLoaded().then(() => { - const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); - savedConfig.teams.should.deep.contain({ - name: 'TestTeam', - url: 'http://example.org', - }); - done(); - }).catch((err) => { - done(err); - }); + waitUntilWindowLoaded(); + + const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); + savedConfig.teams.should.deep.contain({ + name: 'TestTeam', + url: 'http://example.org', + }); }); }); });