From 3e36773e3af86148b91894b0329a51ec14155747 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 29 Oct 2021 12:21:47 -0400 Subject: [PATCH] [MM-39665] MM-T1285 Edit Server Modal (#1841) * [MM-39665] MM-T1285 Edit Server Modal * Lint fix --- test/specs/browser/index_test.js | 35 ----- test/specs/browser/modal_test.js | 249 +++++++++++++++++++++++++++++++ test/specs/menu_test.js | 33 ++++ 3 files changed, 282 insertions(+), 35 deletions(-) diff --git a/test/specs/browser/index_test.js b/test/specs/browser/index_test.js index 5e17006a..e36dc17e 100644 --- a/test/specs/browser/index_test.js +++ b/test/specs/browser/index_test.js @@ -5,8 +5,6 @@ const fs = require('fs'); -const robot = require('robotjs'); - // const http = require('http'); // const path = require('path'); @@ -162,37 +160,4 @@ describe('renderer/index.html', function desc() { const modalTitle = await newServerModal.innerText('#newServerModal .modal-title'); modalTitle.should.equal('Add Server'); }); - - 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; - }); - } }); diff --git a/test/specs/browser/modal_test.js b/test/specs/browser/modal_test.js index b6aebb8f..097e5613 100644 --- a/test/specs/browser/modal_test.js +++ b/test/specs/browser/modal_test.js @@ -263,4 +263,253 @@ describe('modals', function desc() { }); }); }); + + 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, + }); + }); + }); }); diff --git a/test/specs/menu_test.js b/test/specs/menu_test.js index ac7e4b1a..ab8aea4a 100644 --- a/test/specs/menu_test.js +++ b/test/specs/menu_test.js @@ -140,4 +140,37 @@ describe('mattermost', function desc() { 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; + }); + } });