Skip to content

Commit

Permalink
test(datetime): un-flake presentation test (#28090)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
liamdebeasi and Ionitron authored Aug 31, 2023
1 parent 2a80eb6 commit e1fdbb3
Show file tree
Hide file tree
Showing 85 changed files with 62 additions and 21 deletions.
83 changes: 62 additions & 21 deletions core/src/components/datetime/test/presentation/datetime.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
import type { Locator } from '@playwright/test';
import { expect } from '@playwright/test';
import type { E2EPage, E2EPageOptions } from '@utils/test/playwright';
import type { E2EPage, E2EPageOptions, ScreenshotFn } from '@utils/test/playwright';
import { configs, test } from '@utils/test/playwright';

configs().forEach(({ title, screenshot, config }) => {
test(title('should not have visual regressions'), async ({ page }) => {
await page.goto(`/src/components/datetime/test/presentation`, config);
test.describe(title('datetime: presentation rendering'), () => {
let presentationFixture!: DatetimePresentationFixture;
test.beforeEach(({ page }) => {
presentationFixture = new DatetimePresentationFixture(page);
});

test('should not have visual regressions with date-time presentation', async () => {
await presentationFixture.goto('date-time', config);
await presentationFixture.screenshot('datetime-presentation-date-time-diff', screenshot);
});

await page.waitForSelector('.datetime-ready');
test('should not have visual regressions with time-date presentation', async () => {
await presentationFixture.goto('time-date', config);
await presentationFixture.screenshot('datetime-presentation-time-date-diff', screenshot);
});

const datetime = page.locator('ion-datetime');
test('should not have visual regressions with time presentation', async () => {
await presentationFixture.goto('time', config);
await presentationFixture.screenshot('datetime-presentation-time-diff', screenshot);
});

const compares = [];
const presentations = ['date-time', 'time-date', 'time', 'date', 'month-year', 'month', 'year'];
test('should not have visual regressions with date presentation', async () => {
await presentationFixture.goto('date', config);
await presentationFixture.screenshot('datetime-presentation-date-diff', screenshot);
});

for (const presentation of presentations) {
await page.locator('select').selectOption(presentation);
await page.waitForChanges();
compares.push({
presentation,
screenshot: datetime,
});
}

for (const compare of compares) {
await expect(compare.screenshot).toHaveScreenshot(
screenshot(`datetime-presentation-${compare.presentation}-diff`)
);
}
test('should not have visual regressions with month-year presentation', async () => {
await presentationFixture.goto('month-year', config);
await presentationFixture.screenshot('datetime-presentation-month-year-diff', screenshot);
});

test('should not have visual regressions with month presentation', async () => {
await presentationFixture.goto('month', config);
await presentationFixture.screenshot('datetime-presentation-month-diff', screenshot);
});

test('should not have visual regressions with year presentation', async () => {
await presentationFixture.goto('year', config);
await presentationFixture.screenshot('datetime-presentation-year-diff', screenshot);
});
});
});

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

class DatetimePresentationFixture {
readonly page: E2EPage;

private datetime!: Locator;

constructor(page: E2EPage) {
this.page = page;
}

async goto(presentation: string, config: E2EPageOptions) {
await this.page.setContent(
`
<ion-datetime presentation="${presentation}" value="2010-03-10T13:00:00"></ion-datetime>
`,
config
);
await this.page.waitForSelector('.datetime-ready');
this.datetime = this.page.locator('ion-datetime');
}

async screenshot(name: string, screenshotFn: ScreenshotFn) {
await expect(this.datetime).toHaveScreenshot(screenshotFn(name));
}
}

class TimePickerFixture {
readonly page: E2EPage;

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e1fdbb3

Please sign in to comment.