Skip to content

Commit f5eec13

Browse files
authored
test(action-sheet): migrate to playwright (#25523)
1 parent ab63623 commit f5eec13

File tree

71 files changed

+178
-335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+178
-335
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { expect } from '@playwright/test';
2+
import type { Locator } from '@playwright/test';
3+
import { test } from '@utils/test/playwright';
4+
import type { E2EPage } from '@utils/test/playwright';
5+
6+
test.describe('action sheet: basic', () => {
7+
let actionSheetFixture: ActionSheetFixture;
8+
test.beforeEach(async ({ page }) => {
9+
await page.goto(`/src/components/action-sheet/test/basic`);
10+
actionSheetFixture = new ActionSheetFixture(page);
11+
});
12+
test.describe('action sheet: data', () => {
13+
test('should return data', async ({ page }, testInfo) => {
14+
test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs. RTL layout.');
15+
const ionActionSheetDidDismiss = await page.spyOnEvent('ionActionSheetDidDismiss');
16+
17+
await actionSheetFixture.open('#buttonData');
18+
19+
const buttonOption = page.locator('ion-action-sheet button#option');
20+
await buttonOption.click();
21+
22+
await ionActionSheetDidDismiss.next();
23+
expect(ionActionSheetDidDismiss).toHaveReceivedEventDetail({ data: { type: '1' } });
24+
});
25+
test('should return cancel button data', async ({ page }, testInfo) => {
26+
test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs. RTL layout.');
27+
const ionActionSheetDidDismiss = await page.spyOnEvent('ionActionSheetDidDismiss');
28+
29+
await actionSheetFixture.open('#buttonData');
30+
31+
const buttonOption = page.locator('ion-action-sheet button.action-sheet-cancel');
32+
await buttonOption.click();
33+
34+
await ionActionSheetDidDismiss.next();
35+
expect(ionActionSheetDidDismiss).toHaveReceivedEventDetail({ data: { type: 'cancel' }, role: 'cancel' });
36+
});
37+
});
38+
test.describe('action sheet: attributes', () => {
39+
test('should set htmlAttributes', async ({ page }, testInfo) => {
40+
test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs. RTL layout.');
41+
await actionSheetFixture.open('#basic');
42+
43+
const actionSheet = page.locator('ion-action-sheet');
44+
expect(actionSheet).toHaveAttribute('data-testid', 'basic-action-sheet');
45+
});
46+
});
47+
test.describe('action sheet: variants', () => {
48+
test('should open basic action sheet', async () => {
49+
await actionSheetFixture.open('#basic');
50+
await actionSheetFixture.screenshot('basic');
51+
52+
/**
53+
* We want to test that the dismiss method
54+
* actually works, but we do not need to test
55+
* it every time. As a result, we only
56+
* call dismiss in this test.
57+
*/
58+
await actionSheetFixture.dismiss();
59+
});
60+
test('should open cancel only action sheet', async () => {
61+
await actionSheetFixture.open('#cancelOnly');
62+
await actionSheetFixture.screenshot('cancel-only');
63+
});
64+
test('should open custom action sheet', async () => {
65+
await actionSheetFixture.open('#custom');
66+
await actionSheetFixture.screenshot('custom');
67+
});
68+
test('should open scrollable action sheet', async () => {
69+
await actionSheetFixture.open('#scrollableOptions');
70+
await actionSheetFixture.screenshot('scrollable-options');
71+
});
72+
test('should open scrollable action sheet without cancel', async () => {
73+
await actionSheetFixture.open('#scrollWithoutCancel');
74+
await actionSheetFixture.screenshot('scroll-without-cancel');
75+
});
76+
test('should open custom backdrop action sheet', async ({ page }, testInfo) => {
77+
test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs. RTL layout.');
78+
await actionSheetFixture.open('#customBackdrop');
79+
80+
const backdrop = page.locator('ion-action-sheet ion-backdrop');
81+
expect(backdrop).toHaveCSS('opacity', '1');
82+
});
83+
test('should open alert from action sheet', async ({ page }, testInfo) => {
84+
test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs. RTL layout.');
85+
const ionAlertDidPresent = await page.spyOnEvent('ionAlertDidPresent');
86+
await actionSheetFixture.open('#alertFromActionSheet');
87+
88+
await page.locator('#open-alert').click();
89+
90+
await ionAlertDidPresent.next();
91+
});
92+
test('should not dismiss action sheet when backdropDismiss: false', async ({ page }, testInfo) => {
93+
test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs. RTL layout.');
94+
await actionSheetFixture.open('#noBackdropDismiss');
95+
96+
const actionSheet = page.locator('ion-action-sheet');
97+
await actionSheet.locator('ion-backdrop').click();
98+
99+
expect(actionSheet).toBeVisible();
100+
});
101+
});
102+
test.describe('action sheet: focus trap', () => {
103+
test('it should trap focus in action sheet', async ({ page, browserName }, testInfo) => {
104+
test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs. RTL layout.');
105+
const tabKey = browserName === 'webkit' ? 'Alt+Tab' : 'Tab';
106+
107+
await actionSheetFixture.open('#basic');
108+
const buttons = page.locator('ion-action-sheet button');
109+
110+
await page.keyboard.press(tabKey);
111+
await expect(buttons.nth(0)).toBeFocused();
112+
113+
await page.keyboard.press(`Shift+${tabKey}`);
114+
await expect(buttons.nth(4)).toBeFocused();
115+
116+
await page.keyboard.press(tabKey);
117+
await expect(buttons.nth(0)).toBeFocused();
118+
});
119+
});
120+
});
121+
122+
class ActionSheetFixture {
123+
readonly page: E2EPage;
124+
125+
private actionSheet!: Locator;
126+
127+
constructor(page: E2EPage) {
128+
this.page = page;
129+
}
130+
131+
async open(selector: string) {
132+
const ionActionSheetDidPresent = await this.page.spyOnEvent('ionActionSheetDidPresent');
133+
await this.page.locator(selector).click();
134+
await ionActionSheetDidPresent.next();
135+
this.actionSheet = this.page.locator('ion-action-sheet');
136+
expect(this.actionSheet).toBeVisible();
137+
}
138+
139+
async dismiss() {
140+
const ionActionSheetDidDismiss = await this.page.spyOnEvent('ionActionSheetDidDismiss');
141+
await this.actionSheet.evaluate((el: HTMLIonActionSheetElement) => el.dismiss());
142+
await ionActionSheetDidDismiss.next();
143+
expect(this.actionSheet).not.toBeVisible();
144+
}
145+
146+
async screenshot(modifier: string) {
147+
expect(await this.actionSheet.screenshot()).toMatchSnapshot(
148+
`action-sheet-${modifier}-diff-${this.page.getSnapshotSettings()}.png`
149+
);
150+
}
151+
}

0 commit comments

Comments
 (0)