[MM-39839] Changes for writing unit tests, some re-org (#1849)

* Move tests to individual folders

* Moved e2e tests to e2e folder, fixed lint issues

* Lint fix
This commit is contained in:
Devin Binnie
2021-11-04 11:29:32 -04:00
committed by GitHub
parent ba974dbf75
commit 0bd5a54c76
23 changed files with 76 additions and 81 deletions

51
e2e/specs/app_test.js Normal file
View File

@@ -0,0 +1,51 @@
// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
const env = require('../modules/environment');
describe('application', function desc() {
this.timeout(30000);
beforeEach(async () => {
env.createTestUserDataDir();
env.cleanTestConfig();
this.app = await env.getApp();
});
afterEach(async () => {
if (this.app) {
await this.app.close();
}
});
it('should show the new server modal when no servers exist', async () => {
const newServerModal = this.app.windows().find((window) => window.url().includes('newServer'));
const modalTitle = await newServerModal.innerText('#newServerModal .modal-title');
modalTitle.should.equal('Add Server');
});
it('should show no servers configured in dropdown when no servers exist', async () => {
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
const dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton');
dropdownButtonText.should.equal('No servers configured');
});
it('should be stopped when the app instance already exists', (done) => {
const secondApp = env.getApp();
// In the correct case, 'start().then' is not called.
// So need to use setTimeout in order to finish this test.
const timer = setTimeout(() => {
done();
}, 3000);
secondApp.then(() => {
clearTimeout(timer);
return secondApp.close();
}).then(() => {
done(new Error('Second app instance exists'));
});
});
});

View File

@@ -0,0 +1,163 @@
// 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 http = require('http');
// const path = require('path');
const env = require('../../modules/environment');
const {asyncSleep} = require('../../modules/utils');
describe('renderer/index.html', function desc() {
this.timeout(30000);
const config = {
version: 3,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
lastActiveTeam: 0,
spellCheckerLocales: [],
};
beforeEach(async () => {
env.createTestUserDataDir();
env.cleanTestConfig();
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
await asyncSleep(1000);
this.app = await env.getApp();
});
afterEach(async () => {
if (this.app) {
await this.app.close();
}
});
it('should set src of browser view from config file', async () => {
const firstServer = this.app.windows().find((window) => window.url() === config.teams[0].url);
const secondServer = this.app.windows().find((window) => window.url() === config.teams[1].url);
firstServer.should.not.be.null;
secondServer.should.not.be.null;
});
it('should set name of menu item from config file', async () => {
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
const dropdownView = this.app.windows().find((window) => window.url().includes('dropdown'));
await mainWindow.click('.TeamDropdownButton');
const firstMenuItem = await dropdownView.innerText('.TeamDropdown button.TeamDropdown__button:nth-child(1) span');
const secondMenuItem = await dropdownView.innerText('.TeamDropdown button.TeamDropdown__button:nth-child(2) span');
firstMenuItem.should.equal(config.teams[0].name);
secondMenuItem.should.equal(config.teams[1].name);
});
it('should only show dropdown when button is clicked', async () => {
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
const mainView = this.app.windows().find((window) => window.url().includes('index'));
let dropdownHeight = await browserWindow.evaluate((window) => window.getBrowserViews().find((view) => view.webContents.getURL().includes('dropdown')).getBounds().height);
dropdownHeight.should.equal(0);
await mainView.click('.TeamDropdownButton');
dropdownHeight = await browserWindow.evaluate((window) => window.getBrowserViews().find((view) => view.webContents.getURL().includes('dropdown')).getBounds().height);
dropdownHeight.should.be.greaterThan(0);
await mainView.click('.TabBar');
dropdownHeight = await browserWindow.evaluate((window) => window.getBrowserViews().find((view) => view.webContents.getURL().includes('dropdown')).getBounds().height);
dropdownHeight.should.equal(0);
});
it('should show only the selected team', async () => {
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
let firstViewIsAttached = await browserWindow.evaluate((window, url) => Boolean(window.getBrowserViews().find((view) => view.webContents.getURL() === url)), env.mattermostURL);
firstViewIsAttached.should.be.true;
let secondViewIsAttached = await browserWindow.evaluate((window) => Boolean(window.getBrowserViews().find((view) => view.webContents.getURL() === 'https://github.com/')));
secondViewIsAttached.should.be.false;
const mainView = this.app.windows().find((window) => window.url().includes('index'));
const dropdownView = this.app.windows().find((window) => window.url().includes('dropdown'));
await mainView.click('.TeamDropdownButton');
await dropdownView.click('.TeamDropdown button.TeamDropdown__button:nth-child(2)');
firstViewIsAttached = await browserWindow.evaluate((window, url) => Boolean(window.getBrowserViews().find((view) => view.webContents.getURL() === url)), env.mattermostURL);
firstViewIsAttached.should.be.false;
secondViewIsAttached = await browserWindow.evaluate((window) => Boolean(window.getBrowserViews().find((view) => view.webContents.getURL() === 'https://github.com/')));
secondViewIsAttached.should.be.true;
});
it('should open the new server prompt after clicking the add button', async () => {
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
const dropdownView = this.app.windows().find((window) => window.url().includes('dropdown'));
await mainWindow.click('.TeamDropdownButton');
await dropdownView.click('.TeamDropdown__button.addServer');
const newServerModal = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('newServer'),
});
const modalTitle = await newServerModal.innerText('#newServerModal .modal-title');
modalTitle.should.equal('Add Server');
});
});

