Skip to content

Commit

Permalink
E2E tests for current modals
Browse files Browse the repository at this point in the history
  • Loading branch information
devinbinnie committed Feb 11, 2025
1 parent 7525463 commit fb47697
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions e2e/specs/focus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ describe('focus', function desc() {
const newServerView = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('newServer'),
});
await newServerView.waitForSelector('#cancelNewServerModal');
await newServerView.click('#cancelNewServerModal');
await newServerView.waitForSelector('#newServerModal_cancel');
await newServerView.click('#newServerModal_cancel');

const isTextboxFocused = await firstServer.$eval('#post_textbox', (el) => el === document.activeElement);
isTextboxFocused.should.be.true;
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/menu_bar/dropdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('menu_bar/dropdown', function desc() {
const newServerModal = await this.app.waitForEvent('window', {
predicate: (window) => window.url().includes('newServer'),
});
const modalTitle = await newServerModal.innerText('#newServerModal .modal-title');
const modalTitle = await newServerModal.innerText('#newServerModal .Modal__header__text_container');
modalTitle.should.equal('Add Server');

await afterFunc();
Expand Down
33 changes: 16 additions & 17 deletions e2e/specs/server_management/add_server_modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,25 @@ describe('Add Server Modal', function desc() {
});

it('MM-T4388 should close the window after clicking cancel', async () => {
await newServerView.click('#cancelNewServerModal');
await newServerView.click('#newServerModal_cancel');
await asyncSleep(1000);
const existing = Boolean(this.app.windows().find((window) => window.url().includes('newServer')));
existing.should.be.false;
});

describe('MM-T4389 Invalid messages', () => {
it('MM-T4389_1 should not be valid and save should be disabled if no server name or URL has been set', async () => {
const existing = await newServerView.isVisible('#nameValidation.error');
existing.should.be.true;
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
const disabled = await newServerView.getAttribute('#newServerModal_confirm', 'disabled');
(disabled === '').should.be.true;
});

it('should warn the user if a server with the same URL exists, but still allow them to save', async () => {
await newServerView.type('#serverNameInput', 'some-new-server');
await newServerView.type('#serverUrlInput', config.teams[0].url);
await newServerView.waitForSelector('#urlValidation.warning');
const existing = await newServerView.isVisible('#urlValidation.warning');
await newServerView.waitForSelector('#customMessage_url.Input___warning');
const existing = await newServerView.isVisible('#customMessage_url.Input___warning');
existing.should.be.true;
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
const disabled = await newServerView.getAttribute('#newServerModal_confirm', 'disabled');
(disabled === '').should.be.false;
});

Expand All @@ -76,8 +74,8 @@ describe('Add Server Modal', function desc() {
});

it('MM-T4389_2 Name should not be marked invalid, but should not be able to save', async () => {
await newServerView.waitForSelector('#nameValidation.error', {state: 'detached'});
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
await newServerView.waitForSelector('#customMessage_name.Input___error', {state: 'detached'});
const disabled = await newServerView.getAttribute('#newServerModal_confirm', 'disabled');
(disabled === '').should.be.true;
});
});
Expand All @@ -88,9 +86,10 @@ describe('Add Server Modal', function desc() {
});

it('MM-T4389_3 URL should not be marked invalid, name should be marked invalid', async () => {
const existingUrl = await newServerView.isVisible('#urlValidation.error');
const existingName = await newServerView.isVisible('#nameValidation.error');
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
await newServerView.waitForSelector('#customMessage_name.Input___error');
const existingUrl = await newServerView.isVisible('#customMessage_url.Input___error');
const existingName = await newServerView.isVisible('#customMessage_name.Input___error');
const disabled = await newServerView.getAttribute('#newServerModal_confirm', 'disabled');
existingName.should.be.true;
existingUrl.should.be.false;
(disabled === '').should.be.true;
Expand All @@ -100,25 +99,25 @@ describe('Add Server Modal', function desc() {

it('MM-T2826_1 should not be valid if an invalid server address has been set', async () => {
await newServerView.type('#serverUrlInput', 'superInvalid url');
await newServerView.waitForSelector('#urlValidation.error');
const existing = await newServerView.isVisible('#urlValidation.error');
await newServerView.waitForSelector('#customMessage_url.Input___error');
const existing = await newServerView.isVisible('#customMessage_url.Input___error');
existing.should.be.true;
});

describe('Valid Team Settings', () => {
beforeEach(async () => {
await newServerView.type('#serverUrlInput', 'http://example.org');
await newServerView.type('#serverNameInput', 'TestServer');
await newServerView.waitForSelector('#urlValidation.warning');
await newServerView.waitForSelector('#customMessage_url.Input___warning');
});

it('should be possible to click add', async () => {
const disabled = await newServerView.getAttribute('#saveNewServerModal', 'disabled');
const disabled = await newServerView.getAttribute('#newServerModal_confirm', 'disabled');
(disabled === null).should.be.true;
});

it('MM-T2826_2 should add the server to the config file', async () => {
await newServerView.click('#saveNewServerModal');
await newServerView.click('#newServerModal_confirm');
await asyncSleep(2000);
const existing = Boolean(this.app.windows().find((window) => window.url().includes('newServer')));
existing.should.be.false;
Expand Down
16 changes: 8 additions & 8 deletions e2e/specs/server_management/edit_server_modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('EditServerModal', function desc() {
let editServerView;

it('should not edit server when Cancel is pressed', async () => {
await editServerView.click('#cancelNewServerModal');
await editServerView.click('#newServerModal_cancel');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('EditServerModal', function desc() {
});

it('MM-T4391_1 should not edit server when Save is pressed but nothing edited', async () => {
await editServerView.click('#saveNewServerModal');
await editServerView.click('#newServerModal_confirm');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
Expand Down Expand Up @@ -100,15 +100,15 @@ describe('EditServerModal', function desc() {
});

it('MM-T2826_3 should not edit server if an invalid server address has been set', async () => {
await editServerView.type('#serverUrlInput', 'superInvalid url');
await editServerView.waitForSelector('#urlValidation.error');
const existing = await editServerView.isVisible('#urlValidation.error');
await editServerView.fill('#serverUrlInput', 'superInvalid url');
await editServerView.waitForSelector('#customMessage_url.Input___error');
const existing = await editServerView.isVisible('#customMessage_url.Input___error');
existing.should.be.true;
});

it('MM-T4391_2 should edit server when Save is pressed and name edited', async () => {
await editServerView.fill('#serverNameInput', 'NewTestServer');
await editServerView.click('#saveNewServerModal');
await editServerView.click('#newServerModal_confirm');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('EditServerModal', function desc() {

it('MM-T4391_3 should edit server when Save is pressed and URL edited', async () => {
await editServerView.fill('#serverUrlInput', 'http://google.com');
await editServerView.click('#saveNewServerModal');
await editServerView.click('#newServerModal_confirm');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('EditServerModal', function desc() {
it('MM-T4391_4 should edit server when Save is pressed and both edited', async () => {
await editServerView.fill('#serverNameInput', 'NewTestServer');
await editServerView.fill('#serverUrlInput', 'http://google.com');
await editServerView.click('#saveNewServerModal');
await editServerView.click('#newServerModal_confirm');
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('editServer')));
existing.should.be.false;
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/server_management/long_server_name.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('LongServerName', function desc() {
it('MM-T4050 Long server name', async () => {
await newServerView.type('#serverNameInput', longServerName);
await newServerView.type('#serverUrlInput', longServerUrl);
await newServerView.click('#saveNewServerModal');
await newServerView.click('#newServerModal_confirm');

await asyncSleep(1000);
const existing = Boolean(this.app.windows().find((window) => window.url().includes('newServer')));
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/server_management/remove_server_modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('RemoveServerModal', function desc() {
it('MM-T4390_4 should disappear on click background', async () => {
// ignore any target closed error
try {
await removeServerView.click('.modal', {position: {x: 20, y: 20}});
await removeServerView.click('.Modal', {position: {x: 20, y: 20}});
} catch {} // eslint-disable-line no-empty
await asyncSleep(1000);
const existing = Boolean(await this.app.windows().find((window) => window.url().includes('removeServer')));
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const Modal: React.FC<Props> = (props) => {

confirmButton = (
<button
id={`${props.id}_confirm`}
autoFocus={props.autoFocusConfirmButton}
type='submit'
className={classNames('Modal__button btn btn-primary', isConfirmOrDeleteClassName, props.confirmButtonClassName, {
Expand Down Expand Up @@ -140,6 +141,7 @@ export const Modal: React.FC<Props> = (props) => {

cancelButton = (
<button
id={`${props.id}_cancel`}
type='button'
className={classNames('Modal__button btn btn-tertiary', props.cancelButtonClassName)}
onClick={handleCancel}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/NewServerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ class NewServerModal extends React.PureComponent<Props, State> {
})}
/>
<Input
id='serverNameInput'
name='name'
type='text'
inputSize={SIZE.LARGE}
Expand Down

0 comments on commit fb47697

Please sign in to comment.