mattermost-desktop/test/specs/browser/settings_test.js

345 lines
12 KiB
JavaScript
Raw Normal View History

2016-05-02 06:34:00 -07:00
'use strict';
const fs = require('fs');
const env = require('../../modules/environment');
2016-09-25 07:14:01 -07:00
describe('browser/settings.html', function desc() {
2016-05-02 06:34:00 -07:00
this.timeout(10000);
const config = {
version: 1,
teams: [{
name: 'example_1',
url: env.mattermostURL
}, {
name: 'example_2',
url: env.mattermostURL
}]
};
2016-09-25 07:14:01 -07:00
beforeEach(() => {
2016-05-02 06:34:00 -07:00
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
2016-06-05 08:41:35 -07:00
this.app = env.getSpectronApp();
return this.app.start();
2016-05-02 06:34:00 -07:00
});
2016-09-25 07:14:01 -07:00
afterEach(() => {
2016-05-21 01:23:23 -07:00
if (this.app && this.app.isRunning()) {
2016-09-25 07:14:01 -07:00
return this.app.stop();
2016-05-21 01:23:23 -07:00
}
2016-09-25 07:14:01 -07:00
return true;
2016-05-02 06:34:00 -07:00
});
2016-09-25 07:14:01 -07:00
it('should show index.html when Cancel button is clicked', () => {
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
click('#btnCancel').
pause(1000).
getUrl().should.eventually.match(/\/index.html$/);
2016-05-02 06:34:00 -07:00
});
2016-09-25 07:14:01 -07:00
it('should show index.html when Save button is clicked', () => {
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
click('#btnSave').
pause(1000).
getUrl().should.eventually.match(/\/index.html$/);
2016-05-02 06:34:00 -07:00
});
2016-05-02 08:42:13 -07:00
2016-09-25 07:14:01 -07:00
describe('Options', () => {
describe('Hide Menu Bar', () => {
it('should appear on win32 or linux', () => {
2016-06-05 08:41:35 -07:00
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
isExisting('#inputHideMenuBar').should.eventually.equal(expected);
2016-05-02 08:42:13 -07:00
});
2016-09-25 07:14:01 -07:00
[true, false].forEach((v) => {
env.shouldTest(it, env.isOneOf(['win32', 'linux']))(`should be saved and loaded: ${v}`, () => {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
scroll('#inputHideMenuBar').
2016-11-02 08:35:07 -07:00
isSelected('#inputHideMenuBar').then((isSelected) => {
2016-09-25 07:14:01 -07:00
if (isSelected !== v) {
2016-11-02 08:35:07 -07:00
return this.app.client.click('#inputHideMenuBar');
2016-09-25 07:14:01 -07:00
}
return true;
}).
click('#btnSave').
pause(1000).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.hideMenuBar.should.equal(v);
}).
browserWindow.isMenuBarAutoHide().should.eventually.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().should.eventually.equal(v).
loadSettingsPage().
2016-11-02 08:35:07 -07:00
isSelected('#inputHideMenuBar').should.eventually.equal(v);
2016-09-25 07:14:01 -07:00
});
});
2016-05-21 04:57:59 -07:00
});
2016-05-02 08:42:13 -07:00
});
2016-09-25 07:14:01 -07:00
describe('Allow mixed content', () => {
[true, false].forEach((v) => {
it(`should be saved and loaded: ${v}`, () => {
const webPreferences = v ? 'allowDisplayingInsecureContent' : '';
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
scroll('#inputDisableWebSecurity').
2016-11-02 08:35:07 -07:00
isSelected('#inputDisableWebSecurity').then((isSelected) => {
2016-06-23 05:02:08 -07:00
if (isSelected !== v) {
2016-11-02 08:35:07 -07:00
return this.app.client.click('#inputDisableWebSecurity');
2016-06-23 05:02:08 -07:00
}
2016-09-25 07:14:01 -07:00
return true;
}).
click('#btnSave').
pause(1000).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.disablewebsecurity.should.equal(v);
}).
getAttribute('.mattermostView', 'webpreferences').then((disablewebsecurity) => { // confirm actual behavior
2016-06-23 05:02:08 -07:00
// disablewebsecurity is an array of String
disablewebsecurity.forEach((d) => {
d.should.equal(webPreferences);
2016-09-25 07:14:01 -07:00
});
2016-06-23 05:02:08 -07:00
}).then(() => {
return this.app.restart();
}).then(() => {
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client. // confirm actual behavior
getAttribute('.mattermostView', 'webpreferences').then((disablewebsecurity) => { // disablewebsecurity is an array of String
2016-06-23 05:02:08 -07:00
disablewebsecurity.forEach((d) => {
d.should.equal(webPreferences);
2016-09-25 07:14:01 -07:00
});
}).
loadSettingsPage().
2016-11-02 08:35:07 -07:00
isSelected('#inputDisableWebSecurity').should.eventually.equal(v);
2016-06-23 05:02:08 -07:00
});
});
});
2016-06-22 08:03:04 -07:00
});
2016-09-25 07:14:01 -07:00
describe('Start app on login', () => {
it('should appear on win32 or linux', () => {
2016-06-22 08:03:04 -07:00
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
isExisting('#inputAutoStart').should.eventually.equal(expected);
2016-06-22 08:03:04 -07:00
});
});
2016-09-25 07:14:01 -07:00
describe('Show tray icon', () => {
it('should appear on darwin or linux', () => {
2016-06-22 08:03:04 -07:00
const expected = (process.platform === 'darwin' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
isExisting('#inputShowTrayIcon').should.eventually.equal(expected);
2016-06-22 08:03:04 -07:00
});
});
2016-09-25 07:14:01 -07:00
describe('Minimize to tray', () => {
it('should appear on darwin or linux', () => {
const expected = (process.platform === 'darwin' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
isExisting('#inputMinimizeToTray').should.eventually.equal(expected);
});
});
2016-09-25 07:14:01 -07:00
describe('Toggle window visibility when clicking on the tray icon', () => {
it('should appear on win32', () => {
2016-06-28 06:09:05 -07:00
const expected = (process.platform === 'win32');
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
isExisting('#inputToggleWindowOnTrayIconClick').should.eventually.equal(expected);
2016-06-28 06:09:05 -07:00
});
});
2016-09-25 07:14:01 -07:00
describe('Flash taskbar icon on new messages', () => {
it('should appear on win32 and linux', () => {
2016-07-12 13:14:32 -07:00
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
isExisting('#inputflashWindow').should.eventually.equal(expected);
2016-06-22 08:03:04 -07:00
});
});
2016-07-15 04:04:14 -07:00
2016-09-25 07:14:01 -07:00
describe('Show red icon for unread', () => {
it('should appear on darwin or win32', () => {
2016-07-15 04:04:14 -07:00
const expected = (process.platform === 'darwin' || process.platform === 'win32');
env.addClientCommands(this.app.client);
2016-09-25 07:14:01 -07:00
return this.app.client.
loadSettingsPage().
isExisting('#inputShowUnreadBadge').should.eventually.equal(expected);
2016-07-15 04:04:14 -07:00
});
});
2016-05-02 08:42:13 -07:00
});
2017-01-24 06:40:10 -08:00
describe('RemoveServerModal', () => {
const modalTitleSelector = '.modal-title=Remove Server';
beforeEach(() => {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
isExisting(modalTitleSelector).should.eventually.false.
isVisible(modalTitleSelector).should.eventually.false.
click('=Remove').
waitForVisible(modalTitleSelector);
});
it('should remove existing team on click Remove', (done) => {
this.app.client.
element('.modal-dialog').click('.btn=Remove').
pause(500).
isExisting(modalTitleSelector).should.eventually.false.
click('#btnSave').
pause(500).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams.slice(1));
done();
});
});
it('should NOT remove existing team on click Cancel', (done) => {
this.app.client.
element('.modal-dialog').click('.btn=Cancel').
pause(500).
isExisting(modalTitleSelector).should.eventually.false.
click('#btnSave').
pause(500).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams);
done();
});
});
it('should disappear on click Close', () => {
return this.app.client.
click('.modal-dialog button.close').
pause(500).
isExisting(modalTitleSelector).should.eventually.false;
});
it('should disappear on click background', () => {
return this.app.client.
click('body').
pause(500).
isExisting(modalTitleSelector).should.eventually.false;
});
});
2017-01-16 14:51:36 -08:00
describe('NewTeamModal', () => {
beforeEach(() => {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
click('#addNewServer');
});
it('should open the new server modal', () => {
return this.app.client.isExisting('#newServerModal').should.eventually.equal(true);
});
it('should close the window after clicking cancel', () => {
return this.app.client.
click('#cancelNewServerModal').
isExisting('#newServerModal').should.eventually.equal(false);
});
it('should not be valid if no team name has been set', () => {
return this.app.client.
isExisting('.has-error #teamNameInput').should.eventually.equal(true);
});
it('should not be valid if no server address has been set', () => {
return this.app.client.
isExisting('.has-error #teamUrlInput').should.eventually.equal(true);
});
describe('Valid server name', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamNameInput', 'TestTeam');
});
it('should not be marked invalid', () => {
return this.app.client.
isExisting('.has-error #teamNameInput').should.eventually.equal(false);
});
it('should not be possible to click save', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal('true');
});
});
describe('Valid server url', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamUrlInput', 'http://example.org');
});
it('should be valid', () => {
return this.app.client.
isExisting('.has-error #teamUrlInput').should.eventually.equal(false);
});
it('should not be possible to click save', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal('true');
});
});
it('should not be valid if an invalid server address has been set', () => {
return this.app.client.
setValue('#teamUrlInput', 'superInvalid url').
isExisting('.has-error #teamUrlInput').should.eventually.equal(true);
});
describe('Valid Team Settings', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamUrlInput', 'http://example.org').
setValue('#teamNameInput', 'TestTeam');
});
it('should be possible to click add', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal(null);
});
it('should add the team to the config file', (done) => {
this.app.client.
click('#saveNewServerModal').
click('#btnSave');
this.app.client.pause(1000).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.contain({
name: 'TestTeam',
url: 'http://example.org'
});
return done();
});
});
});
});
2016-09-12 09:02:11 -07:00
});