View File

@@ -0,0 +1,520 @@
// 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('modals', function desc() {
this.timeout(30000);
const config = {
version: 3,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
lastActiveTeam: 0,
spellCheckerLocales: [],
};
beforeEach(async () => {
env.createTestUserDataDir();
env.cleanTestConfig();
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
await asyncSleep(1000);
this.app = await env.getApp();
});
afterEach(async () => {
if (this.app) {
await this.app.close();
}
});
describe('RemoveServerModal', () => {
let removeServerView;
beforeEach(async () => {
const mainView = this.app.windows().find((window) => window.url().includes('index'));
const dropdownView = this.app.windows().find((window) => window.url().includes('dropdown'));
await mainView.click('.TeamDropdownButton');
await dropdownView.hover('.TeamDropdown .TeamDropdown__button:nth-child(1)');
await dropdownView.click('.TeamDropdown .TeamDropdown__button:nth-child(1) button.TeamDropdown__button-remove');
removeServerView = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('removeServer'),
});
});
it('should remove existing team on click Remove', async () => {
await removeServerView.click('button:has-text("Remove")');
await asyncSleep(1000);
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 removeServerView.click('button:has-text("Cancel")');
await asyncSleep(1000);
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.equal(config.teams);
});
it('should disappear on click Close', async () => {
await removeServerView.click('button.close');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('removeServer')));
existing.should.be.false;
});
it('should disappear on click background', async () => {
await removeServerView.click('.modal', {position: {x: 20, y: 20}});
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('removeServer')));
existing.should.be.false;
});
});
describe('NewTeamModal', () => {
let newServerView;
beforeEach(async () => {
const mainView = this.app.windows().find((window) => window.url().includes('index'));
const dropdownView = this.app.windows().find((window) => window.url().includes('dropdown'));
await mainView.click('.TeamDropdownButton');
await dropdownView.click('.TeamDropdown .TeamDropdown__button.addServer');
newServerView = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('newServer'),
});
// wait for autofocus to finish
await asyncSleep(500);
});
it('should open the new server modal', async () => {
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('newServer')));
existing.should.be.true;
});
it('should focus the first text input', async () => {
const isFocused = await newServerView.$eval('#teamNameInput', (el) => el === document.activeElement);
isFocused.should.be.true;
});
it('should close the window after clicking cancel', async () => {
await newServerView.click('#cancelNewServerModal');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('newServer')));
existing.should.be.false;
});
it('should not be valid if no team name has been set', async () => {
await newServerView.click('#saveNewServerModal');
const existing = await newServerView.isVisible('#teamNameInput.is-invalid');
existing.should.be.true;
});
it('should not be valid if no server address has been set', async () => {
await newServerView.click('#saveNewServerModal');
const existing = await newServerView.isVisible('#teamUrlInput.is-invalid');
existing.should.be.true;
});
describe('Valid server name', async () => {
beforeEach(async () => {
await newServerView.type('#teamNameInput', 'TestTeam');
await newServerView.click('#saveNewServerModal');
});
it('should not be marked invalid', async () => {
const existing = await newServerView.isVisible('#teamNameInput.is-invalid');
existing.should.be.false;
});
it('should not be possible to click save', async () => {
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
(disabled === '').should.be.true;
});
});
describe('Valid server url', () => {
beforeEach(async () => {
await newServerView.type('#teamUrlInput', 'http://example.org');
await newServerView.click('#saveNewServerModal');
});
it('should be valid', async () => {
const existing = await newServerView.isVisible('#teamUrlInput.is-invalid');
existing.should.be.false;
});
it('should not be possible to click save', async () => {
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
(disabled === '').should.be.true;
});
});
it('should not be valid if an invalid server address has been set', async () => {
await newServerView.type('#teamUrlInput', 'superInvalid url');
await newServerView.click('#saveNewServerModal');
const existing = await newServerView.isVisible('#teamUrlInput.is-invalid');
existing.should.be.true;
});
describe('Valid Team Settings', () => {
beforeEach(async () => {
await newServerView.type('#teamUrlInput', 'http://example.org');
await newServerView.type('#teamNameInput', 'TestTeam');
});
it('should be possible to click add', async () => {
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
(disabled === null).should.be.true;
});
it('should add the team to the config file', async () => {
await newServerView.click('#saveNewServerModal');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('newServer')));
existing.should.be.false;
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.contain({
name: 'TestTeam',
url: 'http://example.org',
order: 2,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
},
],
lastActiveTab: 0,
});
});
});
});
describe('EditServerModal', () => {
let editServerView;
beforeEach(async () => {
const mainView = this.app.windows().find((window) => window.url().includes('index'));
const dropdownView = this.app.windows().find((window) => window.url().includes('dropdown'));
await mainView.click('.TeamDropdownButton');
await dropdownView.hover('.TeamDropdown .TeamDropdown__button:nth-child(1)');
await dropdownView.click('.TeamDropdown .TeamDropdown__button:nth-child(1) button.TeamDropdown__button-edit');
editServerView = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('editServer'),
});
});
it('should not edit team when Cancel is pressed', async () => {
await editServerView.click('#cancelNewServerModal');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.contain({
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
});
it('should not edit team when Save is pressed but nothing edited', async () => {
await editServerView.click('#saveNewServerModal');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.deep.contain({
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
});
it('should edit team when Save is pressed and name edited', async () => {
await editServerView.fill('#teamNameInput', 'NewTestTeam');
await editServerView.click('#saveNewServerModal');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.not.deep.contain({
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
savedConfig.teams.should.deep.contain({
name: 'NewTestTeam',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
});
it('should edit team when Save is pressed and URL edited', async () => {
await editServerView.fill('#teamUrlInput', 'http://google.com');
await editServerView.click('#saveNewServerModal');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.not.deep.contain({
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
savedConfig.teams.should.deep.contain({
name: 'example',
url: 'http://google.com',
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
});
it('should edit team when Save is pressed and both edited', async () => {
await editServerView.fill('#teamNameInput', 'NewTestTeam');
await editServerView.fill('#teamUrlInput', 'http://google.com');
await editServerView.click('#saveNewServerModal');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.not.deep.contain({
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
savedConfig.teams.should.deep.contain({
name: 'NewTestTeam',
url: 'http://google.com',
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
});
});
});
});

View File

@@ -0,0 +1,268 @@
// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// TODO: fix test with new settings window
'use strict';
const fs = require('fs');
const {SHOW_SETTINGS_WINDOW} = require('../../../src/common/communication');
const env = require('../../modules/environment');
const {asyncSleep} = require('../../modules/utils');
describe('renderer/settings.html', function desc() {
this.timeout(30000);
const config = {
version: 3,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
lastActiveTeam: 0,
spellCheckerLocales: [],
};
beforeEach(async () => {
env.createTestUserDataDir();
env.cleanTestConfig();
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
await asyncSleep(1000);
this.app = await env.getApp();
});
afterEach(async () => {
if (this.app) {
await this.app.close();
}
});
describe('Options', () => {
describe('Start app on login', () => {
it('should appear on win32 or linux', async () => {
const expected = (process.platform === 'win32' || process.platform === 'linux');
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
const existing = await settingsWindow.isVisible('#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');
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
const existing = await settingsWindow.isVisible('#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 () => {
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
await settingsWindow.click('#inputShowTrayIcon');
await settingsWindow.waitForSelector('.IndicatorContainer :text("Saved")');
let config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.showTrayIcon.should.true;
await settingsWindow.click('#inputShowTrayIcon');
await settingsWindow.waitForSelector('.IndicatorContainer :text("Saved")');
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 () => {
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
await settingsWindow.click('#inputShowTrayIcon');
await settingsWindow.click('input[value="dark"]');
await settingsWindow.waitForSelector('.IndicatorContainer :text("Saved")');
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.trayIconTheme.should.equal('dark');
await settingsWindow.click('input[value="light"]');
await settingsWindow.waitForSelector('.IndicatorContainer :text("Saved")');
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');
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
const existing = await settingsWindow.isVisible('#inputMinimizeToTray');
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');
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
const existing = await settingsWindow.isVisible('#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');
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
const existing = await settingsWindow.isVisible('#inputShowUnreadBadge');
existing.should.equal(expected);
});
});
describe('Check spelling', () => {
it('should appear and be selectable', async () => {
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
const existing = await settingsWindow.isVisible('#inputSpellChecker');
existing.should.equal(true);
const selected = await settingsWindow.isChecked('#inputSpellChecker');
selected.should.equal(true);
await settingsWindow.click('#inputSpellChecker');
await settingsWindow.waitForSelector('.IndicatorContainer :text("Saved")');
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';
this.app.evaluate(({ipcMain}, showWindow) => {
ipcMain.emit(showWindow);
}, SHOW_SETTINGS_WINDOW);
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
await settingsWindow.waitForSelector('.settingsPage.container');
const selected = await settingsWindow.isChecked(ID_INPUT_ENABLE_HARDWARE_ACCELERATION);
selected.should.equal(true); // default is true
await settingsWindow.click(ID_INPUT_ENABLE_HARDWARE_ACCELERATION);
await settingsWindow.waitForSelector('.IndicatorContainer :text("Saved")');
const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config0.enableHardwareAcceleration.should.equal(false);
await settingsWindow.click(ID_INPUT_ENABLE_HARDWARE_ACCELERATION);
await settingsWindow.waitForSelector('.IndicatorContainer :text("Saved")');
const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8'));
config1.enableHardwareAcceleration.should.equal(true);
});
});
});
});

116
e2e/specs/config_test.js Normal file
View File

@@ -0,0 +1,116 @@
// 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');
describe('config', function desc() {
this.timeout(30000);
beforeEach(async () => {
env.createTestUserDataDir();
env.cleanTestConfig();
});
afterEach(async () => {
if (this.app) {
try {
await this.app.close();
// eslint-disable-next-line no-empty
} catch (err) {}
}
});
it('should show servers in dropdown when there is config file', async () => {
const config = {
version: 3,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
lastActiveTeam: 0,
spellCheckerLocales: [],
};
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
this.app = await env.getApp();
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
const dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton');
dropdownButtonText.should.equal('example');
await this.app.close();
});
it('should upgrade v0 config file', async () => {
const Config = require('../../src/common/config').default;
const newConfig = new Config(env.configFilePath);
const oldConfig = {
url: env.mattermostURL,
};
fs.writeFileSync(env.configFilePath, JSON.stringify(oldConfig));
this.app = await env.getApp();
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
const dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton:has-text("Primary team")');
dropdownButtonText.should.equal('Primary team');
const str = fs.readFileSync(env.configFilePath, 'utf8');
const upgradedConfig = JSON.parse(str);
upgradedConfig.version.should.equal(newConfig.defaultData.version);
await this.app.close();
});
});

111
e2e/specs/deeplink_test.js Normal file
View File

@@ -0,0 +1,111 @@
// 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('application', function desc() {
this.timeout(30000);
const config = {
version: 3,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: false,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: false,
},
],
lastActiveTab: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: false,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: false,
},
],
lastActiveTab: 0,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
lastActiveTeam: 0,
spellCheckerLocales: [],
};
beforeEach(async () => {
env.cleanDataDir();
env.createTestUserDataDir();
env.cleanTestConfig();
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
await asyncSleep(1000);
});
afterEach(async () => {
if (this.app) {
try {
await this.app.close();
// eslint-disable-next-line no-empty
} catch (err) {}
}
});
if (process.platform === 'win32') {
it('should open the app on the requested deep link', async () => {
this.app = await env.getApp(['mattermost://github.com/test/url']);
this.serverMap = await env.getServerMap(this.app);
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
const webContentsId = this.serverMap[`${config.teams[1].name}___TAB_MESSAGING`].webContentsId;
const isActive = await browserWindow.evaluate((window, id) => {
return window.getBrowserViews().find((view) => view.webContents.id === id).webContents.getURL();
}, webContentsId);
isActive.should.equal('https://github.com/test/url');
const mainView = this.app.windows().find((window) => window.url().includes('index'));
const dropdownButtonText = await mainView.innerText('.TeamDropdownButton');
dropdownButtonText.should.equal('github');
await this.app.close();
});
}
});

16
e2e/specs/index.js Normal file
View File

@@ -0,0 +1,16 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import './app_test.js';
import './config_test.js';
import './deeplink_test.js';
import './mattermost_test.js';
import './menu_test.js';
import './window_test.js';
import './browser/index_test.js';
import './browser/modal_test.js';
import './browser/settings_test.js';
import './main/user_activity_monitor_test.js';
import './utils/util_test.js';

View File

@@ -0,0 +1,69 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import UserActivityMonitor from '../../../src/main/UserActivityMonitor';
describe('UserActivityMonitor', () => {
describe('updateIdleTime', () => {
it('should set idle time to provided value', () => {
const userActivityMonitor = new UserActivityMonitor();
const idleTime = Math.round(Date.now() / 1000);
userActivityMonitor.updateIdleTime(idleTime);
assert.equal(userActivityMonitor.userIdleTime, idleTime);
});
});
describe('updateUserActivityStatus', () => {
let userActivityMonitor;
beforeEach(() => {
userActivityMonitor = new UserActivityMonitor();
});
it('should set user status to active', () => {
userActivityMonitor.setActivityState(true);
assert.equal(userActivityMonitor.userIsActive, true);
});
it('should set user status to inactive', () => {
userActivityMonitor.setActivityState(false);
assert.equal(userActivityMonitor.userIsActive, false);
});
});
describe('sendStatusUpdate', () => {
let userActivityMonitor;
beforeEach(() => {
userActivityMonitor = new UserActivityMonitor();
});
it('should emit a non-system triggered status event indicating a user is active', () => {
userActivityMonitor.on('status', ({userIsActive, isSystemEvent}) => {
assert.equal(userIsActive && !isSystemEvent, true);
});
userActivityMonitor.setActivityState(true, false);
});
it('should emit a non-system triggered status event indicating a user is inactive', () => {
userActivityMonitor.on('status', ({userIsActive, isSystemEvent}) => {
assert.equal(!userIsActive && !isSystemEvent, true);
});
userActivityMonitor.setActivityState(false, false);
});
it('should emit a system triggered status event indicating a user is active', () => {
userActivityMonitor.on('status', ({userIsActive, isSystemEvent}) => {
assert.equal(userIsActive && isSystemEvent, true);
});
userActivityMonitor.setActivityState(true, true);
});
it('should emit a system triggered status event indicating a user is inactive', () => {
userActivityMonitor.on('status', ({userIsActive, isSystemEvent}) => {
assert.equal(!userIsActive && isSystemEvent, true);
});
userActivityMonitor.setActivityState(false, true);
});
});
});

View File

@@ -0,0 +1,106 @@
// 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('mattermost', function desc() {
this.timeout(30000);
const config = {
version: 3,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: false,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: false,
},
],
lastActiveTab: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: false,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: false,
},
],
lastActiveTab: 0,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
lastActiveTeam: 0,
spellCheckerLocales: [],
};
beforeEach(async () => {
env.cleanDataDir();
env.createTestUserDataDir();
env.cleanTestConfig();
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
await asyncSleep(1000);
this.app = await env.getApp();
this.serverMap = await env.getServerMap(this.app);
});
afterEach(async () => {
if (this.app) {
await this.app.close();
}
});
// TODO: enable when we have a server to test against
it.skip('Control+F should focus the search bar in Mattermost', async () => {
const loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen'));
await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'});
const firstServer = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].win;
await env.loginToMattermost(firstServer);
await firstServer.waitForSelector('#searchBox');
await firstServer.press('body', process.platform === 'darwin' ? 'Meta+F' : 'Control+F');
const isFocused = await firstServer.$eval('#searchBox', (el) => el === document.activeElement);
isFocused.should.be.true;
const text = await firstServer.inputValue('#searchBox');
text.should.include('in:');
});
});

