Merge pull request #730 from yuya-oc/async-test

Rewrite tests with async/await
This commit is contained in:
Yuya Ochiai 2018-03-15 23:50:44 +09:00 committed by GitHub
commit d23a244509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 351 additions and 410 deletions

View file

@ -1,6 +1,6 @@
machine: machine:
node: node:
version: 6.11.3 version: 8.2.0
dependencies: dependencies:
cache_directories: cache_directories:

View file

@ -5,7 +5,7 @@
### Prerequisites ### Prerequisites
- C++ environment which supports C++11 (e.g. VS 2015, Xcode, GCC) - C++ environment which supports C++11 (e.g. VS 2015, Xcode, GCC)
- Python 2.7 - Python 2.7
- Node.js 4.2.0 or later - Node.js 8.2.0 or later
- Yarn - Yarn
- Git - Git

View file

@ -14,100 +14,84 @@ describe('application', function desc() {
return this.app.start(); return this.app.start();
}); });
afterEach(() => { afterEach(async () => {
if (this.app && this.app.isRunning()) { if (this.app && this.app.isRunning()) {
return this.app.stop(); await this.app.stop();
} }
return true;
}); });
it('should show a window', () => { it('should show a window', async () => {
return this.app.client. await this.app.client.waitUntilWindowLoaded();
waitUntilWindowLoaded(). const count = await this.app.client.getWindowCount();
getWindowCount().then((count) => {
count.should.equal(1); count.should.equal(1);
}).
browserWindow.isDevToolsOpened().then((opened) => { const opened = await this.app.browserWindow.isDevToolsOpened();
opened.should.be.false; opened.should.be.false;
}).
browserWindow.isVisible().then((visible) => { const visible = await this.app.browserWindow.isVisible();
visible.should.be.true; 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 // bounds seems to be incorrectly calculated in some environments
// - Windows 10: OK // - Windows 10: OK
// - CircleCI: NG // - CircleCI: NG
const expectedBounds = {x: 100, y: 200, width: 300, height: 400}; const expectedBounds = {x: 100, y: 200, width: 300, height: 400};
fs.writeFileSync(env.boundsInfoPath, JSON.stringify(expectedBounds)); fs.writeFileSync(env.boundsInfoPath, JSON.stringify(expectedBounds));
return this.app.restart().then(() => { await this.app.restart();
return this.app.browserWindow.getBounds(); const bounds = await this.app.browserWindow.getBounds();
}).then((bounds) => {
bounds.should.deep.equal(expectedBounds); 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) // bounds seems to be incorrectly calculated in some environments (e.g. CircleCI)
// - Windows 10: OK // - Windows 10: OK
// - CircleCI: NG // - CircleCI: NG
fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: -100000, y: 200, width: 300, height: 400})); fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: -100000, y: 200, width: 300, height: 400}));
return this.app.restart().then(() => { await this.app.restart();
return this.app.browserWindow.getBounds(); let bounds = await this.app.browserWindow.getBounds();
}).then((bounds) => {
bounds.x.should.satisfy((x) => (x > -10000)); bounds.x.should.satisfy((x) => (x > -10000));
}).then(() => {
fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: 100, y: 200000, width: 300, height: 400})); fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: 100, y: 200000, width: 300, height: 400}));
return this.app.restart(); await this.app.restart();
}).then(() => { bounds = await this.app.browserWindow.getBounds();
return this.app.browserWindow.getBounds();
}).then((bounds) => {
bounds.y.should.satisfy((y) => (y < 10000)); bounds.y.should.satisfy((y) => (y < 10000));
}); });
});
it('should show settings.html when there is no config file', () => { it('should show settings.html when there is no config file', async () => {
return this.app.client. await this.app.client.waitUntilWindowLoaded();
waitUntilWindowLoaded(). const url = await this.app.client.getUrl();
getUrl().then((url) => {
url.should.match(/\/settings.html$/); url.should.match(/\/settings.html$/);
}).
isExisting('#newServerModal').then((existing) => { const existing = await this.app.client.isExisting('#newServerModal');
existing.should.equal(true); 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({ fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL, url: env.mattermostURL,
})); }));
return this.app.restart().then(() => { await this.app.restart();
return this.app.client.waitUntilWindowLoaded(); await this.app.client.waitUntilWindowLoaded();
}).then(() => { const url = await this.app.client.getUrl();
return this.app.client.getUrl();
}).then((url) => {
url.should.match(/\/index.html$/); url.should.match(/\/index.html$/);
}); });
});
it('should upgrade v0 config file', () => { it('should upgrade v0 config file', async () => {
const settings = require('../../src/common/settings'); const settings = require('../../src/common/settings');
fs.writeFileSync(env.configFilePath, JSON.stringify({ fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL, url: env.mattermostURL,
})); }));
return this.app.restart().then(() => { await this.app.restart();
return this.app.client.waitUntilWindowLoaded(); await this.app.client.waitUntilWindowLoaded();
}).then(() => {
return this.app.client.getUrl(); const url = await this.app.client.getUrl();
}).then((url) => {
url.should.match(/\/index.html$/); url.should.match(/\/index.html$/);
}).then(() => {
var str = fs.readFileSync(env.configFilePath, 'utf8'); const str = fs.readFileSync(env.configFilePath, 'utf8');
var config = JSON.parse(str); const config = JSON.parse(str);
config.version.should.equal(settings.version); config.version.should.equal(settings.version);
}); });
});
it.skip('should be stopped when the app instance already exists', (done) => { it.skip('should be stopped when the app instance already exists', (done) => {
const secondApp = env.getSpectronApp(); const secondApp = env.getSpectronApp();

View file

@ -38,50 +38,48 @@ describe('browser/index.html', function desc() {
return this.app.start(); return this.app.start();
}); });
afterEach(() => { afterEach(async () => {
if (this.app && this.app.isRunning()) { if (this.app && this.app.isRunning()) {
return this.app.stop(); await this.app.stop();
} }
return true;
}); });
after((done) => { after((done) => {
this.server.close(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({ fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL, url: env.mattermostURL,
})); }));
return this.app.restart().then(() => { await this.app.restart();
return this.app.client.waitUntilWindowLoaded(). await this.app.client.waitUntilWindowLoaded();
isExisting('#tabBar').then((existing) => {
const existing = await this.app.client.isExisting('#tabBar');
existing.should.be.false; existing.should.be.false;
}); });
});
});
it('should set src of webview from config file', () => { it('should set src of webview from config file', async () => {
return this.app.client.waitUntilWindowLoaded(). await this.app.client.waitUntilWindowLoaded();
getAttribute('#mattermostView0', 'src').then((src) => {
src.should.equal(config.teams[0].url); const src0 = await this.app.client.getAttribute('#mattermostView0', 'src');
}). src0.should.equal(config.teams[0].url);
getAttribute('#mattermostView1', 'src').then((src) => {
src.should.equal(config.teams[1].url); const src1 = await this.app.client.getAttribute('#mattermostView1', 'src');
}). src1.should.equal(config.teams[1].url);
isExisting('#mattermostView2').then((existing) => {
const existing = await this.app.client.isExisting('#mattermostView2');
existing.should.be.false; existing.should.be.false;
}); });
});
it('should set name of tab from config file', () => { it('should set name of tab from config file', async () => {
return this.app.client.waitUntilWindowLoaded(). await this.app.client.waitUntilWindowLoaded();
getText('#teamTabItem0').then((text) => {
text.should.equal(config.teams[0].name); const tabName0 = await this.app.client.getText('#teamTabItem0');
}). tabName0.should.equal(config.teams[0].name);
getText('#teamTabItem1').then((text) => {
text.should.equal(config.teams[1].name); const tabName1 = await this.app.client.getText('#teamTabItem1');
}); tabName1.should.equal(config.teams[1].name);
}); });
it('should show only the selected team', () => { it('should show only the selected team', () => {
@ -93,7 +91,7 @@ describe('browser/index.html', function desc() {
waitForVisible('#mattermostView0', 2000, true); waitForVisible('#mattermostView0', 2000, true);
}); });
it('should show error when using incorrect URL', () => { it('should show error when using incorrect URL', async () => {
this.timeout(30000); this.timeout(30000);
fs.writeFileSync(env.configFilePath, JSON.stringify({ fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1, version: 1,
@ -102,13 +100,12 @@ describe('browser/index.html', function desc() {
url: 'http://false', url: 'http://false',
}], }],
})); }));
return this.app.restart().then(() => { await this.app.restart();
return this.app.client.waitUntilWindowLoaded(). return this.app.client.waitUntilWindowLoaded().
waitForVisible('#mattermostView0-fail', 20000); 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({ fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1, version: 1,
teams: [{ teams: [{
@ -116,17 +113,14 @@ describe('browser/index.html', function desc() {
url: `http://localhost:${serverPort}`, url: `http://localhost:${serverPort}`,
}], }],
})); }));
return this.app.restart().then(() => { await this.app.restart();
return this.app.client.waitUntilWindowLoaded().pause(2000); await this.app.client.waitUntilWindowLoaded().pause(2000);
}).then(() => { const windowTitle = await this.app.browserWindow.getTitle();
return this.app.browserWindow.getTitle(); windowTitle.should.equal('Mattermost Desktop testing html');
}).then((title) => {
title.should.equal('Mattermost Desktop testing html');
});
}); });
// Skip because it's very unstable in CI // 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({ fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1, version: 1,
teams: [{ teams: [{
@ -137,35 +131,32 @@ describe('browser/index.html', function desc() {
url: `http://localhost:${serverPort}`, url: `http://localhost:${serverPort}`,
}], }],
})); }));
return this.app.restart().then(() => { await this.app.restart();
return this.app.client.waitUntilWindowLoaded().pause(500); await this.app.client.waitUntilWindowLoaded().pause(500);
}).then(() => {
// Note: Indices of webview are correct. // Note: Indices of webview are correct.
// Somehow they are swapped. // Somehow they are swapped.
return this.app.client. await this.app.client.
windowByIndex(2). windowByIndex(2).
execute(() => { execute(() => {
document.title = 'Title 0'; document.title = 'Title 0';
}). });
windowByIndex(0). await this.app.client.windowByIndex(0).pause(500);
pause(500). let windowTitle = await this.app.browserWindow.getTitle();
browserWindow.getTitle().then((title) => { windowTitle.should.equal('Title 0');
title.should.equal('Title 0');
}). await this.app.client.
windowByIndex(1). windowByIndex(1).
execute(() => { execute(() => {
document.title = 'Title 1'; document.title = 'Title 1';
}).
windowByIndex(0).
pause(500).
browserWindow.getTitle().then((title) => {
title.should.equal('Title 0');
});
}); });
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 // Skip because it's very unstable in CI
it.skip('should update window title when a tab is selected', () => { it.skip('should update window title when a tab is selected', async () => {
fs.writeFileSync(env.configFilePath, JSON.stringify({ fs.writeFileSync(env.configFilePath, JSON.stringify({
version: 1, version: 1,
teams: [{ teams: [{
@ -176,40 +167,37 @@ describe('browser/index.html', function desc() {
url: `http://localhost:${serverPort}`, url: `http://localhost:${serverPort}`,
}], }],
})); }));
return this.app.restart().then(() => { await this.app.restart();
// Note: Indices of webview are correct. // Note: Indices of webview are correct.
// Somehow they are swapped. // Somehow they are swapped.
return this.app.client. await this.app.client.waitUntilWindowLoaded().pause(500);
waitUntilWindowLoaded().
pause(500). await this.app.client.
windowByIndex(2). windowByIndex(2).
execute(() => { execute(() => {
document.title = 'Title 0'; document.title = 'Title 0';
}). });
await this.app.client.
windowByIndex(1). windowByIndex(1).
execute(() => { execute(() => {
document.title = 'Title 1'; 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');
});
}); });
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', () => { it('should open the new server prompt after clicking the add button', async () => {
// See settings_test for specs that cover the actual prompt // See settings_test for specs that cover the actual prompt
return this.app.client.waitUntilWindowLoaded(). await this.app.client.waitUntilWindowLoaded();
click('#addServerButton'). await this.app.client.click('#addServerButton').pause(500);
pause(500). const isModalExisting = await this.app.client.isExisting('#newServerModal');
isExisting('#newServerModal').then((existing) => { isModalExisting.should.be.true;
existing.should.be.true;
});
}); });
}); });

