test(many): use web-first assertions (#27113)

<!-- Please refer to our contributing documentation for any questions on
submitting a pull request, or let us know here if you need any help:
https://ionicframework.com/docs/building/contributing -->

<!-- Some docs updates need to be made in the `ionic-docs` repo, in a
separate PR. See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation
for details. -->

<!-- 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. -->


<!-- Issues are required for both bug fixes and features. -->
Issue URL: N/A

Playwright recommends using Locators with web-first assertions instead
of using `waitForSelector`:
https://playwright.dev/docs/api/class-frame#frame-wait-for-selector


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

- Removes waitForSelector usages for checking if components are visible
in favor of the `toBeVisible` or `toBeHidden` assertions.

## 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. -->
This commit is contained in:
Liam DeBeasi
2023-04-05 08:47:18 -04:00
committed by GitHub
parent d925237082
commit 8c8908c49d
13 changed files with 80 additions and 35 deletions

View File

@ -1,3 +1,4 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('loading: isOpen', () => {
@ -9,22 +10,25 @@ test.describe('loading: isOpen', () => {
test('should open the loading indicator', async ({ page }) => {
const ionLoadingDidPresent = await page.spyOnEvent('ionLoadingDidPresent');
const loading = page.locator('ion-loading');
await page.click('#default');
await ionLoadingDidPresent.next();
await page.waitForSelector('ion-loading', { state: 'visible' });
await expect(loading).toBeVisible();
});
test('should open the loading indicator then close after a timeout', async ({ page }) => {
const ionLoadingDidPresent = await page.spyOnEvent('ionLoadingDidPresent');
const ionLoadingDidDismiss = await page.spyOnEvent('ionLoadingDidDismiss');
const loading = page.locator('ion-loading');
await page.click('#timeout');
await ionLoadingDidPresent.next();
await page.waitForSelector('ion-loading', { state: 'visible' });
await expect(loading).toBeVisible();
await ionLoadingDidDismiss.next();
await page.waitForSelector('ion-loading', { state: 'hidden' });
await expect(loading).toBeHidden();
});
});

View File

@ -1,3 +1,4 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('loading: trigger', () => {
@ -9,15 +10,17 @@ test.describe('loading: trigger', () => {
test('should open the loading indicator', async ({ page }) => {
const ionLoadingDidPresent = await page.spyOnEvent('ionLoadingDidPresent');
const loading = page.locator('#default-loading');
await page.click('#default');
await ionLoadingDidPresent.next();
await page.waitForSelector('#default-loading', { state: 'visible' });
await expect(loading).toBeVisible();
});
test('should present a previously presented loading indicator', async ({ page }) => {
const ionLoadingDidPresent = await page.spyOnEvent('ionLoadingDidPresent');
const ionLoadingDidDismiss = await page.spyOnEvent('ionLoadingDidDismiss');
const loading = page.locator('#timeout-loading');
await page.click('#timeout');
@ -26,6 +29,6 @@ test.describe('loading: trigger', () => {
await page.click('#timeout');
await ionLoadingDidPresent.next();
await page.waitForSelector('#timeout-loading', { state: 'visible' });
await expect(loading).toBeVisible();
});
});