Skip to content

Commit 7cfde33

Browse files
authored
test(loading): migrate loading tests to playwright (#25258)
1 parent 617ec48 commit 7cfde33

File tree

76 files changed

+118
-137
lines changed

Some content is hidden

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

76 files changed

+118
-137
lines changed

core/src/components/loading/test/basic/e2e.ts

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { expect } from '@playwright/test';
2+
import type { E2EPage } from '@utils/test/playwright';
3+
import { test } from '@utils/test/playwright';
4+
5+
test.describe('loading: basic', () => {
6+
test.beforeEach(async ({ page }) => {
7+
await page.goto('/src/components/loading/test/basic');
8+
});
9+
test.describe('loading: visual regression tests', () => {
10+
const runVisualTest = async (page: E2EPage, selector: string, screenshotModifier: string) => {
11+
const ionLoadingDidPresent = await page.spyOnEvent('ionLoadingDidPresent');
12+
const ionLoadingDidDismiss = await page.spyOnEvent('ionLoadingDidPresent');
13+
14+
await page.click(selector);
15+
16+
await ionLoadingDidPresent.next();
17+
18+
expect(await page.screenshot()).toMatchSnapshot(
19+
`loading-${screenshotModifier}-diff-${page.getSnapshotSettings()}.png`
20+
);
21+
22+
const loading = await page.locator('ion-loading');
23+
await loading.evaluate((el: HTMLIonLoadingElement) => el.dismiss());
24+
25+
await ionLoadingDidDismiss.next();
26+
27+
expect(loading).toBeHidden();
28+
};
29+
test('should open a basic loader', async ({ page }) => {
30+
await runVisualTest(page, '#basic-loading', 'basic');
31+
});
32+
test('should open a loader with long text', async ({ page }) => {
33+
await runVisualTest(page, '#long-content-loading', 'long-content');
34+
});
35+
test('should open a loader with no spinner', async ({ page }) => {
36+
await runVisualTest(page, '#no-spinner-loading', 'no-spinner');
37+
});
38+
test('should open a translucent loader', async ({ page }) => {
39+
await runVisualTest(page, '#translucent-loading', 'translucent');
40+
});
41+
test('should open a loader with a custom class', async ({ page }) => {
42+
await runVisualTest(page, '#no-spinner-loading', 'no-spinner');
43+
});
44+
test('should open a loader with html content', async ({ page }) => {
45+
await runVisualTest(page, '#html-content-loading', 'html-content');
46+
});
47+
});
48+
test.describe('loading: html attributes', () => {
49+
test('it should pass html attributes to the loader', async ({ page }) => {
50+
const ionLoadingDidPresent = await page.spyOnEvent('ionLoadingDidPresent');
51+
52+
await page.click('#basic-loading');
53+
54+
await ionLoadingDidPresent.next();
55+
56+
const loading = await page.locator('ion-loading');
57+
expect(loading).toHaveAttribute('data-testid', 'basic-loading');
58+
});
59+
});
60+
test.describe('loading: focus trapping', () => {
61+
test('it should trap focus in the loader', async ({ page, browserName }) => {
62+
const ionLoadingDidPresent = await page.spyOnEvent('ionLoadingDidPresent');
63+
64+
await page.click('#html-content-loading');
65+
66+
await ionLoadingDidPresent.next();
67+
68+
const button = await page.locator('ion-loading ion-button');
69+
70+
if (browserName === 'webkit') {
71+
await page.keyboard.down('Alt');
72+
}
73+
74+
await page.keyboard.press('Tab');
75+
76+
expect(button).toBeFocused();
77+
78+
await page.keyboard.down('Shift');
79+
await page.keyboard.press('Tab');
80+
await page.keyboard.up('Shift');
81+
82+
expect(button).toBeFocused();
83+
84+
await page.keyboard.press('Tab');
85+
86+
if (browserName === 'webkit') {
87+
await page.keyboard.up('Alt');
88+
}
89+
90+
expect(button).toBeFocused();
91+
});
92+
});
93+
});
97.7 KB
37.2 KB
89.9 KB
97.5 KB
37.2 KB
89.9 KB
104 KB
42.3 KB

0 commit comments

Comments
 (0)