Skip to content

Commit e1fdbb3

Browse files
test(datetime): un-flake presentation test (#28090)
Issue number: N/A --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> There are two problems with this test: 1. The screenshots are not capturing the correct UI. For example, the following screenshot should capture the date and time grid picker, but it's only capturing the year wheel picker: https://github.com/ionic-team/ionic-framework/blob/8ab3476ac7e9b05aba5328c31db763011dc0a766/core/src/components/datetime/test/presentation/datetime.e2e.ts-snapshots/datetime-presentation-date-time-diff-ios-rtl-Mobile-Safari-linux.png 2. These screenshots are flaky. This is possibly due to how they were written where they iterate through an array, select a value from the `select`, and then wait a timeout for the view to change. 3. I also discovered that we'll have some visual diffs once 2024 hits. The current value of the datetime on the wheel picker is 2022. 2023 is shown, but 2024 is not (since we are still in 2023). Once Jan 1 2024 hits, these tests will likely start to fail with visual diffs. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Refactored these tests to use a test fixture where each presentation is a separate test. This ensures that the tests are correct. Because there is less interaction going on with the page (i.e. the correct presentation is set on load), my hope is that this also reduces test flakiness. - Also changed the date used to be several years ago so we don't have new years showing up in the wheel picker screenshots as time goes on. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: ionitron <[email protected]>
1 parent 2a80eb6 commit e1fdbb3

File tree

85 files changed

+62
-21
lines changed

Some content is hidden

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

85 files changed

+62
-21
lines changed

core/src/components/datetime/test/presentation/datetime.e2e.ts

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
import type { Locator } from '@playwright/test';
22
import { expect } from '@playwright/test';
3-
import type { E2EPage, E2EPageOptions } from '@utils/test/playwright';
3+
import type { E2EPage, E2EPageOptions, ScreenshotFn } from '@utils/test/playwright';
44
import { configs, test } from '@utils/test/playwright';
55

66
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+
});
917

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+
});
1122

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+
});
1327

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+
});
1632

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+
});
3147
});
3248
});
3349

@@ -157,6 +173,31 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
157173
});
158174
});
159175

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+
160201
class TimePickerFixture {
161202
readonly page: E2EPage;
162203

0 commit comments

Comments
 (0)