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

499 lines
18 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() {
2017-09-22 08:41:42 -07:00
this.timeout(30000);
2016-05-02 06:34:00 -07:00
const config = {
version: 1,
teams: [{
2018-01-19 03:50:00 -08:00
name: 'example',
url: env.mattermostURL,
2016-05-02 06:34:00 -07:00
}, {
2018-01-19 03:50:00 -08:00
name: 'github',
url: 'https://github.com/',
}],
2016-05-02 06:34:00 -07:00
};
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
});
2018-03-13 07:08:07 -07:00
afterEach(async () => {
2016-05-21 01:23:23 -07:00
if (this.app && this.app.isRunning()) {
2018-03-13 07:08:07 -07:00
await this.app.stop();
2016-05-21 01:23:23 -07:00
}
2016-05-02 06:34:00 -07:00
});
2018-03-13 07:08:07 -07:00
describe('Close button', async () => {
it('should show index.html when it\'s clicked', async () => {
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.
loadSettingsPage().
click('#btnClose').
2018-03-13 07:08:07 -07:00
pause(1000);
const url = await this.app.client.getUrl();
url.should.match(/\/index.html(\?.+)?$/);
});
2018-03-13 07:08:07 -07:00
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);
});
2016-05-02 06:34:00 -07:00
});
2016-05-02 08:42:13 -07:00
2018-03-13 07:08:07 -07:00
it('should show NewServerModal after all servers are removed', async () => {
const modalTitleSelector = '.modal-title=Remove Server';
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.
loadSettingsPage().
click('=Remove').
waitForVisible(modalTitleSelector).
element('.modal-dialog').click('.btn=Remove').
pause(500).
click('=Remove').
waitForVisible(modalTitleSelector).
element('.modal-dialog').click('.btn=Remove').
2018-03-13 07:08:07 -07:00
pause(500);
const isModalExisting = await this.app.client.isExisting('#newServerModal');
isModalExisting.should.be.true;
});
2017-01-29 05:06:20 -08:00
describe('Server list', () => {
2018-03-13 07:08:07 -07:00
it('should open the corresponding tab when a server list item is clicked', async () => {
2017-01-29 05:06:20 -08:00
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.
2018-02-20 04:44:23 -08:00
loadSettingsPage().
click('h4=example').
2018-02-23 03:29:44 -08:00
pause(1000).
2018-03-13 07:08:07 -07:00
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;
2017-01-29 05:06:20 -08:00
2018-03-13 07:08:07 -07:00
await this.app.client.
2018-02-20 04:44:23 -08:00
loadSettingsPage().
click('h4=github').
2018-02-23 03:29:44 -08:00
pause(1000).
2018-03-13 07:08:07 -07:00
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;
2017-01-29 05:06:20 -08:00
});
});
2016-09-25 07:14:01 -07:00
describe('Options', () => {
2017-02-01 06:32:07 -08:00
describe.skip('Hide Menu Bar', () => {
2018-03-13 07:08:07 -07:00
it('should appear on win32 or linux', async () => {
2016-06-05 08:41:35 -07:00
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputHideMenuBar');
existing.should.equal(expected);
2016-05-02 08:42:13 -07:00
});
2016-09-25 07:14:01 -07:00
[true, false].forEach((v) => {
2018-03-13 07:08:07 -07:00
env.shouldTest(it, env.isOneOf(['win32', 'linux']))(`should be saved and loaded: ${v}`, async () => {
2016-09-25 07:14:01 -07:00
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.
2016-09-25 07:14:01 -07:00
loadSettingsPage().
2018-03-13 07:08:07 -07:00
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).
2017-02-15 05:44:51 -08:00
click('#btnClose').
2018-03-13 07:08:07 -07:00
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);
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('Start app on login', () => {
2018-03-13 07:08:07 -07:00
it('should appear on win32 or linux', async () => {
2016-06-22 08:03:04 -07:00
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputAutoStart');
existing.should.equal(expected);
2016-06-22 08:03:04 -07:00
});
});
2017-02-01 07:26:04 -08:00
describe('Show icon in menu bar / notification area', () => {
2018-03-13 07:08:07 -07:00
it('should appear on darwin or linux', async () => {
2016-06-22 08:03:04 -07:00
const expected = (process.platform === 'darwin' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputShowTrayIcon');
existing.should.equal(expected);
2016-06-22 08:03:04 -07:00
});
2017-03-15 06:18:35 -07:00
describe('Save tray icon setting on mac', () => {
2018-03-13 07:08:07 -07:00
env.shouldTest(it, env.isOneOf(['darwin', 'linux']))('should be saved when it\'s selected', async () => {
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.
loadSettingsPage().
click('#inputShowTrayIcon').
2018-03-13 07:08:07 -07:00
waitForAppOptionsAutoSaved();
let config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.showTrayIcon.should.true;
await this.app.client.
click('#inputShowTrayIcon').
2018-03-13 07:08:07 -07:00
waitForAppOptionsAutoSaved();
config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.showTrayIcon.should.false;
});
});
2017-03-15 06:18:35 -07:00
describe('Save tray icon theme on linux', () => {
2018-03-13 07:08:07 -07:00
env.shouldTest(it, process.platform === 'linux')('should be saved when it\'s selected', async () => {
2017-03-15 06:18:35 -07:00
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.
2017-03-15 06:18:35 -07:00
loadSettingsPage().
click('#inputShowTrayIcon').
click('input[value="light"]').
2018-03-13 07:08:07 -07:00
pause(700); // wait auto-save
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.trayIconTheme.should.equal('light');
await this.app.client.
2017-03-15 06:18:35 -07:00
click('input[value="dark"]').
2018-03-13 07:08:07 -07:00
pause(700); // wait auto-save
const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config1.trayIconTheme.should.equal('dark');
2017-03-15 06:18:35 -07:00
});
});
2016-06-22 08:03:04 -07:00
});
2017-02-01 07:26:04 -08:00
describe('Leave app running in notification area when application window is closed', () => {
2018-03-13 07:08:07 -07:00
it('should appear on linux', async () => {
2017-02-01 06:32:07 -08:00
const expected = (process.platform === 'linux');
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputMinimizeToTray');
existing.should.equal(expected);
});
});
2017-02-01 06:32:07 -08:00
describe.skip('Toggle window visibility when clicking on the tray icon', () => {
2018-03-13 07:08:07 -07:00
it('should appear on win32', async () => {
2016-06-28 06:09:05 -07:00
const expected = (process.platform === 'win32');
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputToggleWindowOnTrayIconClick');
existing.should.equal(expected);
2016-06-28 06:09:05 -07:00
});
});
2017-02-22 07:25:14 -08:00
describe('Flash app window and taskbar icon when a new message is received', () => {
2018-03-13 07:08:07 -07:00
it('should appear on win32 and linux', async () => {
2016-07-12 13:14:32 -07:00
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputflashWindow');
existing.should.equal(expected);
2016-06-22 08:03:04 -07:00
});
});
2016-07-15 04:04:14 -07:00
2017-02-01 07:26:04 -08:00
describe('Show red badge on taskbar icon to indicate unread messages', () => {
2018-03-13 07:08:07 -07:00
it('should appear on darwin or win32', async () => {
2016-07-15 04:04:14 -07:00
const expected = (process.platform === 'darwin' || process.platform === 'win32');
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputShowUnreadBadge');
existing.should.equal(expected);
2016-07-15 04:04:14 -07:00
});
});
2017-04-20 05:32:34 -07:00
describe('Check spelling', () => {
2018-03-13 07:08:07 -07:00
it('should appear and be selectable', async () => {
2017-04-20 05:32:34 -07:00
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
await this.app.client.loadSettingsPage();
const existing = await this.app.client.isExisting('#inputSpellChecker');
existing.should.equal(true);
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);
2017-04-20 05:32:34 -07:00
});
});
describe('Enable GPU hardware acceleration', () => {
it('should save selected option', async () => {
const ID_INPUT_ENABLE_HARDWARE_ACCELERATION = '#inputEnableHardwareAcceleration';
env.addClientCommands(this.app.client);
await this.app.client.
loadSettingsPage().
waitForExist(ID_INPUT_ENABLE_HARDWARE_ACCELERATION, 5000);
const selected = await this.app.client.isSelected(ID_INPUT_ENABLE_HARDWARE_ACCELERATION);
selected.should.equal(true); // default is true
await this.app.client.click(ID_INPUT_ENABLE_HARDWARE_ACCELERATION).
waitForVisible('#appOptionsSaveIndicator', 5000).
waitForVisible('#appOptionsSaveIndicator', 5000, true); // at least 2500 ms to disappear
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.enableHardwareAcceleration.should.equal(false);
await this.app.client.click(ID_INPUT_ENABLE_HARDWARE_ACCELERATION).
waitForVisible('#appOptionsSaveIndicator', 5000).
waitForVisible('#appOptionsSaveIndicator', 5000, true); // at least 2500 ms to disappear
const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config1.enableHardwareAcceleration.should.equal(true);
});
});
2016-05-02 08:42:13 -07:00
});
2017-01-24 06:40:10 -08:00
describe('RemoveServerModal', () => {
const modalTitleSelector = '.modal-title=Remove Server';
2018-03-13 07:08:07 -07:00
beforeEach(async () => {
2017-01-24 06:40:10 -08:00
env.addClientCommands(this.app.client);
2018-03-13 07:08:07 -07:00
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.
2017-01-24 06:40:10 -08:00
click('=Remove').
waitForVisible(modalTitleSelector);
});
2018-03-13 07:08:07 -07:00
it('should remove existing team on click Remove', async () => {
await this.app.client.
2017-01-24 06:40:10 -08:00
element('.modal-dialog').click('.btn=Remove').
2018-03-13 07:08:07 -07:00
pause(500);
const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false;
await this.app.client.
2017-02-15 05:44:51 -08:00
click('#btnClose').
2018-03-13 07:08:07 -07:00
pause(500);
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams.slice(1));
2017-01-24 06:40:10 -08:00
});
2018-03-13 07:08:07 -07:00
it('should NOT remove existing team on click Cancel', async () => {
await this.app.client.
2017-01-24 06:40:10 -08:00
element('.modal-dialog').click('.btn=Cancel').
2018-03-13 07:08:07 -07:00
pause(500);
const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false;
await this.app.client.
2017-02-15 05:44:51 -08:00
click('#btnClose').
2018-03-13 07:08:07 -07:00
pause(500);
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams);
2017-01-24 06:40:10 -08:00
});
2018-03-13 07:08:07 -07:00
it('should disappear on click Close', async () => {
await this.app.client.
2017-01-24 06:40:10 -08:00
click('.modal-dialog button.close').
2018-04-12 07:01:46 -07:00
waitForVisible(modalTitleSelector, 10000, true);
2018-03-13 07:08:07 -07:00
const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false;
2017-01-24 06:40:10 -08:00
});
2018-03-13 07:08:07 -07:00
it('should disappear on click background', async () => {
await this.app.client.
2017-01-24 06:40:10 -08:00
click('body').
2018-04-12 07:01:46 -07:00
waitForVisible(modalTitleSelector, 10000, true);
2018-03-13 07:08:07 -07:00
const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false;
2017-01-24 06:40:10 -08:00
});
});
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', () => {
2018-02-02 05:45:54 -08:00
return this.app.client.isExisting('#newServerModal').then((existing) => {
existing.should.be.true;
});
2017-01-16 14:51:36 -08:00
});
it('should close the window after clicking cancel', () => {
return this.app.client.
click('#cancelNewServerModal').
2017-02-03 09:49:35 -08:00
pause(1000). // Animation
2018-02-02 05:45:54 -08:00
isExisting('#newServerModal').then((existing) => {
existing.should.be.false;
});
2017-01-16 14:51:36 -08:00
});
it('should not be valid if no team name has been set', () => {
return this.app.client.
click('#saveNewServerModal').
2017-03-02 07:49:07 -08:00
pause(500).
2018-02-02 05:45:54 -08:00
isExisting('.has-error #teamNameInput').then((existing) => {
existing.should.be.true;
});
2017-01-16 14:51:36 -08:00
});
it('should not be valid if no server address has been set', () => {
return this.app.client.
click('#saveNewServerModal').
2017-03-02 07:49:07 -08:00
pause(500).
2018-02-02 05:45:54 -08:00
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.true;
});
2017-01-16 14:51:36 -08:00
});
describe('Valid server name', () => {
beforeEach(() => {
return this.app.client.
2018-02-20 04:44:23 -08:00
setValue('#teamNameInput', 'TestTeam').
click('#saveNewServerModal');
2017-01-16 14:51:36 -08:00
});
it('should not be marked invalid', () => {
return this.app.client.
2018-02-20 04:44:23 -08:00
isExisting('.has-error #teamNameInput').then((existing) => {
existing.should.be.false;
});
2017-01-16 14:51:36 -08:00
});
it('should not be possible to click save', () => {
return this.app.client.
2018-02-02 05:45:54 -08:00
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => {
disabled.should.equal('true');
});
2017-01-16 14:51:36 -08:00
});
});
describe('Valid server url', () => {
beforeEach(() => {
return this.app.client.
2018-02-20 04:44:23 -08:00
setValue('#teamUrlInput', 'http://example.org').
click('#saveNewServerModal');
2017-01-16 14:51:36 -08:00
});
it('should be valid', () => {
return this.app.client.
2018-02-02 05:45:54 -08:00
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.false;
});
2017-01-16 14:51:36 -08:00
});
it('should not be possible to click save', () => {
return this.app.client.
2018-02-02 05:45:54 -08:00
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => {
disabled.should.equal('true');
});
2017-01-16 14:51:36 -08:00
});
});
it('should not be valid if an invalid server address has been set', () => {
return this.app.client.
setValue('#teamUrlInput', 'superInvalid url').
click('#saveNewServerModal').
2017-03-02 07:49:07 -08:00
pause(500).
2018-02-02 05:45:54 -08:00
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.true;
});
2017-01-16 14:51:36 -08:00
});
describe('Valid Team Settings', () => {
beforeEach(() => {
return this.app.client.
2018-02-20 04:44:23 -08:00
setValue('#teamUrlInput', 'http://example.org').
setValue('#teamNameInput', 'TestTeam');
2017-01-16 14:51:36 -08:00
});
it('should be possible to click add', () => {
return this.app.client.
2018-02-02 05:45:54 -08:00
getAttribute('#saveNewServerModal', 'disabled').then((disabled) => {
(disabled === null).should.be.true;
});
2017-01-16 14:51:36 -08:00
});
2018-03-13 07:08:07 -07:00
it('should add the team to the config file', async () => {
await this.app.client.
2017-01-16 14:51:36 -08:00
click('#saveNewServerModal').
2018-04-12 06:40:38 -07:00
waitForVisible('#newServerModal', 10000, true).
waitForVisible('#serversSaveIndicator', 10000).
2018-02-02 07:00:31 -08:00
waitForVisible('#serversSaveIndicator', 10000, true). // at least 2500 ms to disappear
2018-03-13 07:08:07 -07:00
waitUntilWindowLoaded();
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.contain({
name: 'TestTeam',
url: 'http://example.org',
});
2017-01-16 14:51:36 -08:00
});
});
});
2016-09-12 09:02:11 -07:00
});