|
1 | 1 | import type { Locator } from '@playwright/test';
|
2 | 2 | import { expect } from '@playwright/test';
|
3 |
| -import type { E2EPage, E2EPageOptions } from '@utils/test/playwright'; |
| 3 | +import type { E2EPage, E2EPageOptions, ScreenshotFn } from '@utils/test/playwright'; |
4 | 4 | import { configs, test } from '@utils/test/playwright';
|
5 | 5 |
|
6 | 6 | configs().forEach(({ title, screenshot, config }) => {
|
7 |
| - test(title('should not have visual regressions'), async ({ page }) => { |
8 |
| - await page.goto(`/src/components/datetime/test/presentation`, config); |
| 7 | + test.describe(title('datetime: presentation rendering'), () => { |
| 8 | + let presentationFixture!: DatetimePresentationFixture; |
| 9 | + test.beforeEach(({ page }) => { |
| 10 | + presentationFixture = new DatetimePresentationFixture(page); |
| 11 | + }); |
| 12 | + |
| 13 | + test('should not have visual regressions with date-time presentation', async () => { |
| 14 | + await presentationFixture.goto('date-time', config); |
| 15 | + await presentationFixture.screenshot('datetime-presentation-date-time-diff', screenshot); |
| 16 | + }); |
9 | 17 |
|
10 |
| - await page.waitForSelector('.datetime-ready'); |
| 18 | + test('should not have visual regressions with time-date presentation', async () => { |
| 19 | + await presentationFixture.goto('time-date', config); |
| 20 | + await presentationFixture.screenshot('datetime-presentation-time-date-diff', screenshot); |
| 21 | + }); |
11 | 22 |
|
12 |
| - const datetime = page.locator('ion-datetime'); |
| 23 | + test('should not have visual regressions with time presentation', async () => { |
| 24 | + await presentationFixture.goto('time', config); |
| 25 | + await presentationFixture.screenshot('datetime-presentation-time-diff', screenshot); |
| 26 | + }); |
13 | 27 |
|
14 |
| - const compares = []; |
15 |
| - const presentations = ['date-time', 'time-date', 'time', 'date', 'month-year', 'month', 'year']; |
| 28 | + test('should not have visual regressions with date presentation', async () => { |
| 29 | + await presentationFixture.goto('date', config); |
| 30 | + await presentationFixture.screenshot('datetime-presentation-date-diff', screenshot); |
| 31 | + }); |
16 | 32 |
|
17 |
| - for (const presentation of presentations) { |
18 |
| - await page.locator('select').selectOption(presentation); |
19 |
| - await page.waitForChanges(); |
20 |
| - compares.push({ |
21 |
| - presentation, |
22 |
| - screenshot: datetime, |
23 |
| - }); |
24 |
| - } |
25 |
| - |
26 |
| - for (const compare of compares) { |
27 |
| - await expect(compare.screenshot).toHaveScreenshot( |
28 |
| - screenshot(`datetime-presentation-${compare.presentation}-diff`) |
29 |
| - ); |
30 |
| - } |
| 33 | + test('should not have visual regressions with month-year presentation', async () => { |
| 34 | + await presentationFixture.goto('month-year', config); |
| 35 | + await presentationFixture.screenshot('datetime-presentation-month-year-diff', screenshot); |
| 36 | + }); |
| 37 | + |
| 38 | + test('should not have visual regressions with month presentation', async () => { |
| 39 | + await presentationFixture.goto('month', config); |
| 40 | + await presentationFixture.screenshot('datetime-presentation-month-diff', screenshot); |
| 41 | + }); |
| 42 | + |
| 43 | + test('should not have visual regressions with year presentation', async () => { |
| 44 | + await presentationFixture.goto('year', config); |
| 45 | + await presentationFixture.screenshot('datetime-presentation-year-diff', screenshot); |
| 46 | + }); |
31 | 47 | });
|
32 | 48 | });
|
33 | 49 |
|
@@ -157,6 +173,31 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
|
157 | 173 | });
|
158 | 174 | });
|
159 | 175 |
|
| 176 | +class DatetimePresentationFixture { |
| 177 | + readonly page: E2EPage; |
| 178 | + |
| 179 | + private datetime!: Locator; |
| 180 | + |
| 181 | + constructor(page: E2EPage) { |
| 182 | + this.page = page; |
| 183 | + } |
| 184 | + |
| 185 | + async goto(presentation: string, config: E2EPageOptions) { |
| 186 | + await this.page.setContent( |
| 187 | + ` |
| 188 | + <ion-datetime presentation="${presentation}" value="2010-03-10T13:00:00"></ion-datetime> |
| 189 | + `, |
| 190 | + config |
| 191 | + ); |
| 192 | + await this.page.waitForSelector('.datetime-ready'); |
| 193 | + this.datetime = this.page.locator('ion-datetime'); |
| 194 | + } |
| 195 | + |
| 196 | + async screenshot(name: string, screenshotFn: ScreenshotFn) { |
| 197 | + await expect(this.datetime).toHaveScreenshot(screenshotFn(name)); |
| 198 | + } |
| 199 | +} |
| 200 | + |
160 | 201 | class TimePickerFixture {
|
161 | 202 | readonly page: E2EPage;
|
162 | 203 |
|
|
0 commit comments