Fix tests with proper promise chain

This commit is contained in:
Yuya Ochiai
2018-02-02 22:45:54 +09:00
parent abfe5f1ae8
commit 88e6dd9de0
6 changed files with 190 additions and 65 deletions

View File

@@ -38,7 +38,9 @@ describe('browser/settings.html', function desc() {
loadSettingsPage().
click('#btnClose').
pause(1000).
getUrl().then((url) => url.should.match(/\/index.html(\?.+)?$/));
getUrl().then((url) => {
url.should.match(/\/index.html(\?.+)?$/);
});
});
it('should be disabled when the number of servers is zero', () => {
@@ -81,7 +83,9 @@ describe('browser/settings.html', function desc() {
waitForVisible(modalTitleSelector).
element('.modal-dialog').click('.btn=Remove').
pause(500).
isExisting('#newServerModal').then((existing) => existing.should.be.true);
isExisting('#newServerModal').then((existing) => {
existing.should.be.true;
});
});
describe('Server list', () => {
@@ -92,17 +96,29 @@ describe('browser/settings.html', function desc() {
click('h4=example_1').
pause(100).
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).
getUrl().then((url) => {
url.should.match(/\/index.html(\?.+)?$/);
}).
isVisible('#mattermostView0').then((visible) => {
visible.should.be.true;
}).
isVisible('#mattermostView1').then((visible) => {
visible.should.be.false;
}).
loadSettingsPage().
click('h4=example_2').
pause(100).
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);
getUrl().then((url) => {
url.should.match(/\/index.html(\?.+)?$/);
}).
isVisible('#mattermostView0').then((visible) => {
visible.should.be.false;
}).
isVisible('#mattermostView1').then((visible) => {
visible.should.be.true;
});
});
});
@@ -113,7 +129,9 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputHideMenuBar').then((existing) => existing.should.equal(expected));
isExisting('#inputHideMenuBar').then((existing) => {
existing.should.equal(expected);
});
});
[true, false].forEach((v) => {
@@ -134,14 +152,20 @@ describe('browser/settings.html', function desc() {
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
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)).
browserWindow.isMenuBarAutoHide().then((autoHide) => {
autoHide.should.equal(v);
}).
loadSettingsPage().
isSelected('#inputHideMenuBar').then((autoHide) => autoHide.should.equal(v));
isSelected('#inputHideMenuBar').then((autoHide) => {
autoHide.should.equal(v);
});
});
});
});
@@ -153,7 +177,9 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputAutoStart').then((existing) => existing.should.equal(expected));
isExisting('#inputAutoStart').then((existing) => {
existing.should.equal(expected);
});
});
});
@@ -163,7 +189,9 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputShowTrayIcon').then((existing) => existing.should.equal(expected));
isExisting('#inputShowTrayIcon').then((existing) => {
existing.should.equal(expected);
});
});
describe('Save tray icon theme on linux', () => {
@@ -195,7 +223,9 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputMinimizeToTray').then((existing) => existing.should.equal(expected));
isExisting('#inputMinimizeToTray').then((existing) => {
existing.should.equal(expected);
});
});
});
@@ -205,7 +235,9 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputToggleWindowOnTrayIconClick').then((existing) => existing.should.equal(expected));
isExisting('#inputToggleWindowOnTrayIconClick').then((existing) => {
existing.should.equal(expected);
});
});
});
@@ -215,7 +247,9 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputflashWindow').then((existing) => existing.should.equal(expected));
isExisting('#inputflashWindow').then((existing) => {
existing.should.equal(expected);
});
});
});
@@ -225,7 +259,9 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputShowUnreadBadge').then((existing) => existing.should.equal(expected));
isExisting('#inputShowUnreadBadge').then((existing) => {
existing.should.equal(expected);
});
});
});
@@ -234,9 +270,13 @@ describe('browser/settings.html', function desc() {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting('#inputSpellChecker').then((existing) => existing.should.equal(true)).
isExisting('#inputSpellChecker').then((existing) => {
existing.should.equal(true);
}).
scroll('#inputSpellChecker').
isSelected('#inputSpellChecker').then((selected) => selected.should.equal(true)).
isSelected('#inputSpellChecker').then((selected) => {
selected.should.equal(true);
}).
click('#inputSpellChecker').
pause(700).
then(() => {
@@ -254,8 +294,12 @@ describe('browser/settings.html', function desc() {
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).
isExisting(modalTitleSelector).then((existing) => {
existing.should.be.false;
}).
isVisible(modalTitleSelector).then((visible) => {
visible.should.be.false;
}).
click('=Remove').
waitForVisible(modalTitleSelector);
});
@@ -264,7 +308,9 @@ describe('browser/settings.html', function desc() {
this.app.client.
element('.modal-dialog').click('.btn=Remove').
pause(500).
isExisting(modalTitleSelector).then((existing) => existing.should.be.false).
isExisting(modalTitleSelector).then((existing) => {
existing.should.be.false;
}).
click('#btnClose').
pause(500).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
@@ -277,7 +323,9 @@ describe('browser/settings.html', function desc() {
this.app.client.
element('.modal-dialog').click('.btn=Cancel').
pause(500).
isExisting(modalTitleSelector).then((existing) => existing.should.be.false).
isExisting(modalTitleSelector).then((existing) => {
existing.should.be.false;
}).
click('#btnClose').
pause(500).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
@@ -290,14 +338,18 @@ describe('browser/settings.html', function desc() {
return this.app.client.
click('.modal-dialog button.close').
pause(500).
isExisting(modalTitleSelector).then((existing) => existing.should.be.false);
isExisting(modalTitleSelector).then((existing) => {
existing.should.be.false;
});
});
it('should disappear on click background', () => {
return this.app.client.
click('body').
pause(500).
isExisting(modalTitleSelector).then((existing) => existing.should.be.false);
isExisting(modalTitleSelector).then((existing) => {
existing.should.be.false;
});
});
});
@@ -310,28 +362,36 @@ describe('browser/settings.html', function desc() {
});
it('should open the new server modal', () => {
return this.app.client.isExisting('#newServerModal').then((existing) => existing.should.be.true);
return this.app.client.isExisting('#newServerModal').then((existing) => {
existing.should.be.true;
});
});
it('should close the window after clicking cancel', () => {
return this.app.client.
click('#cancelNewServerModal').
pause(1000). // Animation
isExisting('#newServerModal').then((existing) => existing.should.be.false);
isExisting('#newServerModal').then((existing) => {
existing.should.be.false;
});
});
it('should not be valid if no team name has been set', () => {
return this.app.client.
click('#saveNewServerModal').
pause(500).
isExisting('.has-error #teamNameInput').then((existing) => existing.should.be.true);
isExisting('.has-error #teamNameInput').then((existing) => {
existing.should.be.true;
});
});
it('should not be valid if no server address has been set', () => {
return this.app.client.
click('#saveNewServerModal').
pause(500).
isExisting('.has-error #teamUrlInput').then((existing) => existing.should.be.true);
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.true;
});
});
describe('Valid server name', () => {
@@ -343,12 +403,16 @@ describe('browser/settings.html', function desc() {
it('should not be marked invalid', () => {
return this.app.client.
isExisting('.has-error #teamNameInput').then((existing) => existing.should.be.false);
isExisting('.has-error #teamNameInput').then((existing) => {
existing.should.be.false;
});
});
it('should not be possible to click save', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => disabled.should.equal('true'));
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => {
disabled.should.equal('true');
});
});
});
@@ -361,12 +425,16 @@ describe('browser/settings.html', function desc() {
it('should be valid', () => {
return this.app.client.
isExisting('.has-error #teamUrlInput').then((existing) => existing.should.be.false);
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.false;
});
});
it('should not be possible to click save', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => disabled.should.equal('true'));
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => {
disabled.should.equal('true');
});
});
});
@@ -375,7 +443,9 @@ describe('browser/settings.html', function desc() {
setValue('#teamUrlInput', 'superInvalid url').
click('#saveNewServerModal').
pause(500).
isExisting('.has-error #teamUrlInput').then((existing) => existing.should.be.true);
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.true;
});
});
describe('Valid Team Settings', () => {
@@ -387,7 +457,9 @@ describe('browser/settings.html', function desc() {
it('should be possible to click add', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => (disabled === null).should.be.true);
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => {
(disabled === null).should.be.true;
});
});
it('should add the team to the config file', (done) => {