Skip to content

Commit

Permalink
test(many): replace waitForSelector with waitFor (#28888)
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 some tests that use Playwright's `waitForSelector`
[function](https://playwright.dev/docs/api/class-page#page-wait-for-selector).
However, Playwright has informed the community to not use this function
by labeling it as
[discouraged](https://playwright.dev/docs/api/class-page#page-wait-for-selector).

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Replaced `waitForSelector` with the
[recommended](https://playwright.dev/docs/api/class-page#page-wait-for-selector)
`waitFor`
[function](https://playwright.dev/docs/api/class-locator#locator-wait-for).

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

N/A
  • Loading branch information
thetaPC authored Jan 26, 2024
1 parent ddd8b92 commit 2a3c26e
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 126 deletions.
2 changes: 1 addition & 1 deletion core/src/components/button/test/basic/button.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ configs({ modes: ['md'] }).forEach(({ config, screenshot, title }) => {
await page.mouse.down();
}

await page.waitForSelector('#default.ion-activated');
await page.locator('#default.ion-activated').waitFor();

await expect(button).toHaveScreenshot(screenshot(`button-ripple-effect`));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();
});
test('should switch to a date-only view when the date button is clicked', async ({ page }) => {
const datetime = page.locator('ion-datetime');
Expand Down Expand Up @@ -45,7 +45,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('Jan 1, 2022');
await expect(page.locator('#time-button')).toContainText('6:30 AM');
Expand All @@ -58,7 +58,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('January 2022');
await expect(page.locator('#time-button')).toBeHidden();
Expand All @@ -71,7 +71,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('2022');
await expect(page.locator('#time-button')).toBeHidden();
Expand All @@ -84,7 +84,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('January');
await expect(page.locator('#time-button')).toBeHidden();
Expand All @@ -97,7 +97,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#time-button')).toContainText('6:30 AM');
await expect(page.locator('#date-button')).toBeHidden();
Expand All @@ -110,7 +110,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const datetime = page.locator('ion-datetime');
const dateTarget = page.locator('#date-button');
Expand All @@ -135,7 +135,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('January 2022');
await expect(page.locator('#time-button')).toBeHidden();
Expand All @@ -153,7 +153,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('2022');
await expect(page.locator('#time-button')).toBeHidden();
Expand All @@ -169,7 +169,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

/**
* The entire text reads 1 ene 2022, but some browsers will add
Expand All @@ -187,7 +187,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#time-button')).toContainText('16:30');
});
Expand All @@ -199,7 +199,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const timeTarget = page.locator('#time-button');
await expect(timeTarget).toContainText('6:30');
Expand All @@ -223,7 +223,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('Jan 1, 2022 6:30 AM');
await expect(page.locator('#time-button')).not.toBeVisible();
Expand All @@ -238,7 +238,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('Jan 1, 2022 6:30 AM');
await expect(page.locator('#time-button')).not.toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toBeDisabled();
await expect(page.locator('#time-button')).toBeDisabled();
Expand All @@ -24,7 +24,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const datetimeButton = page.locator('ion-datetime-button');
await expect(datetimeButton).toHaveScreenshot(screenshot(`datetime-button-disabled`));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toContainText('3 days');
});
Expand All @@ -32,7 +32,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toHaveText('0 days');
});
Expand All @@ -49,7 +49,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toHaveText('Jun 1, 2022');
});
Expand All @@ -69,7 +69,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toHaveText('Selected: 3');
});
Expand All @@ -86,7 +86,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const datetime = page.locator('ion-datetime');
const ionValueChange = await page.spyOnEvent('ionValueChange');
Expand All @@ -111,7 +111,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
`,
config
);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(page.locator('#date-button')).toHaveText('Jun 1, 2022');
await expect(page.locator('#time-button')).toHaveText('4:30 PM');
Expand Down
6 changes: 3 additions & 3 deletions core/src/components/datetime/test/a11y/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {

const container = page.locator('#container');

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(container).toHaveScreenshot(screenshot(`datetime-scale`));
});
Expand Down Expand Up @@ -87,7 +87,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const clearButton = page.locator('#clear-button button');
const selectedDay = page.locator('.calendar-day-active');
Expand All @@ -114,7 +114,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();
const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');
const calendarBody = page.locator('.calendar-body');
await expect(calendarMonthYear).toHaveText('February 2022');
Expand Down
24 changes: 12 additions & 12 deletions core/src/components/datetime/test/basic/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();
const datetime = page.locator('ion-datetime');
const ionChange = await page.spyOnEvent('ionChange');

Expand Down Expand Up @@ -255,7 +255,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const calendarBody = page.locator('ion-datetime .calendar-body');
const calendarHeader = page.locator('ion-datetime .calendar-month-year');
Expand All @@ -275,7 +275,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const calendarBody = page.locator('ion-datetime .calendar-body');
const calendarHeader = page.locator('ion-datetime .calendar-month-year');
Expand All @@ -297,7 +297,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const calendarBody = page.locator('ion-datetime .calendar-body');
const calendarHeader = page.locator('ion-datetime .calendar-month-year');
Expand Down Expand Up @@ -331,7 +331,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const monthYearButton = page.locator('ion-datetime .calendar-month-year');
const monthYearInterface = page.locator('ion-datetime .datetime-year');
Expand All @@ -349,7 +349,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
await datetime.evaluate((el: HTMLIonDatetimeElement) => el.style.removeProperty('display'));
await expect(datetime).toBeVisible();

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

// month/year interface should be reset
await expect(monthYearInterface).toBeHidden();
Expand Down Expand Up @@ -399,7 +399,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const selectedDay = page.locator('ion-datetime .calendar-day-active');

Expand Down Expand Up @@ -428,7 +428,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const ionChange = await page.spyOnEvent('ionChange');
const calendarButtons = page.locator('.calendar-day:not([disabled])');
Expand All @@ -447,7 +447,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const ionChange = await page.spyOnEvent('ionChange');
const datetime = page.locator('ion-datetime');
Expand Down Expand Up @@ -487,7 +487,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {

const datetime = page.locator('ion-datetime');

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(datetime.locator('.calendar-day-today')).toHaveScreenshot(
screenshot(`datetime-today-calendar-button`)
Expand Down Expand Up @@ -517,7 +517,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, co

const datetime = page.locator('ion-datetime');

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

await expect(datetime).toHaveScreenshot(screenshot(`date-highlight-start-of-month`));

Expand All @@ -543,7 +543,7 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const datetime = page.locator('ion-datetime');

Expand Down
2 changes: 1 addition & 1 deletion core/src/components/datetime/test/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();
});

test('should switch the calendar header when moving to a month with a different number of days', async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ configs({ directions: ['ltr'], modes: ['ios'] }).forEach(({ title, config }) =>
test.describe('check example usages', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/src/components/datetime/test/disable-dates', config);
await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').first().waitFor();
});

test('should disable a specific date', async ({ page }) => {
Expand Down
8 changes: 4 additions & 4 deletions core/src/components/datetime/test/disabled/datetime.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config, scree
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const febFirstButton = page.locator(`.calendar-day[data-day='1'][data-month='2']`);

Expand All @@ -42,7 +42,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config, scree
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();
const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');
await expect(calendarMonthYear.locator('button')).toBeDisabled();
});
Expand Down Expand Up @@ -71,7 +71,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config, scree
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();

const clearButton = page.locator('#clear-button button');

Expand All @@ -86,7 +86,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config, scree
config
);

await page.waitForSelector('.datetime-ready');
await page.locator('.datetime-ready').waitFor();
const calendarMonthYear = page.locator('ion-datetime .calendar-month-year');
const calendarBody = page.locator('.calendar-body');
await expect(calendarMonthYear).toHaveText('February 2022');
Expand Down
Loading

0 comments on commit 2a3c26e

Please sign in to comment.