176
e2e/specs/menu_test.js Normal file
View File

@@ -0,0 +1,176 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
const fs = require('fs');
// const http = require('http');
// const path = require('path');
const robot = require('robotjs');
const env = require('../modules/environment');
const {asyncSleep} = require('../modules/utils');
describe('mattermost', function desc() {
this.timeout(30000);
const config = {
version: 3,
teams: [{
name: 'example',
url: env.mattermostURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: false,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: false,
},
],
lastActiveTab: 0,
}, {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: false,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: false,
},
],
lastActiveTab: 0,
}],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
darkMode: false,
lastActiveTeam: 0,
spellCheckerLocales: [],
};
beforeEach(async () => {
env.cleanDataDir();
env.createTestUserDataDir();
env.cleanTestConfig();
fs.writeFileSync(env.configFilePath, JSON.stringify(config));
await asyncSleep(1000);
this.app = await env.getApp();
this.serverMap = await env.getServerMap(this.app);
});
afterEach(async () => {
if (this.app) {
await this.app.close();
}
});
it('should reload page when pressing Ctrl+R', async () => {
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
const webContentsId = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].webContentsId;
const loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen'));
await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'});
const check = browserWindow.evaluate(async (window, id) => {
const promise = new Promise((resolve) => {
const browserView = window.getBrowserViews().find((view) => view.webContents.id === id);
browserView.webContents.on('did-finish-load', () => {
resolve();
});
});
await promise;
return true;
}, webContentsId);
await asyncSleep(500);
robot.keyTap('r', ['control']);
const result = await check;
result.should.be.true;
});
it('should reload page when pressing Ctrl+Shift+R', async () => {
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
const webContentsId = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].webContentsId;
const loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen'));
await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'});
const check = browserWindow.evaluate(async (window, id) => {
const promise = new Promise((resolve) => {
const browserView = window.getBrowserViews().find((view) => view.webContents.id === id);
browserView.webContents.on('did-finish-load', () => {
resolve();
});
});
await promise;
return true;
}, webContentsId);
await asyncSleep(500);
robot.keyTap('r', ['control', 'shift']);
const result = await check;
result.should.be.true;
});
it('should switch to servers when keyboard shortcuts are pressed', async () => {
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
let dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton');
dropdownButtonText.should.equal('example');
robot.keyTap('2', ['control', 'shift']);
dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton');
dropdownButtonText.should.equal('github');
robot.keyTap('1', ['control', 'shift']);
dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton');
dropdownButtonText.should.equal('example');
});
if (process.platform !== 'darwin') {
it('should open the 3 dot menu with Alt', async () => {
const mainWindow = this.app.windows().find((window) => window.url().includes('index'));
mainWindow.should.not.be.null;
// Settings window should open if Alt works
robot.keyTap('alt');
robot.keyTap('enter');
robot.keyTap('f');
robot.keyTap('s');
robot.keyTap('enter');
const settingsWindow = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('settings'),
});
settingsWindow.should.not.be.null;
});
}
});

