From 1c44c8527a38716a91e64eeded334639a04edfff Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Tue, 19 Apr 2022 09:56:41 -0400 Subject: [PATCH] E2E test fixups (#2045) * Reinstall reporter and re-enable skipped tests * Fixups for Linux * Mac fixes * Windows fixes * Use keyboard shortcuts instead of menu for most menu actions * Couple fixes * One more fix for now * Windows fixes * Lint fixes * Change up developer tools tests to be more consistent * Fix key for mac * Couple fixes for flaky tests/to avoid crashes on unload --- e2e/modules/environment.js | 3 + e2e/specs/deep_linking/deeplink.test.js | 5 +- e2e/specs/linux_dark_mode.test.js | 2 +- e2e/specs/mattermost/back_button.test.js | 2 +- e2e/specs/mattermost/copy_link.test.js | 2 +- e2e/specs/menu_bar/dropdown.test.js | 12 +- e2e/specs/menu_bar/edit_menu.test.js | 211 +++++------ e2e/specs/menu_bar/file_menu.test.js | 65 ++-- e2e/specs/menu_bar/menu.test.js | 3 +- e2e/specs/menu_bar/view_menu.test.js | 339 ++++++------------ e2e/specs/menu_bar/window_menu.test.js | 46 +-- .../add_server_modal.test.js | 1 - .../edit_server_modal.test.js | 3 +- e2e/specs/server_management/header.test.js | 2 +- e2e/specs/settings.test.js | 58 +-- e2e/specs/startup/window.test.js | 37 +- src/main/tray/tray.ts | 4 + src/main/views/MattermostView.ts | 4 + src/renderer/components/SettingsPage.tsx | 15 +- 19 files changed, 323 insertions(+), 491 deletions(-) diff --git a/e2e/modules/environment.js b/e2e/modules/environment.js index 4b6eb829..8775b231 100644 --- a/e2e/modules/environment.js +++ b/e2e/modules/environment.js @@ -105,6 +105,8 @@ const demoMattermostConfig = { }, githubTeam], }; +const cmdOrCtrl = process.platform === 'darwin' ? 'command' : 'control'; + module.exports = { sourceRootDir, configFilePath, @@ -114,6 +116,7 @@ module.exports = { mattermostURL, demoConfig, demoMattermostConfig, + cmdOrCtrl, cleanTestConfig() { [configFilePath, boundsInfoPath].forEach((file) => { diff --git a/e2e/specs/deep_linking/deeplink.test.js b/e2e/specs/deep_linking/deeplink.test.js index 8e4bf3bd..c80451ae 100644 --- a/e2e/specs/deep_linking/deeplink.test.js +++ b/e2e/specs/deep_linking/deeplink.test.js @@ -33,15 +33,14 @@ describe('application', function desc() { it('MM-T1304/MM-T1306 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 mainWindow = this.app.windows().find((window) => window.url().includes('index')); 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'); + const dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton'); dropdownButtonText.should.equal('github'); await this.app.close(); }); diff --git a/e2e/specs/linux_dark_mode.test.js b/e2e/specs/linux_dark_mode.test.js index 9a96ea12..4c682ec9 100644 --- a/e2e/specs/linux_dark_mode.test.js +++ b/e2e/specs/linux_dark_mode.test.js @@ -30,7 +30,7 @@ describe('dark_mode', function desc() { } }); - if (process.platform !== 'darwin') { + if (process.platform === 'linux') { it('MM-T2465 Linux Dark Mode Toggle', async () => { const mainWindow = this.app.windows().find((window) => window.url().includes('index')); mainWindow.should.not.be.null; diff --git a/e2e/specs/mattermost/back_button.test.js b/e2e/specs/mattermost/back_button.test.js index 24f41dec..4b62a46e 100644 --- a/e2e/specs/mattermost/back_button.test.js +++ b/e2e/specs/mattermost/back_button.test.js @@ -7,7 +7,7 @@ const fs = require('fs'); const env = require('../../modules/environment'); const {asyncSleep} = require('../../modules/utils'); -describe('Menu/window_menu', function desc() { +describe('back_button', function desc() { this.timeout(30000); const config = { diff --git a/e2e/specs/mattermost/copy_link.test.js b/e2e/specs/mattermost/copy_link.test.js index 96608775..164ed5bf 100644 --- a/e2e/specs/mattermost/copy_link.test.js +++ b/e2e/specs/mattermost/copy_link.test.js @@ -44,6 +44,6 @@ describe('copylink', function desc() { const clipboardText = clipboard.readText(); await firstServer.fill('#post_textbox', clipboardText); const content = await firstServer.locator('#post_textbox').textContent(); - content.should.be.equal('/ad-1/channels/suscipit-4'); + content.should.contain('/ad-1/channels/suscipit-4'); }); }); diff --git a/e2e/specs/menu_bar/dropdown.test.js b/e2e/specs/menu_bar/dropdown.test.js index 3c8a36cc..5f49f636 100644 --- a/e2e/specs/menu_bar/dropdown.test.js +++ b/e2e/specs/menu_bar/dropdown.test.js @@ -38,18 +38,17 @@ describe('menu_bar/dropdown', function desc() { }); it('MM-T4406 should only show dropdown when button is clicked', async () => { - const mainWindow = await this.app.firstWindow(); + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); 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'); + await mainWindow.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'); + await mainWindow.click('.TabBar'); dropdownHeight = await browserWindow.evaluate((window) => window.getBrowserViews().find((view) => view.webContents.getURL().includes('dropdown')).getBounds().height); dropdownHeight.should.equal(0); }); @@ -68,7 +67,7 @@ describe('menu_bar/dropdown', function desc() { }); it('MM-T4408 should show only the selected team', async () => { - const mainWindow = await this.app.firstWindow(); + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); const browserWindow = await this.app.browserWindow(mainWindow); let firstViewIsAttached = await browserWindow.evaluate((window, url) => Boolean(window.getBrowserViews().find((view) => view.webContents.getURL() === url)), env.exampleURL); @@ -76,9 +75,8 @@ describe('menu_bar/dropdown', function desc() { 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 mainWindow.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.exampleURL); diff --git a/e2e/specs/menu_bar/edit_menu.test.js b/e2e/specs/menu_bar/edit_menu.test.js index bae58d56..22c2ab0a 100644 --- a/e2e/specs/menu_bar/edit_menu.test.js +++ b/e2e/specs/menu_bar/edit_menu.test.js @@ -31,147 +31,111 @@ describe('edit_menu', function desc() { }); it('MM-T807 Undo in the Menu Bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - 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('#sidebarItem_suscipit-4'); + 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('#sidebarItem_suscipit-4'); - // click on sint channel - await firstServer.click('#sidebarItem_suscipit-4'); - await firstServer.click('#post_textbox'); - await firstServer.type('#post_textbox', 'Mattermost'); - await firstServer.click('#post_textbox'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('u'); - const content = await firstServer.inputValue('#post_textbox'); - content.should.be.equal('Mattermos'); - } + // click on sint channel + await firstServer.click('#sidebarItem_suscipit-4'); + await firstServer.click('#post_textbox'); + await firstServer.type('#post_textbox', 'Mattermost'); + await firstServer.click('#post_textbox'); + robot.keyTap('z', [env.cmdOrCtrl]); + await asyncSleep(500); + const content = await firstServer.inputValue('#post_textbox'); + content.should.be.equal('Mattermos'); }); it('MM-T808 Redo in the Menu Bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - 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('#sidebarItem_suscipit-4'); + 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('#sidebarItem_suscipit-4'); - // click on sint channel - await firstServer.click('#sidebarItem_suscipit-4'); - await firstServer.click('#post_textbox'); - await firstServer.type('#post_textbox', 'Mattermost'); - await firstServer.click('#post_textbox'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('u'); - const textAfterUndo = await firstServer.inputValue('#post_textbox'); - textAfterUndo.should.be.equal('Mattermos'); - await firstServer.click('#post_textbox'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('r'); - const content = await firstServer.inputValue('#post_textbox'); - content.should.be.equal('Mattermost'); - } + // click on sint channel + await firstServer.click('#sidebarItem_suscipit-4'); + await firstServer.click('#post_textbox'); + await firstServer.type('#post_textbox', 'Mattermost'); + await firstServer.click('#post_textbox'); + robot.keyTap('z', [env.cmdOrCtrl]); + await asyncSleep(500); + const textAfterUndo = await firstServer.inputValue('#post_textbox'); + textAfterUndo.should.be.equal('Mattermos'); + await firstServer.click('#post_textbox'); + robot.keyTap('z', ['shift', env.cmdOrCtrl]); + await asyncSleep(500); + const content = await firstServer.inputValue('#post_textbox'); + content.should.be.equal('Mattermost'); }); it('MM-T809 Cut in the Menu Bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - 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('#sidebarItem_suscipit-4'); + 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('#sidebarItem_suscipit-4'); - // click on sint channel - await firstServer.click('#sidebarItem_suscipit-4'); - await firstServer.click('#post_textbox'); - await firstServer.type('#post_textbox', 'Mattermost'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('s'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('c'); - robot.keyTap('enter'); - const content = await firstServer.inputValue('#post_textbox'); - content.should.be.equal(''); - } + // click on sint channel + await firstServer.click('#sidebarItem_suscipit-4'); + await firstServer.click('#post_textbox'); + await firstServer.type('#post_textbox', 'Mattermost'); + robot.keyTap('a', [env.cmdOrCtrl]); + await asyncSleep(500); + robot.keyTap('x', [env.cmdOrCtrl]); + await asyncSleep(500); + const content = await firstServer.inputValue('#post_textbox'); + content.should.be.equal(''); }); it('MM-T810 Copy in the Menu Bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - 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('#sidebarItem_suscipit-4'); + 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('#sidebarItem_suscipit-4'); - // click on sint channel - await firstServer.click('#sidebarItem_suscipit-4'); - await firstServer.click('#post_textbox'); - await firstServer.type('#post_textbox', 'Mattermost'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('s'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('c'); - robot.keyTap('c'); - robot.keyTap('enter'); - await firstServer.click('#post_textbox'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('p'); - robot.keyTap('enter'); - const content = await firstServer.inputValue('#post_textbox'); - content.should.be.equal('MattermostMattermost'); - } + // click on sint channel + await firstServer.click('#sidebarItem_suscipit-4'); + await firstServer.click('#post_textbox'); + await firstServer.type('#post_textbox', 'Mattermost'); + robot.keyTap('a', [env.cmdOrCtrl]); + await asyncSleep(500); + robot.keyTap('c', [env.cmdOrCtrl]); + await asyncSleep(500); + await firstServer.click('#post_textbox'); + robot.keyTap('v', [env.cmdOrCtrl]); + await asyncSleep(500); + const content = await firstServer.inputValue('#post_textbox'); + content.should.be.equal('MattermostMattermost'); }); it('MM-T811 Paste in the Menu Bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - 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('#sidebarItem_suscipit-4'); + 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('#sidebarItem_suscipit-4'); - // click on sint channel - await firstServer.click('#sidebarItem_suscipit-4'); - await firstServer.click('#post_textbox'); - await firstServer.type('#post_textbox', 'Mattermost'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('s'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('c'); - robot.keyTap('c'); - robot.keyTap('enter'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('s'); - robot.keyTap('backspace'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('p'); - robot.keyTap('enter'); - const content = await firstServer.inputValue('#post_textbox'); - content.should.be.equal('Mattermost'); - } + // click on sint channel + await firstServer.click('#sidebarItem_suscipit-4'); + await firstServer.click('#post_textbox'); + await firstServer.type('#post_textbox', 'Mattermost'); + robot.keyTap('a', [env.cmdOrCtrl]); + await asyncSleep(500); + robot.keyTap('c', [env.cmdOrCtrl]); + await asyncSleep(500); + robot.keyTap('a', [env.cmdOrCtrl]); + await asyncSleep(500); + robot.keyTap('v', [env.cmdOrCtrl]); + await asyncSleep(500); + const content = await firstServer.inputValue('#post_textbox'); + content.should.be.equal('Mattermost'); }); it('MM-T812 Select All in the Menu Bar', async () => { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); 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; @@ -182,9 +146,8 @@ describe('edit_menu', function desc() { await firstServer.click('#sidebarItem_suscipit-4'); await firstServer.click('#post_textbox'); await firstServer.fill('#post_textbox', 'Mattermost'); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('e'); - robot.keyTap('s'); + robot.keyTap('a', [env.cmdOrCtrl]); + await asyncSleep(500); const channelHeaderText = await firstServer.evaluate('window.getSelection().toString()'); channelHeaderText.should.equal('Mattermost'); }); diff --git a/e2e/specs/menu_bar/file_menu.test.js b/e2e/specs/menu_bar/file_menu.test.js index e886c86a..51eca899 100644 --- a/e2e/specs/menu_bar/file_menu.test.js +++ b/e2e/specs/menu_bar/file_menu.test.js @@ -35,17 +35,16 @@ describe('file_menu/dropdown', function desc() { it('MM-T1313 Open Settings modal using keyboard shortcuts', async () => { const mainWindow = this.app.windows().find((window) => window.url().includes('index')); mainWindow.should.not.be.null; - if (process.platform === 'win32' || process.platform === 'linux') { - robot.keyTap(',', ['control']); - const settingsWindow = await this.app.waitForEvent('window', { - predicate: (window) => window.url().includes('settings'), - }); - settingsWindow.should.not.be.null; - } + robot.keyTap(',', [env.cmdOrCtrl]); + const settingsWindow = await this.app.waitForEvent('window', { + predicate: (window) => window.url().includes('settings'), + }); + settingsWindow.should.not.be.null; }); - it('MM-T805 Sign in to Another Server Window opens using menu item', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { + // TODO: No keyboard shortcut for macOS + if (process.platform !== 'darwin') { + it('MM-T805 Sign in to Another Server Window opens using menu item', async () => { const mainWindow = this.app.windows().find((window) => window.url().includes('index')); mainWindow.should.not.be.null; await mainWindow.click('button.three-dot-menu'); @@ -57,19 +56,20 @@ describe('file_menu/dropdown', function desc() { predicate: (window) => window.url().includes('newServer'), }); signInToAnotherServerWindow.should.not.be.null; - } - }); + }); + } it('MM-T804 Preferences in Menu Bar open the Settings page', async () => { + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); + mainWindow.should.not.be.null; + robot.keyTap(',', [env.cmdOrCtrl]); + const settingsWindow = await this.app.waitForEvent('window', { + predicate: (window) => window.url().includes('settings'), + }); + settingsWindow.should.not.be.null; + if (process.platform !== 'darwin') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - mainWindow.should.not.be.null; - robot.keyTap(',', ['control']); - const settingsWindow = await this.app.waitForEvent('window', { - predicate: (window) => window.url().includes('settings'), - }); - settingsWindow.should.not.be.null; - robot.keyTap('w', ['control']); + robot.keyTap('w', [env.cmdOrCtrl]); //Opening the menu bar robot.keyTap('alt'); @@ -84,20 +84,23 @@ describe('file_menu/dropdown', function desc() { } }); - it('MM-T806 Exit in the Menu Bar', () => { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - mainWindow.should.not.be.null; + // TODO: Causes issues on Windows so skipping for Windows + if (process.platform !== 'win32') { + it('MM-T806 Exit in the Menu Bar', () => { + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); + mainWindow.should.not.be.null; - if (process.platform === 'darwin') { - robot.keyTap('q', ['command']); - } + if (process.platform === 'darwin') { + robot.keyTap('q', ['command']); + } - if (process.platform === 'linux' || process.platform === 'win32') { - robot.keyTap('q', ['control']); - } + if (process.platform === 'linux' || process.platform === 'win32') { + robot.keyTap('q', ['control']); + } - this.app.windows().find((window) => window.url().should.not.include('index')); + this.app.windows().find((window) => window.url().should.not.include('index')); - skipAfterEach = true; // Need to skip closing in aftereach as apps execution context is destroyed above - }); + skipAfterEach = true; // Need to skip closing in aftereach as apps execution context is destroyed above + }); + } }); diff --git a/e2e/specs/menu_bar/menu.test.js b/e2e/specs/menu_bar/menu.test.js index 326aa690..b7482e7d 100644 --- a/e2e/specs/menu_bar/menu.test.js +++ b/e2e/specs/menu_bar/menu.test.js @@ -21,7 +21,6 @@ describe('menu/menu', function desc() { fs.writeFileSync(env.configFilePath, JSON.stringify(config)); await asyncSleep(1000); this.app = await env.getApp(); - this.serverMap = await env.getServerMap(this.app); }); afterEach(async () => { @@ -31,7 +30,7 @@ describe('menu/menu', function desc() { }); if (process.platform !== 'darwin') { - it.skip('MM-T4404 should open the 3 dot menu with Alt', async () => { + it('MM-T4404 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; diff --git a/e2e/specs/menu_bar/view_menu.test.js b/e2e/specs/menu_bar/view_menu.test.js index 3c65ee2f..0809850d 100644 --- a/e2e/specs/menu_bar/view_menu.test.js +++ b/e2e/specs/menu_bar/view_menu.test.js @@ -20,57 +20,8 @@ async function setupPromise(window, id) { return true; } -function robotTextInput(txt) { - for (let i = 0; i < txt.length; i++) { - robot.keyTap(txt[i]); - } -} - -function robotKeyTaps(n, ...params) { - for (let i = 0; i < n; i++) { - robot.keyTap(...params); - } -} - -function openDevToolsCommandPalette() { - const modifierKeys = process.platform === 'darwin' ? ['command'] : ['control']; - robotKeyTaps(1, 'p', [...modifierKeys, 'shift']); -} - -async function openDevToolsConsoleTab() { - openDevToolsCommandPalette(); - await asyncSleep(1500); - robotTextInput('con', 1200); // search for console command - await asyncSleep(500); - robotKeyTaps(1, 'enter'); -} - -async function clickThreeDotMenu(app) { - const mainWindow = app.windows().find((window) => window.url().includes('index')); - await mainWindow.click('button.three-dot-menu'); -} - -async function windowEventPromise(app) { - return new Promise((res) => { - app.on('window', (window) => { - res(window); - }); - }); -} - -function windowsDialogEventPromises(app, limit) { - return app.windows().map((window) => { - return new Promise((res, rej) => { - window.on('dialog', (e) => { - res(e); - }); - setTimeout(rej, limit); - }); - }); -} - describe('menu/view', function desc() { - this.timeout(60000); + this.timeout(30000); const config = env.demoMattermostConfig; @@ -96,6 +47,7 @@ describe('menu/view', function desc() { const firstServer = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].win; await env.loginToMattermost(firstServer); await firstServer.waitForSelector('#searchBox'); + await asyncSleep(1000); robot.keyTap('f', [process.platform === 'darwin' ? 'command' : 'control']); await asyncSleep(500); const isFocused = await firstServer.$eval('#searchBox', (el) => el === document.activeElement); @@ -104,8 +56,9 @@ describe('menu/view', function desc() { text.should.include('in:'); }); - it.skip('MM-T816 Toggle Full Screen in the Menu Bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { + // TODO: No keyboard shortcut for macOS + if (process.platform !== 'darwin') { + it('MM-T816 Toggle Full Screen in the Menu Bar', async () => { const mainWindow = this.app.windows().find((window) => window.url().includes('index')); const loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen')); await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'}); @@ -132,54 +85,61 @@ describe('menu/view', function desc() { currentHeight = await firstServer.evaluate('window.outerHeight'); currentWidth.should.be.lessThan(fullScreenWidth); currentHeight.should.be.lessThan(fullScreenHeight); - } - }); + }); + } it('MM-T817 Actual Size Zoom in the menu bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - mainWindow.should.not.be.null; - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('v'); - robot.keyTap('a'); - const zoomLevel = await mainWindow.evaluate('window.devicePixelRatio'); - zoomLevel.should.be.equal(1); - } + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); + const browserWindow = await this.app.browserWindow(mainWindow); + 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; + const firstServerId = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].webContentsId; + await env.loginToMattermost(firstServer); + await firstServer.waitForSelector('#searchBox'); + + robot.keyTap('=', [env.cmdOrCtrl]); + await asyncSleep(1000); + console.log(firstServerId); + let zoomLevel = await browserWindow.evaluate((window, id) => window.getBrowserViews().find((view) => view.webContents.id === id).webContents.getZoomFactor(), firstServerId); + zoomLevel.should.be.greaterThan(1); + + robot.keyTap('0', [env.cmdOrCtrl]); + await asyncSleep(1000); + zoomLevel = await browserWindow.evaluate((window, id) => window.getBrowserViews().find((view) => view.webContents.id === id).webContents.getZoomFactor(), firstServerId); + zoomLevel.should.be.equal(1); }); it('MM-T818 Zoom in from the menu bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - 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 mainWindow.click('button.three-dot-menu'); - robot.keyTap('v'); - robot.keyTap('z'); - robot.keyTap('enter'); - const zoomLevel = await firstServer.evaluate('window.devicePixelRatio'); - zoomLevel.should.be.greaterThan(1); - } + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); + const browserWindow = await this.app.browserWindow(mainWindow); + 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; + const firstServerId = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].webContentsId; + await env.loginToMattermost(firstServer); + await firstServer.waitForSelector('#searchBox'); + + robot.keyTap('=', [env.cmdOrCtrl]); + await asyncSleep(1000); + const zoomLevel = await browserWindow.evaluate((window, id) => window.getBrowserViews().find((view) => view.webContents.id === id).webContents.getZoomFactor(), firstServerId); + zoomLevel.should.be.greaterThan(1); }); it('MM-T819 Zoom out from the menu bar', async () => { - if (process.platform === 'win32' || process.platform === 'linux') { - const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - 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 mainWindow.click('button.three-dot-menu'); - robot.keyTap('v'); - robot.keyTap('z'); - robot.keyTap('z'); - robot.keyTap('enter'); - const zoomLevel = await firstServer.evaluate('window.devicePixelRatio'); - zoomLevel.should.be.lessThan(1); - } + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); + const browserWindow = await this.app.browserWindow(mainWindow); + 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; + const firstServerId = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].webContentsId; + await env.loginToMattermost(firstServer); + await firstServer.waitForSelector('#searchBox'); + + robot.keyTap('-', [env.cmdOrCtrl]); + await asyncSleep(1000); + const zoomLevel = await browserWindow.evaluate((window, id) => window.getBrowserViews().find((view) => view.webContents.id === id).webContents.getZoomFactor(), firstServerId); + zoomLevel.should.be.lessThan(1); }); describe('Reload', () => { @@ -187,7 +147,7 @@ describe('menu/view', function desc() { let webContentsId; beforeEach(async () => { - const mainWindow = await this.app.firstWindow(); + const mainWindow = this.app.windows().find((window) => window.url().includes('index')); browserWindow = await this.app.browserWindow(mainWindow); webContentsId = this.serverMap[`${config.teams[0].name}___TAB_MESSAGING`].webContentsId; @@ -198,7 +158,7 @@ describe('menu/view', function desc() { it('MM-T814 should reload page when pressing Ctrl+R', async () => { const check = browserWindow.evaluate(setupPromise, webContentsId); await asyncSleep(500); - robot.keyTap('r', ['control']); + robot.keyTap('r', [env.cmdOrCtrl]); const result = await check; result.should.be.true; }); @@ -206,156 +166,59 @@ describe('menu/view', function desc() { it('MM-T815 should reload page when pressing Ctrl+Shift+R', async () => { const check = browserWindow.evaluate(setupPromise, webContentsId); await asyncSleep(500); - robot.keyTap('r', ['control', 'shift']); + robot.keyTap('r', [env.cmdOrCtrl, 'shift']); const result = await check; result.should.be.true; }); }); - describe('Toggle DevTools', () => { - const CharPerMin = 600; - const DelayBetweenInputs = 500; // ms - const DevToolsLoadTime = 7000; // ms - const DevToolsLoadTimeBuffer = 10000; // ms - const MaxDialogEventWaitTime = 6000; // ms - beforeEach(async () => { + it('MM-T820 should open Developer Tools For Application Wrapper for main window', async () => { + const mainWindow = this.app.windows().find((window) => window.url().includes('loadingScreen')); + const browserWindow = await this.app.browserWindow(mainWindow); + const loadingScreen = this.app.windows().find((window) => window.url().includes('loadingScreen')); + await loadingScreen.waitForSelector('.LoadingScreen', {state: 'hidden'}); + + let isDevToolsOpen = await browserWindow.evaluate((window) => { + return window.webContents.isDevToolsOpened(); + }); + isDevToolsOpen.should.be.false; + + robot.keyTap('i', process.platform === 'darwin' ? ['command', 'alt'] : ['control', 'shift']); + await asyncSleep(1000); + + isDevToolsOpen = await browserWindow.evaluate((window) => { + return window.webContents.isDevToolsOpened(); + }); + isDevToolsOpen.should.be.true; + }); + + // TODO: Missing shortcut for macOS + if (process.platform !== 'darwin') { + it('MM-T821 should open Developer Tools For Current Server for the active tab', async () => { + const mainWindow = this.app.windows().find((window) => window.url().includes('loadingScreen')); + 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'}); + + let isDevToolsOpen = await browserWindow.evaluate((window, id) => { + return window.getBrowserViews().find((view) => view.webContents.id === id).webContents.isDevToolsOpened(); + }, webContentsId); + isDevToolsOpen.should.be.false; + + // Open Developer Tools for Current Server + robot.keyTap('alt'); + robot.keyTap('enter'); + robot.keyTap('v'); + robot.keyTap('d'); + robot.keyTap('d'); + robot.keyTap('enter'); + await asyncSleep(1000); + + isDevToolsOpen = await browserWindow.evaluate((window, id) => { + return window.getBrowserViews().find((view) => view.webContents.id === id).webContents.isDevToolsOpened(); + }, webContentsId); + isDevToolsOpen.should.be.true; }); - - it('MM-T820 should open dev tools for Application Wrapper when pressing keyboard shortcuts', async () => { - const macModifierKeys = ['command', 'alt']; - const winModifierKeys = ['shift', 'control']; - - const windowLoaded = windowEventPromise(this.app); - robotKeyTaps(1, 'i', process.platform === 'darwin' ? macModifierKeys : winModifierKeys); - - const window = await windowLoaded; - const windowTitle = await window.title(); - - const isWindowTitleDevTools = windowTitle === 'DevTools'; - isWindowTitleDevTools.should.be.true; - }); - - it.skip('MM-T820 dev tools opened through keyboard shortcuts should point to index.html', async () => { - const macModifierKeys = ['command', 'alt']; - const winModifierKeys = ['shift', 'control']; - - robotKeyTaps(1, 'i', process.platform === 'darwin' ? macModifierKeys : winModifierKeys); - - // check the url - await asyncSleep(DevToolsLoadTime); - await openDevToolsConsoleTab(); - - const allWindowsDialogEventListener = windowsDialogEventPromises(this.app, MaxDialogEventWaitTime); - await asyncSleep(DelayBetweenInputs); - robot.typeStringDelayed('alert (window?.location?.href)', CharPerMin); - await asyncSleep(DelayBetweenInputs); - robotKeyTaps(1, 'enter'); - - const windowAlertDialog = await Promise.any(allWindowsDialogEventListener); - const alertMsg = windowAlertDialog?.message(); - const devToolsPointsToIndexHtml = alertMsg.endsWith('index.html'); - devToolsPointsToIndexHtml.should.be.true; - }); - - it('MM-T820 should open dev tools for Application Wrapper through menu, View > Developer Tools for Application Wrapper', async () => { - const windowLoaded = windowEventPromise(this.app); - - if (process.platform === 'darwin') { - robotKeyTaps(1, 'f2', ['control']); - robotKeyTaps(3, 'right'); - robotKeyTaps(1, 'enter'); - robotKeyTaps(2, 'up'); - robotKeyTaps(1, 'enter'); - } else { - await clickThreeDotMenu(this.app); - robotKeyTaps(3, 'down'); - robotKeyTaps(1, 'right'); - robotKeyTaps(2, 'up'); - robotKeyTaps(2, 'enter'); - } - - const window = await windowLoaded; - const windowTitle = await window.title(); - - const isWindowTitleDevTools = windowTitle === 'DevTools'; - isWindowTitleDevTools.should.be.true; - }); - - it.skip('MM-T820 dev tools opened through menu, should point to index.html', async () => { - if (process.platform === 'darwin') { - robotKeyTaps(1, 'f2', ['control']); - robotKeyTaps(3, 'right'); - robotKeyTaps(1, 'enter'); - robotKeyTaps(2, 'up'); - robotKeyTaps(1, 'enter'); - } else { - await clickThreeDotMenu(this.app); - robotKeyTaps(3, 'down'); - robotKeyTaps(1, 'right'); - robotKeyTaps(2, 'up'); - robotKeyTaps(2, 'enter'); - } - - // check the url - await asyncSleep(DevToolsLoadTime); - await openDevToolsConsoleTab(); - - const allWindowsDialogEventListener = windowsDialogEventPromises(this.app, MaxDialogEventWaitTime); - await asyncSleep(DelayBetweenInputs); - robot.typeStringDelayed('alert (window?.location?.href)', CharPerMin); - await asyncSleep(DelayBetweenInputs); - robotKeyTaps(1, 'enter'); - - const windowAlertDialog = await Promise.any(allWindowsDialogEventListener); - const alertMsg = windowAlertDialog?.message(); - const devToolsPointsToIndexHtml = alertMsg.endsWith('index.html'); - devToolsPointsToIndexHtml.should.be.true; - }); - - it('MM-T821 should open dev tools for Current Server through menu, View > Developer Tools for Current Server', async () => { - const windowLoaded = windowEventPromise(this.app); - if (process.platform === 'darwin') { - robotKeyTaps(1, 'f2', ['control']); - robotKeyTaps(3, 'right'); - robotKeyTaps(1, 'enter'); - robotKeyTaps(1, 'up'); - robotKeyTaps(1, 'enter'); - } else { - await clickThreeDotMenu(this.app); - robotKeyTaps(3, 'down'); - robotKeyTaps(1, 'right'); - robotKeyTaps(1, 'up'); - robotKeyTaps(1, 'enter'); - } - - const window = await windowLoaded; - const windowTitle = await window.title(); - - const isWindowTitleDevTools = windowTitle === 'DevTools'; - isWindowTitleDevTools.should.be.true; - }); - - it.skip('MM-T821 dev tools should point to localhost:8065 ', async () => { - // check the url - await asyncSleep(DevToolsLoadTimeBuffer); - await openDevToolsConsoleTab(); - - const allWindowsDialogEventListener = windowsDialogEventPromises(this.app, MaxDialogEventWaitTime); - await asyncSleep(DelayBetweenInputs); - robot.typeStringDelayed('alert (window?.location?.href)', CharPerMin); - await asyncSleep(DelayBetweenInputs); - robotKeyTaps(1, 'enter'); - - const windowAlertDialog = await Promise.any(allWindowsDialogEventListener); - - const alertMsg = windowAlertDialog?.message(); - const devToolsPointsToIndexHtml = alertMsg.endsWith('index.html'); - devToolsPointsToIndexHtml.should.be.false; - - const devToolsPointsToCurrentServer = alertMsg.includes('localhost:8065'); - devToolsPointsToCurrentServer.should.be.true; - }); - }); + } }); diff --git a/e2e/specs/menu_bar/window_menu.test.js b/e2e/specs/menu_bar/window_menu.test.js index c626627e..b7bd36a2 100644 --- a/e2e/specs/menu_bar/window_menu.test.js +++ b/e2e/specs/menu_bar/window_menu.test.js @@ -40,6 +40,8 @@ describe('Menu/window_menu', function desc() { lastActiveTab: 0, }, ], + minimizeToTray: true, + alwaysMinimize: true, }; beforeEach(async () => { @@ -64,16 +66,16 @@ describe('Menu/window_menu', function desc() { let dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton'); dropdownButtonText.should.equal('example'); - robot.keyTap('2', ['control', 'shift']); - dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton'); + robot.keyTap('2', ['control', process.platform === 'darwin' ? 'command' : 'shift']); + dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton:has-text("github")'); dropdownButtonText.should.equal('github'); - robot.keyTap('3', ['control', 'shift']); - dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton'); + robot.keyTap('3', ['control', process.platform === 'darwin' ? 'command' : 'shift']); + dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton:has-text("google")'); dropdownButtonText.should.equal('google'); - robot.keyTap('1', ['control', 'shift']); - dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton'); + robot.keyTap('1', ['control', process.platform === 'darwin' ? 'command' : 'shift']); + dropdownButtonText = await mainWindow.innerText('.TeamDropdownButton:has-text("example")'); dropdownButtonText.should.equal('example'); }); @@ -83,15 +85,15 @@ describe('Menu/window_menu', function desc() { let tabViewButton = await mainView.innerText('.active'); tabViewButton.should.equal('Channels'); - robot.keyTap('2', [process.platform === 'darwin' ? 'command' : 'control']); + robot.keyTap('2', [env.cmdOrCtrl]); tabViewButton = await mainView.innerText('.active'); tabViewButton.should.equal('Boards'); - robot.keyTap('3', [process.platform === 'darwin' ? 'command' : 'control']); + robot.keyTap('3', [env.cmdOrCtrl]); tabViewButton = await mainView.innerText('.active'); tabViewButton.should.equal('Playbooks'); - robot.keyTap('1', [process.platform === 'darwin' ? 'command' : 'control']); + robot.keyTap('1', [env.cmdOrCtrl]); tabViewButton = await mainView.innerText('.active'); tabViewButton.should.equal('Channels'); }); @@ -111,25 +113,27 @@ describe('Menu/window_menu', function desc() { tabViewButton.should.equal('Channels'); }); - it.skip('MM-T824 should be minimized when keyboard shortcuts are pressed', async () => { - const browserWindow = await this.app.browserWindow(await this.app.firstWindow()); + it('MM-T824 should be minimized when keyboard shortcuts are pressed', async () => { const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('w'); - robot.keyTap('m'); - robot.keyTap('enter'); + const browserWindow = await this.app.browserWindow(mainWindow); + if (process.platform === 'darwin') { + robot.keyTap('m', [env.cmdOrCtrl]); + } else { + await mainWindow.click('button.three-dot-menu'); + robot.keyTap('w'); + robot.keyTap('m'); + robot.keyTap('enter'); + } + await asyncSleep(2000); const isMinimized = await browserWindow.evaluate((window) => window.isMinimized()); isMinimized.should.be.true; }); - it.skip('MM-T825 should be hidden when keyboard shortcuts are pressed', async () => { - const browserWindow = await this.app.browserWindow(await this.app.firstWindow()); + it('MM-T825 should be hidden when keyboard shortcuts are pressed', async () => { const mainWindow = this.app.windows().find((window) => window.url().includes('index')); - await mainWindow.click('button.three-dot-menu'); - robot.keyTap('w'); - robot.keyTap('c'); - robot.keyTap('enter'); + const browserWindow = await this.app.browserWindow(mainWindow); + robot.keyTap('w', [env.cmdOrCtrl]); await asyncSleep(2000); const isVisible = await browserWindow.evaluate((window) => window.isVisible()); isVisible.should.be.false; diff --git a/e2e/specs/server_management/add_server_modal.test.js b/e2e/specs/server_management/add_server_modal.test.js index 85eaead3..55baa700 100644 --- a/e2e/specs/server_management/add_server_modal.test.js +++ b/e2e/specs/server_management/add_server_modal.test.js @@ -159,7 +159,6 @@ describe('Add Server Modal', function desc() { order: 2, }, ], - lastActiveTab: 0, }); }); }); diff --git a/e2e/specs/server_management/edit_server_modal.test.js b/e2e/specs/server_management/edit_server_modal.test.js index 02685ff8..6060e6b1 100644 --- a/e2e/specs/server_management/edit_server_modal.test.js +++ b/e2e/specs/server_management/edit_server_modal.test.js @@ -233,8 +233,7 @@ describe('EditServerModal', function desc() { }); }); - // TODO: disabling flaky test - it.skip('MM-T4391_4 should edit team when Save is pressed and both edited', async () => { + it('MM-T4391_4 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'); diff --git a/e2e/specs/server_management/header.test.js b/e2e/specs/server_management/header.test.js index c88143f2..fb582740 100644 --- a/e2e/specs/server_management/header.test.js +++ b/e2e/specs/server_management/header.test.js @@ -29,7 +29,7 @@ describe('header', function desc() { const initialBounds = {x: 0, y: 0, width: 800, height: 400, maximized: false}; fs.writeFileSync(env.boundsInfoPath, JSON.stringify(initialBounds)); this.app = await env.getApp(); - const mainWindow = await this.app.firstWindow(); + const mainWindow = await this.app.windows().find((window) => window.url().includes('index')); const browserWindow = await this.app.browserWindow(mainWindow); const header = await mainWindow.locator('div.topBar'); const headerBounds = await header.boundingBox(); diff --git a/e2e/specs/settings.test.js b/e2e/specs/settings.test.js index 17536364..974a16f5 100644 --- a/e2e/specs/settings.test.js +++ b/e2e/specs/settings.test.js @@ -41,7 +41,7 @@ describe('Settings', function desc() { predicate: (window) => window.url().includes('settings'), }); await settingsWindow.waitForSelector('.settingsPage.container'); - await settingsWindow.waitForSelector('#inputAutoStart'); + await settingsWindow.waitForSelector('#inputAutoStart', {state: expected ? 'attached' : 'detached'}); const existing = await settingsWindow.isVisible('#inputAutoStart'); existing.should.equal(expected); }); @@ -57,7 +57,7 @@ describe('Settings', function desc() { predicate: (window) => window.url().includes('settings'), }); await settingsWindow.waitForSelector('.settingsPage.container'); - await settingsWindow.waitForSelector('#inputShowTrayIcon'); + await settingsWindow.waitForSelector('#inputShowTrayIcon', {state: expected ? 'attached' : 'detached'}); const existing = await settingsWindow.isVisible('#inputShowTrayIcon'); existing.should.equal(expected); }); @@ -115,8 +115,8 @@ describe('Settings', function desc() { }); describe('Leave app running in notification area when application window is closed', () => { - it('MM-T4394 should appear on linux', async () => { - const expected = (process.platform === 'linux'); + it('MM-T4394 should appear on linux and win32', async () => { + const expected = (process.platform === 'linux' || process.platform === 'win32'); this.app.evaluate(({ipcMain}, showWindow) => { ipcMain.emit(showWindow); }, SHOW_SETTINGS_WINDOW); @@ -210,31 +210,33 @@ describe('Settings', function desc() { }); }); - describe('Enable automatic check for updates', () => { - it('MM-T4549 should save selected option', async () => { - const ID_INPUT_ENABLE_AUTO_UPDATES = '#inputAutoCheckForUpdates'; - this.app.evaluate(({ipcMain}, showWindow) => { - ipcMain.emit(showWindow); - }, SHOW_SETTINGS_WINDOW); - const settingsWindow = await this.app.waitForEvent('window', { - predicate: (window) => window.url().includes('settings'), + if (process.platform !== 'darwin') { + describe('Enable automatic check for updates', () => { + it('MM-T4549 should save selected option', async () => { + const ID_INPUT_ENABLE_AUTO_UPDATES = '#inputAutoCheckForUpdates'; + 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_AUTO_UPDATES); + selected.should.equal(true); // default is true + + await settingsWindow.click(ID_INPUT_ENABLE_AUTO_UPDATES); + await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saving...")'); + await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saved")'); + const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); + config0.autoCheckForUpdates.should.equal(false); + + await settingsWindow.click(ID_INPUT_ENABLE_AUTO_UPDATES); + await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saving...")'); + await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saved")'); + const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); + config1.autoCheckForUpdates.should.equal(true); }); - await settingsWindow.waitForSelector('.settingsPage.container'); - const selected = await settingsWindow.isChecked(ID_INPUT_ENABLE_AUTO_UPDATES); - selected.should.equal(true); // default is true - - await settingsWindow.click(ID_INPUT_ENABLE_AUTO_UPDATES); - await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saving...")'); - await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saved")'); - const config0 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); - config0.autoCheckForUpdates.should.equal(false); - - await settingsWindow.click(ID_INPUT_ENABLE_AUTO_UPDATES); - await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saving...")'); - await settingsWindow.waitForSelector('.updatesSaveIndicator :text("Saved")'); - const config1 = JSON.parse(fs.readFileSync(env.configFilePath, 'utf-8')); - config1.autoCheckForUpdates.should.equal(true); }); - }); + } }); }); diff --git a/e2e/specs/startup/window.test.js b/e2e/specs/startup/window.test.js index 92a34430..0db84c83 100644 --- a/e2e/specs/startup/window.test.js +++ b/e2e/specs/startup/window.test.js @@ -24,28 +24,24 @@ describe('window', function desc() { } }); - it.skip('MM-T4403_1 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(); - }); + // TODO: this fails on Linux right now due to the window frame for some reason + if (process.platform !== 'linux') { + it('MM-T4403_1 should restore window bounds', async () => { + 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.windows().find((window) => window.url().includes('index')); + 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('MM-T4403_2 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 mainWindow = await this.app.windows().find((window) => window.url().includes('index')); const browserWindow = await this.app.browserWindow(mainWindow); const bounds = await browserWindow.evaluate((window) => window.getContentBounds()); bounds.x.should.satisfy((x) => (x > -100000)); @@ -53,12 +49,9 @@ describe('window', function desc() { }); it('MM-T4403_3 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 mainWindow = await this.app.windows().find((window) => window.url().includes('index')); const browserWindow = await this.app.browserWindow(mainWindow); const bounds = await browserWindow.evaluate((window) => window.getContentBounds()); bounds.y.should.satisfy((y) => (y < 200000)); diff --git a/src/main/tray/tray.ts b/src/main/tray/tray.ts index ec5d0069..4dfde10e 100644 --- a/src/main/tray/tray.ts +++ b/src/main/tray/tray.ts @@ -107,6 +107,10 @@ export function setupTray(icontheme: string) { } function setTray(status: string, message: string) { + if (trayIcon.isDestroyed()) { + return; + } + lastStatus = status; lastMessage = message; trayIcon.setImage(trayImages[status]); diff --git a/src/main/views/MattermostView.ts b/src/main/views/MattermostView.ts index b9e97654..36e14b91 100644 --- a/src/main/views/MattermostView.ts +++ b/src/main/views/MattermostView.ts @@ -105,6 +105,10 @@ export class MattermostView extends EventEmitter { // wait for screen to truly finish loading before sending the message down const timeout = setInterval(() => { + if (!this.view.webContents) { + return; + } + if (!this.view.webContents.isLoading()) { try { this.view.webContents.send(SET_VIEW_OPTIONS, this.tab.name, this.tab.shouldNotify); diff --git a/src/renderer/components/SettingsPage.tsx b/src/renderer/components/SettingsPage.tsx index 5f9147ac..e84c65f0 100644 --- a/src/renderer/components/SettingsPage.tsx +++ b/src/renderer/components/SettingsPage.tsx @@ -129,7 +129,7 @@ export default class SettingsPage extends React.PureComponent { window.ipcRenderer.invoke(GET_LOCAL_CONFIGURATION).then((config) => { - this.setState({ready: true, maximized: false, ...this.convertConfigDataToState(config) as Omit}); + this.setState({ready: true, maximized: false, ...this.convertConfigDataToState(config, this.state) as Omit}); }); } @@ -161,8 +161,8 @@ export default class SettingsPage extends React.PureComponent { this.savingIsDebounced = false; + window.ipcRenderer.send(UPDATE_CONFIGURATION, this.saveQueue.splice(0, this.saveQueue.length)); }, 500); - window.ipcRenderer.send(UPDATE_CONFIGURATION, this.saveQueue.splice(0, this.saveQueue.length)); } updateSaveState = () => { @@ -197,13 +197,12 @@ export default class SettingsPage extends React.PureComponent { this.resetSaveStateIsDebounced = false; + if (this.state.savingState[configType] !== SavingState.SAVING_STATE_SAVING) { + const savingState = Object.assign({}, this.state.savingState); + savingState[configType] = SavingState.SAVING_STATE_DONE; + this.setState({savingState}); + } }, 2000); - - if (this.state.savingState[configType] !== SavingState.SAVING_STATE_SAVING) { - const savingState = Object.assign({}, this.state.savingState); - savingState[configType] = SavingState.SAVING_STATE_DONE; - this.setState({savingState}); - } } handleChangeShowTrayIcon = () => {