From bce2811dbc7e978b9df277acf03db1c44e785161 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Thu, 14 Apr 2022 09:16:11 -0400 Subject: [PATCH] [MM-39796][MM-39872][MM-T1659][MM-T2827] E2E Tests for Popups (#2047) * [MM-39796] E2E Test: Copy and Paste when connecting plugin * [MM-39872] E2E Test Prevent browser back/forward from firing in OAuth windows --- e2e/specs/popup.test.js | 126 ++++++++++++++++++ e2e/specs/settings/keyboard_shortcuts.test.js | 4 +- 2 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 e2e/specs/popup.test.js diff --git a/e2e/specs/popup.test.js b/e2e/specs/popup.test.js new file mode 100644 index 00000000..089257b7 --- /dev/null +++ b/e2e/specs/popup.test.js @@ -0,0 +1,126 @@ +// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +'use strict'; + +const fs = require('fs'); + +const robot = require('robotjs'); + +const env = require('../modules/environment'); +const {asyncSleep} = require('../modules/utils'); + +describe('popup', function desc() { + this.timeout(40000); + + const config = env.demoMattermostConfig; + + 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(); + } + }); + + // NOTE: These tests requires that the test server have the GitHub plugin configured + describe('MM-T2827 Keyboard shortcuts in popup windows', () => { + let popupWindow; + + beforeEach(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('#sidebarItem_suscipit-4'); + await firstServer.click('#sidebarItem_suscipit-4'); + await firstServer.click('#post_textbox'); + await firstServer.type('#post_textbox', '/github connect'); + await firstServer.press('#post_textbox', 'Enter'); + + const githubLink = await firstServer.waitForSelector('a.theme.markdown__link:has-text("GitHub account")'); + githubLink.click(); + popupWindow = await this.app.waitForEvent('window'); + const loginField = await popupWindow.waitForSelector('#login_field'); + await loginField.focus(); + await loginField.type('mattermost'); + }); + + it('MM-T2827_1 should be able to select all in popup windows', async () => { + robot.keyTap('a', [process.platform === 'darwin' ? 'command' : 'control']); + const selectedText = await popupWindow.evaluate(() => { + const box = document.querySelectorAll('#login_field')[0]; + return box.value.substring(box.selectionStart, + box.selectionEnd); + }); + selectedText.should.equal('mattermost'); + }); + + it('MM-T2827_2 should be able to cut and paste in popup windows', async () => { + const textbox = await popupWindow.waitForSelector('#login_field'); + + await textbox.selectText({force: true}); + robot.keyTap('x', [process.platform === 'darwin' ? 'command' : 'control']); + let textValue = await textbox.inputValue(); + textValue.should.equal(''); + + await textbox.focus(); + robot.keyTap('v', [process.platform === 'darwin' ? 'command' : 'control']); + textValue = await textbox.inputValue(); + textValue.should.equal('mattermost'); + }); + + it('MM-T2827_3 should be able to copy and paste in popup windows', async () => { + const textbox = await popupWindow.waitForSelector('#login_field'); + + await textbox.selectText({force: true}); + robot.keyTap('c', [process.platform === 'darwin' ? 'command' : 'control']); + await textbox.focus(); + await textbox.type('other-text'); + robot.keyTap('v', [process.platform === 'darwin' ? 'command' : 'control']); + const textValue = await textbox.inputValue(); + textValue.should.equal('other-textmattermost'); + }); + }); + + it('MM-T1659 should not be able to go Back or Forward in the popup window', 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('#sidebarItem_suscipit-4'); + await firstServer.click('#sidebarItem_suscipit-4'); + await firstServer.click('#post_textbox'); + await firstServer.type('#post_textbox', '/github connect'); + await firstServer.press('#post_textbox', 'Enter'); + + const githubLink = await firstServer.waitForSelector('a.theme.markdown__link:has-text("GitHub account")'); + githubLink.click(); + const popupWindow = await this.app.waitForEvent('window'); + popupWindow.focus(); + const currentURL = popupWindow.url(); + + // Try and go back + if (process.platform === 'darwin') { + robot.keyTap('[', ['command']); + } else { + robot.keyTap('left', ['alt']); + } + popupWindow.url().should.equal(currentURL); + + // Try and go forward + if (process.platform === 'darwin') { + robot.keyTap(']', ['command']); + } else { + robot.keyTap('right', ['alt']); + } + popupWindow.url().should.equal(currentURL); + }); +}); diff --git a/e2e/specs/settings/keyboard_shortcuts.test.js b/e2e/specs/settings/keyboard_shortcuts.test.js index 549976ec..6832e360 100644 --- a/e2e/specs/settings/keyboard_shortcuts.test.js +++ b/e2e/specs/settings/keyboard_shortcuts.test.js @@ -58,7 +58,7 @@ describe('settings/keyboard_shortcuts', function desc() { selectedText.should.equal('mattermost'); }); - it('MM-T1288_1 should be able to cut and paste in the settings window', async () => { + it('MM-T1288_2 should be able to cut and paste in the settings window', async () => { const textbox = await settingsWindow.waitForSelector('#inputSpellCheckerLocalesDropdown'); await textbox.selectText({force: true}); @@ -72,7 +72,7 @@ describe('settings/keyboard_shortcuts', function desc() { textValue.should.equal('mattermost'); }); - it('MM-T1288_1 should be able to copy and paste in the settings window', async () => { + it('MM-T1288_3 should be able to copy and paste in the settings window', async () => { const textbox = await settingsWindow.waitForSelector('#inputSpellCheckerLocalesDropdown'); await textbox.selectText({force: true});