mattermost-desktop/test/specs/browser/settings_test.js
Devin Binnie 932ddafdb0
[MM-10586] Desktop App Window/Tabs Update (#1056)
* [MM-19054] Added new server tab look and feel, still missing proper hover states and session expired icon

* [MM-19055] Added window controls and removed border for macOS

* [MM-19055] Add dark mode for macOS

* [MM-19054] Added session expired icon

* Test windows titlebar

* Fixed the menu issue and added non-macOS dark mode

* Blank commit

* Fixed a lint issue

* Fixed more lint issues

* Fixed more issues

* New tray icons

* [MM-19603] Drag and drop tabs

* Fixed some assets and fixed build output to include missing assets

* Fixed a couple small issues

* Only show tabs for only 1 server on Mac

* Fixed some more tests

* Fixed another test

* Revert "Fixed another test"

This reverts commit 36040294a71a68663d06996d71eecc5ed23d7014.

* Fixed another test

* Trial and error!

* A bunch of additional fixes

* Fixed a lint issue

* Fixed restore focus on add server tab causing bad UX

* Trial and error on flaky test again

* Fixed some bugs based on PR feedback.

* blank commit to push tests

* Revert "Test windows titlebar"

This reverts commit 9cd46b71b1427b75942434ac49185870d2437b85.

* Remove the rest of the old new titlebar and fixes

* Added three-dot link

* New menu

* Rest of new windows menu and other fixes

* Fixed lint errors

* Added windows 10 style title bar buttons for non mac OS

* Lint fixes and enabled the tab bar regardless of number of servers

* Missed one

* Fixed unicode characters

* Commenting out test that should no longer be applicable

* Removed Windows 10 style titlebar icons and used material design instead

* Fixed a lint issue

* Some small UX fixes

* blank commit

* Fixed an issue where dropping the first tab moves it too far over before snapping into place

* Additional style fixes

* Another small issue fix

* Back to Windows 10 style

* Lint fixes

* Accessible three dot menu

* Lint fixes

* Shrinking tabs when window is too small

* Gradient between tabs and title bar buttons when window is too small

* Add drag to gradient

* Replaced icons, drag and drop cursor sticking fix, slight tab change

* Lint and some mac fixes

* Light theme fix to three dot menu

* Hack for tab sticking to cursor on macOS

* Fixes for the find utility

* Fix for Catalina dark mode

* Revert "Fix for Catalina dark mode"

This reverts commit 45da05dd0f17f46efd1c53fafb92e9c1fd9dd8d9.

* Fixed a couple issues Dean found

* More fixes

* Three dot hover effect to circle

* PR feedback

* Test fixes

* Test and config fixes

* Disable dragging when there are GPO servers

* [MM-20757] Fixed dark mode on debug when running macOS Catalina

* Allow future config versions to use v2 config if launching this version of the app

* Oops

* New titlebar icons, blur for titlebar on inactive

* Lint fix

* Set unfocused opacity to 0.4

* Final FINAL icons

* Fixed closing menu not returning focus to the app

* Lint fix

* Update src/browser/components/TabBar.jsx

Co-Authored-By: Guillermo Vayá <guivaya@gmail.com>

* Update src/main/Validator.js

Co-Authored-By: Guillermo Vayá <guivaya@gmail.com>

* Lint fixes

* Moved react-smooth-dnd fork to MM org and fixed another merge issue

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Guillermo Vayá <guivaya@gmail.com>
2020-01-03 12:00:43 -05:00

529 lines
19 KiB
JavaScript

// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
const fs = require('fs');
const env = require('../../modules/environment');
const {asyncSleep} = require('../../modules/utils');
describe('browser/settings.html', function desc() {
this.timeout(30000);
const config = {
version: 2,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
};
beforeEach(async () => {
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
await asyncSleep(1000);
this.app = env.getSpectronApp();
await this.app.start();
});
afterEach(async () => {
if (this.app && this.app.isRunning()) {
await this.app.stop();
}
});
describe('Close button', async () => {
it.skip('should show index.html when it\'s clicked', async () => {
env.addClientCommands(this.app.client);
await this.app.client.
loadSettingsPage().
click('#btnClose').
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', async () => {
await this.app.stop();
env.cleanTestConfig();
await this.app.start();
await this.app.client.waitUntilWindowLoaded().
waitForVisible('#newServerModal', 10000).
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', async () => {
const modalTitleSelector = '.modal-title=Remove Server';
env.addClientCommands(this.app.client);
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').
pause(500);
const isModalExisting = await this.app.client.isExisting('#newServerModal');
isModalExisting.should.be.true;
});
describe('Server list', () => {
it.skip('should open the corresponding tab when a server list item is clicked', async () => {
env.addClientCommands(this.app.client);
await this.app.client.
loadSettingsPage().
click('h4=example').
pause(1000).
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();
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', async () => {
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
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}`, async () => {
env.addClientCommands(this.app.client);
await this.app.client.
loadSettingsPage().
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);
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', async () => {
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
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', async () => {
const expected = (process.platform === 'darwin' || process.platform === 'linux');
env.addClientCommands(this.app.client);
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', async () => {
env.addClientCommands(this.app.client);
await this.app.browserWindow.setSize(1024, 768); // Resize the window to click the element
await this.app.client.
loadSettingsPage().
click('#inputShowTrayIcon').
waitForAppOptionsAutoSaved();
let config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.showTrayIcon.should.true;
await this.app.client.
click('#inputShowTrayIcon').
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', async () => {
env.addClientCommands(this.app.client);
await this.app.browserWindow.setSize(1024, 768); // Resize the window to click the element
await this.app.client.
loadSettingsPage().
click('#inputShowTrayIcon').
click('input[value="dark"]').
pause(700); // wait auto-save
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.trayIconTheme.should.equal('dark');
await this.app.client.
click('input[value="light"]').
pause(700); // wait auto-save
const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config1.trayIconTheme.should.equal('light');
});
});
});
describe('Leave app running in notification area when application window is closed', () => {
it('should appear on linux', async () => {
const expected = (process.platform === 'linux');
env.addClientCommands(this.app.client);
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', async () => {
const expected = (process.platform === 'win32');
env.addClientCommands(this.app.client);
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', async () => {
const expected = (process.platform === 'win32' || process.platform === 'linux');
env.addClientCommands(this.app.client);
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', async () => {
const expected = (process.platform === 'darwin' || process.platform === 'win32');
env.addClientCommands(this.app.client);
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', async () => {
env.addClientCommands(this.app.client);
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);
const windowBounds = await this.app.browserWindow.getBounds();
const inputLocation = await this.app.client.getLocation('#inputSpellChecker');
const offset = (inputLocation.y - windowBounds.height) + 100;
await this.app.client.
scroll(0, offset).
click('#inputSpellChecker').
pause(5000);
const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config1.useSpellChecker.should.equal(false);
});
});
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).
scroll(ID_INPUT_ENABLE_HARDWARE_ACCELERATION);
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);
});
});
});
describe('RemoveServerModal', () => {
const modalTitleSelector = '.modal-title=Remove Server';
beforeEach(async () => {
env.addClientCommands(this.app.client);
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', async () => {
await this.app.client.
element('.modal-dialog').click('.btn=Remove').
waitForExist(modalTitleSelector, 5000, true);
await this.app.client.waitForVisible('#serversSaveIndicator', 10000, true);
const expectedConfig = JSON.parse(JSON.stringify(config.teams.slice(1)));
expectedConfig.forEach((value) => {
value.order--;
});
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(expectedConfig);
});
it('should NOT remove existing team on click Cancel', async () => {
await this.app.client.
element('.modal-dialog').click('.btn=Cancel').
waitForExist(modalTitleSelector, 5000, true);
await this.app.client.waitForVisible('#serversSaveIndicator', 10000, true);
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams);
});
it('should disappear on click Close', async () => {
await this.app.client.
click('.modal-dialog button.close').
waitForVisible(modalTitleSelector, 10000, true);
const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false;
});
it('should disappear on click background', async () => {
await this.app.browserWindow.setSize(1024, 768); // Resize the window to click the center of <body>
await this.app.client.
click('body').
waitForVisible(modalTitleSelector, 10000, true);
const existing = await this.app.client.isExisting(modalTitleSelector);
existing.should.be.false;
});
});
describe('NewTeamModal', () => {
beforeEach(() => {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
click('#addNewServer').
pause(1000);
});
it('should open the new server modal', () => {
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').
waitForExist('#newServerModal', 10000, true).
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').
waitForExist('.has-error #teamNameInput', 10000).
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').
waitForExist('.has-error #teamUrlInput', 10000).
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.true;
});
});
describe('Valid server name', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamNameInput', 'TestTeam').
click('#saveNewServerModal');
});
it('should not be marked invalid', () => {
return this.app.client.
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');
});
});
});
describe('Valid server url', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamUrlInput', 'http://example.org').
click('#saveNewServerModal');
});
it('should be valid', () => {
return this.app.client.
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');
});
});
});
it('should not be valid if an invalid server address has been set', () => {
return this.app.client.
setValue('#teamUrlInput', 'superInvalid url').
click('#saveNewServerModal').
pause(500).
isExisting('.has-error #teamUrlInput').then((existing) => {
existing.should.be.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').then((disabled) => {
(disabled === null).should.be.true;
});
});
it('should add the team to the config file', async () => {
await this.app.client.
click('#saveNewServerModal').
waitForVisible('#newServerModal', 10000, true).
waitForVisible('#serversSaveIndicator', 10000).
waitForVisible('#serversSaveIndicator', 10000, true). // at least 2500 ms to disappear
waitUntilWindowLoaded();
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.contain({
name: 'TestTeam',
url: 'http://example.org',
order: 2,
});
});
});
});
});