View file

@ -24,36 +24,35 @@ describe('browser/settings.html', function desc() {
return this.app.start(); return this.app.start();
}); });
afterEach(() => { afterEach(async () => {
if (this.app && this.app.isRunning()) { if (this.app && this.app.isRunning()) {
return this.app.stop(); await this.app.stop();
} }
return true;
}); });
describe('Close button', () => { describe('Close button', async () => {
it('should show index.html when it\'s clicked', () => { it('should show index.html when it\'s clicked', async () => {
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.
loadSettingsPage(). loadSettingsPage().
click('#btnClose'). click('#btnClose').
pause(1000). pause(1000);
getUrl().then((url) => { const url = await this.app.client.getUrl();
url.should.match(/\/index.html(\?.+)?$/); url.should.match(/\/index.html(\?.+)?$/);
}); });
});
it('should be disabled when the number of servers is zero', () => { it('should be disabled when the number of servers is zero', async () => {
return this.app.stop().then(() => { await this.app.stop();
env.cleanTestConfig(); env.cleanTestConfig();
return this.app.start(); await this.app.start();
}).then(() => {
return this.app.client.waitUntilWindowLoaded(). await this.app.client.waitUntilWindowLoaded().
waitForVisible('#newServerModal'). waitForVisible('#newServerModal').
click('#cancelNewServerModal'). click('#cancelNewServerModal');
isEnabled('#btnClose').then((enabled) => { let isCloseButtonEnabled = await this.app.client.isEnabled('#btnClose');
enabled.should.equal(false); isCloseButtonEnabled.should.equal(false);
}).
await this.app.client.
waitForVisible('#newServerModal', true). waitForVisible('#newServerModal', true).
pause(250). pause(250).
click('#addNewServer'). click('#addNewServer').
@ -63,18 +62,16 @@ describe('browser/settings.html', function desc() {
click('#saveNewServerModal'). click('#saveNewServerModal').
waitForVisible('#newServerModal', true). waitForVisible('#newServerModal', true).
waitForVisible('#serversSaveIndicator'). waitForVisible('#serversSaveIndicator').
waitForVisible('#serversSaveIndicator', 10000, true). // at least 2500 ms to disappear waitForVisible('#serversSaveIndicator', 10000, true); // at least 2500 ms to disappear
isEnabled('#btnClose').then((enabled) => { isCloseButtonEnabled = await this.app.client.isEnabled('#btnClose');
enabled.should.equal(true); 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'; const modalTitleSelector = '.modal-title=Remove Server';
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.
loadSettingsPage(). loadSettingsPage().
click('=Remove'). click('=Remove').
waitForVisible(modalTitleSelector). waitForVisible(modalTitleSelector).
@ -83,297 +80,272 @@ describe('browser/settings.html', function desc() {
click('=Remove'). click('=Remove').
waitForVisible(modalTitleSelector). waitForVisible(modalTitleSelector).
element('.modal-dialog').click('.btn=Remove'). element('.modal-dialog').click('.btn=Remove').
pause(500). pause(500);
isExisting('#newServerModal').then((existing) => { const isModalExisting = await this.app.client.isExisting('#newServerModal');
existing.should.be.true; isModalExisting.should.be.true;
});
}); });
describe('Server list', () => { 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); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.
loadSettingsPage(). loadSettingsPage().
click('h4=example'). click('h4=example').
pause(1000). pause(1000).
waitUntilWindowLoaded(). waitUntilWindowLoaded();
getUrl().then((url) => { let indexURL = await this.app.client.getUrl();
url.should.match(/\/index.html(\?.+)?$/); indexURL.should.match(/\/index.html(\?.+)?$/);
}).
isVisible('#mattermostView0').then((visible) => {
visible.should.be.true;
}).
isVisible('#mattermostView1').then((visible) => {
visible.should.be.false;
}).
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(). loadSettingsPage().
click('h4=github'). click('h4=github').
pause(1000). pause(1000).
waitUntilWindowLoaded(). waitUntilWindowLoaded();
getUrl().then((url) => { indexURL = await this.app.client.getUrl();
url.should.match(/\/index.html(\?.+)?$/); indexURL.should.match(/\/index.html(\?.+)?$/);
}).
isVisible('#mattermostView0').then((visible) => { isView0Visible = await this.app.client.isVisible('#mattermostView0');
visible.should.be.false; isView0Visible.should.be.false;
}).
isVisible('#mattermostView1').then((visible) => { isView1Visible = await this.app.client.isVisible('#mattermostView1');
visible.should.be.true; isView1Visible.should.be.true;
});
}); });
}); });
describe('Options', () => { describe('Options', () => {
describe.skip('Hide Menu Bar', () => { 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'); const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputHideMenuBar');
isExisting('#inputHideMenuBar').then((existing) => {
existing.should.equal(expected); existing.should.equal(expected);
}); });
});
[true, false].forEach((v) => { [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); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.
loadSettingsPage(). loadSettingsPage().
scroll('#inputHideMenuBar'). scroll('#inputHideMenuBar');
isSelected('#inputHideMenuBar').then((isSelected) => { const isSelected = await this.app.client.isSelected('#inputHideMenuBar');
if (isSelected !== v) { if (isSelected !== v) {
return this.app.client.click('#inputHideMenuBar'); await this.app.client.click('#inputHideMenuBar');
} }
return true;
}). await this.app.client.
pause(600). pause(600).
click('#btnClose'). click('#btnClose').
pause(1000).then(() => { pause(1000);
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.hideMenuBar.should.equal(v); savedConfig.hideMenuBar.should.equal(v);
}).
browserWindow.isMenuBarAutoHide().then((autoHide) => { let autoHide = await this.app.browserWindow.isMenuBarAutoHide();
autoHide.should.equal(v); autoHide.should.equal(v);
}).then(() => { // confirm actual behavior
return this.app.restart(); // confirm actual behavior
}).then(() => { await this.app.restart();
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. // confirm actual behavior
browserWindow.isMenuBarAutoHide().then((autoHide) => { autoHide = await this.app.browserWindow.isMenuBarAutoHide();
autoHide.should.equal(v); autoHide.should.equal(v);
}).
loadSettingsPage(). await this.app.loadSettingsPage();
isSelected('#inputHideMenuBar').then((autoHide) => { autoHide = await this.app.client.isSelected('#inputHideMenuBar');
autoHide.should.equal(v); autoHide.should.equal(v);
}); });
}); });
}); });
});
});
describe('Start app on login', () => { 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'); const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputAutoStart');
isExisting('#inputAutoStart').then((existing) => {
existing.should.equal(expected); existing.should.equal(expected);
}); });
}); });
});
describe('Show icon in menu bar / notification area', () => { 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'); const expected = (process.platform === 'darwin' || process.platform === 'linux');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputShowTrayIcon');
isExisting('#inputShowTrayIcon').then((existing) => {
existing.should.equal(expected); existing.should.equal(expected);
}); });
});
describe('Save tray icon setting on mac', () => { 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); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.
loadSettingsPage(). loadSettingsPage().
click('#inputShowTrayIcon'). click('#inputShowTrayIcon').
waitForAppOptionsAutoSaved(). waitForAppOptionsAutoSaved();
then(() => {
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); let config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.showTrayIcon.should.true; config0.showTrayIcon.should.true;
return this.app.client;
}). await this.app.client.
click('#inputShowTrayIcon'). click('#inputShowTrayIcon').
waitForAppOptionsAutoSaved(). waitForAppOptionsAutoSaved();
then(() => {
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.showTrayIcon.should.false; config0.showTrayIcon.should.false;
}); });
}); });
});
describe('Save tray icon theme on linux', () => { 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); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.
loadSettingsPage(). loadSettingsPage().
click('#inputShowTrayIcon'). click('#inputShowTrayIcon').
click('input[value="light"]'). click('input[value="light"]').
pause(700). // wait auto-save pause(700); // wait auto-save
then(() => {
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.trayIconTheme.should.equal('light'); config0.trayIconTheme.should.equal('light');
return this.app.client;
}). await this.app.client.
click('input[value="dark"]'). click('input[value="dark"]').
pause(700). // wait auto-save pause(700); // wait auto-save
then(() => {
const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config1.trayIconTheme.should.equal('dark'); config1.trayIconTheme.should.equal('dark');
}); });
}); });
}); });
});
describe('Leave app running in notification area when application window is closed', () => { 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'); const expected = (process.platform === 'linux');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputMinimizeToTray');
isExisting('#inputMinimizeToTray').then((existing) => {
existing.should.equal(expected); existing.should.equal(expected);
}); });
}); });
});
describe.skip('Toggle window visibility when clicking on the tray icon', () => { 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'); const expected = (process.platform === 'win32');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputToggleWindowOnTrayIconClick');
isExisting('#inputToggleWindowOnTrayIconClick').then((existing) => {
existing.should.equal(expected); existing.should.equal(expected);
}); });
}); });
});
describe('Flash app window and taskbar icon when a new message is received', () => { 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'); const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputflashWindow');
isExisting('#inputflashWindow').then((existing) => {
existing.should.equal(expected); existing.should.equal(expected);
}); });
}); });
});
describe('Show red badge on taskbar icon to indicate unread messages', () => { 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'); const expected = (process.platform === 'darwin' || process.platform === 'win32');
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputShowUnreadBadge');
isExisting('#inputShowUnreadBadge').then((existing) => {
existing.should.equal(expected); existing.should.equal(expected);
}); });
}); });
});
describe('Check spelling', () => { describe('Check spelling', () => {
it('should appear and be selectable', () => { it('should appear and be selectable', async () => {
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting('#inputSpellChecker');
isExisting('#inputSpellChecker').then((existing) => {
existing.should.equal(true); existing.should.equal(true);
}).
scroll('#inputSpellChecker'). await this.app.client.scroll('#inputSpellChecker');
isSelected('#inputSpellChecker').then((selected) => { const selected = await this.app.client.isSelected('#inputSpellChecker');
selected.should.equal(true); selected.should.equal(true);
}).
click('#inputSpellChecker'). await this.app.client.click('#inputSpellChecker').pause(700);
pause(700).
then(() => {
const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config1.useSpellChecker.should.equal(false); config1.useSpellChecker.should.equal(false);
}); });
}); });
}); });
});
describe('RemoveServerModal', () => { describe('RemoveServerModal', () => {
const modalTitleSelector = '.modal-title=Remove Server'; const modalTitleSelector = '.modal-title=Remove Server';
beforeEach(() => { beforeEach(async () => {
env.addClientCommands(this.app.client); env.addClientCommands(this.app.client);
return this.app.client. await this.app.client.loadSettingsPage();
loadSettingsPage(). const existing = await this.app.client.isExisting(modalTitleSelector);
isExisting(modalTitleSelector).then((existing) => {
existing.should.be.false; existing.should.be.false;
}).
isVisible(modalTitleSelector).then((visible) => { const visible = await this.app.client.isVisible(modalTitleSelector);
visible.should.be.false; visible.should.be.false;
}).
await this.app.client.
click('=Remove'). click('=Remove').
waitForVisible(modalTitleSelector); waitForVisible(modalTitleSelector);
}); });
it('should remove existing team on click Remove', (done) => { it('should remove existing team on click Remove', async () => {
this.app.client. await this.app.client.
element('.modal-dialog').click('.btn=Remove'). element('.modal-dialog').click('.btn=Remove').
pause(500). pause(500);
isExisting(modalTitleSelector).then((existing) => { const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false; existing.should.be.false;
}).
await this.app.client.
click('#btnClose'). click('#btnClose').
pause(500).then(() => { pause(500);
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams.slice(1)); savedConfig.teams.should.deep.equal(config.teams.slice(1));
done();
});
}); });
it('should NOT remove existing team on click Cancel', (done) => { it('should NOT remove existing team on click Cancel', async () => {
this.app.client. await this.app.client.
element('.modal-dialog').click('.btn=Cancel'). element('.modal-dialog').click('.btn=Cancel').
pause(500). pause(500);
isExisting(modalTitleSelector).then((existing) => { const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false; existing.should.be.false;
}).
await this.app.client.
click('#btnClose'). click('#btnClose').
pause(500).then(() => { pause(500);
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams); savedConfig.teams.should.deep.equal(config.teams);
done();
});
}); });
it('should disappear on click Close', () => { it('should disappear on click Close', async () => {
return this.app.client. await this.app.client.
click('.modal-dialog button.close'). click('.modal-dialog button.close').
pause(500). pause(500);
isExisting(modalTitleSelector).then((existing) => { const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false; existing.should.be.false;
}); });
});
it('should disappear on click background', () => { it('should disappear on click background', async () => {
return this.app.client. await this.app.client.
click('body'). click('body').
pause(500). pause(500);
isExisting(modalTitleSelector).then((existing) => { const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false; existing.should.be.false;
}); });
}); });
});
describe('NewTeamModal', () => { describe('NewTeamModal', () => {
beforeEach(() => { beforeEach(() => {
@ -484,22 +456,19 @@ describe('browser/settings.html', function desc() {
}); });
}); });
it('should add the team to the config file', (done) => { it('should add the team to the config file', async () => {
this.app.client. await this.app.client.
click('#saveNewServerModal'). click('#saveNewServerModal').
waitForVisible('#newServerModal', true). waitForVisible('#newServerModal', true).
waitForVisible('#serversSaveIndicator'). waitForVisible('#serversSaveIndicator').
waitForVisible('#serversSaveIndicator', 10000, true). // at least 2500 ms to disappear waitForVisible('#serversSaveIndicator', 10000, true). // at least 2500 ms to disappear
waitUntilWindowLoaded().then(() => { waitUntilWindowLoaded();
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.contain({ savedConfig.teams.should.deep.contain({
name: 'TestTeam', name: 'TestTeam',
url: 'http://example.org', url: 'http://example.org',
}); });
done();
}).catch((err) => {
done(err);
});
}); });
}); });
}); });