View File

@@ -0,0 +1,106 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
import assert from 'assert';
import urlUtils from '../../../src/common/utils/url';
describe('Utils', () => {
describe('isValidURL', () => {
it('should be true for a valid web url', () => {
const testURL = 'https://developers.mattermost.com/';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for a valid, non-https web url', () => {
const testURL = 'http://developers.mattermost.com/';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for an invalid, self-defined, top-level domain', () => {
const testURL = 'https://www.example.x';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for a file download url', () => {
const testURL = 'https://community.mattermost.com/api/v4/files/ka3xbfmb3ffnmgdmww8otkidfw?download=1';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for a permalink url', () => {
const testURL = 'https://community.mattermost.com/test-channel/pl/pdqowkij47rmbyk78m5hwc7r6r';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for a valid, internal domain', () => {
const testURL = 'https://mattermost.company-internal';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for a second, valid internal domain', () => {
const testURL = 'https://serverXY/mattermost';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for a valid, non-https internal domain', () => {
const testURL = 'http://mattermost.local';
assert.equal(urlUtils.isValidURL(testURL), true);
});
it('should be true for a valid, non-https, ip address with port number', () => {
const testURL = 'http://localhost:8065';
assert.equal(urlUtils.isValidURL(testURL), true);
});
});
describe('isValidURI', () => {
it('should be true for a deeplink url', () => {
const testURL = 'mattermost://community-release.mattermost.com/core/channels/developers';
assert.equal(urlUtils.isValidURI(testURL), true);
});
it('should be false for a malicious url', () => {
const testURL = String.raw`mattermost:///" --data-dir "\\deans-mbp\mattermost`;
assert.equal(urlUtils.isValidURI(testURL), false);
});
});
describe('isInternalURL', () => {
it('should be false for different hosts', () => {
const currentURL = new URL('http://localhost/team/channel1');
const targetURL = new URL('http://example.com/team/channel2');
const basename = '/';
assert.equal(urlUtils.isInternalURL(targetURL, currentURL, basename), false);
});
it('should be false for same hosts, non-matching basename', () => {
const currentURL = new URL('http://localhost/subpath/team/channel1');
const targetURL = new URL('http://localhost/team/channel2');
const basename = '/subpath';
assert.equal(urlUtils.isInternalURL(targetURL, currentURL, basename), false);
});
it('should be true for same hosts, matching basename', () => {
const currentURL = new URL('http://localhost/subpath/team/channel1');
const targetURL = new URL('http://localhost/subpath/team/channel2');
const basename = '/subpath';
assert.equal(urlUtils.isInternalURL(targetURL, currentURL, basename), true);
});
it('should be true for same hosts, default basename', () => {
const currentURL = new URL('http://localhost/team/channel1');
const targetURL = new URL('http://localhost/team/channel2');
const basename = '/';
assert.equal(urlUtils.isInternalURL(targetURL, currentURL, basename), true);
});
it('should be true for same hosts, default basename, empty target path', () => {
const currentURL = new URL('http://localhost/team/channel1');
const targetURL = new URL('http://localhost/');
const basename = '/';
assert.equal(urlUtils.isInternalURL(targetURL, currentURL, basename), true);
});
});
describe('getHost', () => {
it('should return the origin of a well formed url', () => {
const myurl = 'https://mattermost.com/download';
assert.equal(urlUtils.getHost(myurl), 'https://mattermost.com');
});
it('shoud raise an error on malformed urls', () => {
const myurl = 'http://example.com:-80/';
assert.throws(() => urlUtils.getHost(myurl), Error);
});
});
});

