Skip to content

Commit 6f13304

Browse files
authored
test: Merge modal page objects (RocketChat#37253)
1 parent 6dd5ddd commit 6f13304

8 files changed

Lines changed: 76 additions & 50 deletions

File tree

apps/meteor/client/views/modal/uikit/ModalBlock.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ const ModalBlock = ({ view, errors, onSubmit, onClose, onCancel }: ModalBlockPar
175175
return (
176176
<AnimatedVisibility visibility={AnimatedVisibility.UNHIDING}>
177177
<FocusScope contain restoreFocus autoFocus>
178-
<Modal open id={id} ref={ref}>
178+
<Modal aria-labelledby={`${id}-title`} open id={id} ref={ref}>
179179
<ModalHeader>
180180
{view.showIcon ? <ModalThumb url={getURL(`/api/apps/${view.appId}/icon`)} /> : null}
181-
<ModalTitle>{modalParser.text(view.title, UiKit.BlockContext.NONE, 0)}</ModalTitle>
181+
<ModalTitle id={`${id}-title`}>{modalParser.text(view.title, UiKit.BlockContext.NONE, 0)}</ModalTitle>
182182
<ModalClose tabIndex={-1} onClick={onClose} />
183183
</ModalHeader>
184184
<ModalContent>

apps/meteor/tests/e2e/apps/apps-modal.spec.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ import type { Page } from '@playwright/test';
33
import { IS_EE } from '../config/constants';
44
import { Users } from '../fixtures/userStates';
55
import { HomeChannel } from '../page-objects';
6-
import { Modal } from '../page-objects/modal';
6+
import { AppsModal } from '../page-objects/fragments/apps-modal';
77
import { expect, test } from '../utils/test';
88

99
test.use({ storageState: Users.user1.state });
1010

1111
test.describe.serial('Apps > Modal', () => {
1212
test.skip(!IS_EE, 'Premium Only');
1313
let poHomeChannel: HomeChannel;
14-
let poModal: Modal;
14+
let poModal: AppsModal;
1515

1616
let page: Page;
1717

1818
test.beforeAll(async ({ browser }) => {
1919
page = await browser.newPage();
2020

2121
poHomeChannel = new HomeChannel(page);
22-
poModal = new Modal(page);
22+
poModal = new AppsModal(page);
2323

2424
await page.goto('/home');
2525
await poHomeChannel.sidenav.openChat('general');
@@ -29,23 +29,17 @@ test.describe.serial('Apps > Modal', () => {
2929
await page.close();
3030
});
3131

32-
test('expect allow user open app modal', async () => {
32+
test('should allow user open app modal', async () => {
3333
await poHomeChannel.content.dispatchSlashCommand('/modal');
34-
await expect(poModal.btnModalSubmit).toBeVisible();
34+
await poModal.waitForDisplay();
3535
});
3636

37-
test('expect validation error message appears in app modal', async () => {
38-
await expect(poModal.textInput).toBeVisible();
39-
40-
await poModal.btnModalSubmit.click();
41-
37+
test('should display validation error message in app modal', async () => {
38+
await poModal.btnSubmit.click();
4239
await expect(poModal.textInputErrorMessage).toBeVisible();
4340
});
4441

45-
test("expect validation error message don't appears in app modal", async () => {
46-
await poModal.textInput.fill('something');
47-
await poModal.btnModalSubmit.click();
48-
49-
await expect(poModal.textInputErrorMessage).not.toBeVisible();
42+
test('should not display validation error message in app modal', async () => {
43+
await poModal.submit('something');
5044
});
5145
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Locator, Page } from 'playwright-core';
2+
3+
import { Modal } from './modal';
4+
5+
export class AppsModal extends Modal {
6+
protected readonly page: Page;
7+
8+
constructor(page: Page) {
9+
super(page.getByRole('dialog', { name: 'Modal Example' }));
10+
}
11+
12+
get textInput(): Locator {
13+
return this.root.locator('[name="modal_input"]');
14+
}
15+
16+
get textInputErrorMessage(): Locator {
17+
return this.root.getByText('Validation failed');
18+
}
19+
20+
get btnSubmit(): Locator {
21+
return this.root.getByRole('button', { name: 'Submit' });
22+
}
23+
24+
async submit(inputText: string) {
25+
await this.textInput.fill(inputText);
26+
await this.btnSubmit.click();
27+
await this.waitForDismissal();
28+
}
29+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Page } from 'playwright-core';
2+
3+
import { Modal } from './modal';
4+
5+
export class EditStatusModal extends Modal {
6+
protected readonly page: Page;
7+
8+
constructor(page: Page) {
9+
super(page.getByRole('dialog', { name: 'Edit Status' }));
10+
}
11+
12+
private get statusMessageInput() {
13+
return this.root.getByRole('textbox', { name: 'Status message' });
14+
}
15+
16+
async changeStatusMessage(statusMessage: string): Promise<void> {
17+
await this.statusMessageInput.fill(statusMessage);
18+
await this.save();
19+
}
20+
}

apps/meteor/tests/e2e/page-objects/fragments/modal.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@ import { expect } from '../../utils/test';
55
export abstract class Modal {
66
constructor(protected root: Locator) {}
77

8+
waitForDisplay() {
9+
return expect(this.root).toBeVisible();
10+
}
11+
812
waitForDismissal() {
913
return expect(this.root).not.toBeVisible();
1014
}
15+
16+
private get btnSave() {
17+
return this.root.getByRole('button', { name: 'Save' });
18+
}
19+
20+
async save() {
21+
await this.btnSave.click();
22+
await this.waitForDismissal();
23+
}
1124
}

apps/meteor/tests/e2e/page-objects/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ export * from './omnichannel-settings';
2020
export * from './omnichannel-business-hours';
2121
export * from './omnichannel-tags';
2222
export * from './utils';
23-
export * from './modal';
2423
export * from './marketplace';
2524
export * from './toastBar';

apps/meteor/tests/e2e/page-objects/modal.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

apps/meteor/tests/e2e/presence.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DEFAULT_USER_CREDENTIALS, IS_EE } from './config/constants';
22
import { Users } from './fixtures/userStates';
33
import { Registration, HomeChannel } from './page-objects';
4-
import { Modal } from './page-objects/modal';
4+
import { EditStatusModal } from './page-objects/fragments/edit-status-modal';
55
import { setSettingValueById } from './utils/setSettingValueById';
66
import { test, expect } from './utils/test';
77

@@ -48,12 +48,11 @@ test.describe.serial('Presence', () => {
4848
const user1Page = await browser.newPage({ storageState: Users.user1.state });
4949
await user1Page.goto('/home');
5050
const user1Channel = new HomeChannel(user1Page);
51-
const user1Modal = new Modal(user1Page);
51+
const user1Modal = new EditStatusModal(user1Page);
5252

5353
await user1Channel.sidenav.btnUserProfileMenu.click();
5454
await user1Channel.sidenav.getUserProfileMenuOption('Custom Status').click();
55-
await user1Modal.getModalByName('Edit Status').getByRole('textbox', { name: 'Status message' }).fill('new status');
56-
await user1Modal.getModalByName('Edit Status').getByRole('button', { name: 'Save' }).click();
55+
await user1Modal.changeStatusMessage('new status');
5756

5857
await user1Page.close();
5958
});

0 commit comments

Comments
 (0)