67
e2e/specs/window_test.js Normal file
View File

@@ -0,0 +1,67 @@
// 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');
describe('window', function desc() {
this.timeout(30000);
beforeEach(async () => {
env.createTestUserDataDir();
env.cleanTestConfig();
});
afterEach(async () => {
if (this.app) {
try {
await this.app.close();
// eslint-disable-next-line no-empty
} catch (err) {}
}
});
it.skip('should restore window bounds', async () => {
// TODO: Still fails in CircleCI
// bounds seems to be incorrectly calculated in some environments
// - Windows 10: OK
// - CircleCI: NG
const expectedBounds = {x: 100, y: 200, width: 800, height: 400};
fs.writeFileSync(env.boundsInfoPath, JSON.stringify(expectedBounds));
this.app = await env.getApp();
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
const bounds = await browserWindow.evaluate((window) => window.getContentBounds());
bounds.should.deep.equal(expectedBounds);
await this.app.close();
});
it('should NOT restore window bounds if x is located on outside of viewarea', async () => {
// bounds seems to be incorrectly calculated in some environments (e.g. CircleCI)
// - Windows 10: OK
// - CircleCI: NG
fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: -100000, y: 200, width: 800, height: 400}));
this.app = await env.getApp();
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
const bounds = await browserWindow.evaluate((window) => window.getContentBounds());
bounds.x.should.satisfy((x) => (x > -100000));
await this.app.close();
});
it('should NOT restore window bounds if y is located on outside of viewarea', async () => {
// bounds seems to be incorrectly calculated in some environments (e.g. CircleCI)
// - Windows 10: OK
// - CircleCI: NG
fs.writeFileSync(env.boundsInfoPath, JSON.stringify({x: 100, y: 200000, width: 800, height: 400}));
this.app = await env.getApp();
const mainWindow = await this.app.firstWindow();
const browserWindow = await this.app.browserWindow(mainWindow);
const bounds = await browserWindow.evaluate((window) => window.getContentBounds());
bounds.y.should.satisfy((y) => (y < 200000));
await this.app.close();
});
});