Skip to content

Commit

Permalink
test(picker, picker-column): migrate to generators (#27352)
Browse files Browse the repository at this point in the history
Issue number: N/A

---------

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

Picker and picker column tests use legacy syntax

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

- Picker and picker column tests use generator syntax

## 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. -->
  • Loading branch information
liamdebeasi committed May 2, 2023
1 parent 19c53c4 commit df3aaff
Show file tree
Hide file tree
Showing 57 changed files with 134 additions and 117 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { configs, test } from '@utils/test/playwright';

import { testPickerColumn } from '../test.utils';

configs().forEach(({ title, screenshot, config }) => {
test.describe(title('picker-column'), () => {
test.beforeEach(async ({ page }) => {
await page.goto('/src/components/picker-column/test/standalone', config);
});
test.describe('single column', () => {
test('should not have any visual regressions', async ({ page }) => {
await testPickerColumn(page, screenshot, '#single-column-button', 'single');
});
});

test.describe('multiple columns', () => {
test('should not have any visual regressions', async ({ page }) => {
await testPickerColumn(page, screenshot, '#multiple-column-button', 'multiple');
});
});
});
});
12 changes: 9 additions & 3 deletions core/src/components/picker-column/test/test.utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { expect } from '@playwright/test';
import type { E2EPage } from '@utils/test/playwright';
import type { E2EPage, ScreenshotFn } from '@utils/test/playwright';

/**
* Visual regression tests for picker-column.
* @param page - The page to run the tests on.
* @param screenshot - The screenshot function to generate unique screenshot names
* @param buttonSelector - The selector for the button that opens the picker.
* @param description - The description to amend to the screenshot names (typically 'single' or 'multiple').
*/
export async function testPickerColumn(page: E2EPage, buttonSelector: string, description: string) {
export async function testPickerColumn(
page: E2EPage,
screenshot: ScreenshotFn,
buttonSelector: string,
description: string
) {
const ionPickerDidPresentSpy = await page.spyOnEvent('ionPickerDidPresent');

await page.click(buttonSelector);
await ionPickerDidPresentSpy.next();

await page.waitForChanges();

await expect(page).toHaveScreenshot(`picker-${description}-column-initial-${page.getSnapshotSettings()}.png`);
await expect(page).toHaveScreenshot(screenshot(`picker-${description}-column-initial`));

// TODO FW-3403
/*
Expand Down
26 changes: 0 additions & 26 deletions core/src/components/picker/test/basic/picker.e2e-legacy.ts

This file was deleted.

28 changes: 28 additions & 0 deletions core/src/components/picker/test/basic/picker.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

configs().forEach(({ title, screenshot, config }) => {
test.describe(title('picker: basic'), () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto('/src/components/picker/test/basic', config);
const didPresent = await page.spyOnEvent('ionPickerDidPresent');
const didDismiss = await page.spyOnEvent('ionPickerDidDismiss');

await page.click('#basic');
await didPresent.next();
await page.waitForChanges();

await expect(page).toHaveScreenshot(screenshot(`picker-basic`));

await page.click('.picker-opt:nth-child(2)');
await page.click('ion-picker .save-btn');
await didDismiss.next();

await page.click('#basic');
await didPresent.next();
await page.waitForChanges();

await expect(page).toHaveScreenshot(screenshot(`picker-value-selected`));
});
});
});
34 changes: 0 additions & 34 deletions core/src/components/picker/test/is-open/picker.e2e-legacy.ts

This file was deleted.

37 changes: 37 additions & 0 deletions core/src/components/picker/test/is-open/picker.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

/**
* This behavior does not vary across modes/directions.
*/
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('picker: isOpen'), () => {
test.beforeEach(async ({ page }) => {
await page.goto('/src/components/picker/test/is-open', config);
});

test('should open the picker', async ({ page }) => {
const ionPickerDidPresent = await page.spyOnEvent('ionPickerDidPresent');
const picker = page.locator('ion-picker');

await page.click('#default');

await ionPickerDidPresent.next();
await expect(picker).toBeVisible();
});

test('should open the picker then close after a timeout', async ({ page }) => {
const ionPickerDidPresent = await page.spyOnEvent('ionPickerDidPresent');
const ionPickerDidDismiss = await page.spyOnEvent('ionPickerDidDismiss');
const picker = page.locator('ion-picker');

await page.click('#timeout');

await ionPickerDidPresent.next();
await expect(picker).toBeVisible();

await ionPickerDidDismiss.next();
await expect(picker).toBeHidden();
});
});
});
35 changes: 0 additions & 35 deletions core/src/components/picker/test/trigger/picker.e2e-legacy.ts

This file was deleted.

38 changes: 38 additions & 0 deletions core/src/components/picker/test/trigger/picker.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';

/**
* This behavior does not vary across modes/directions.
*/
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('picker: trigger'), () => {
test.beforeEach(async ({ page }) => {
await page.goto('/src/components/picker/test/trigger', config);
});

test('should open the picker', async ({ page }) => {
const ionPickerDidPresent = await page.spyOnEvent('ionPickerDidPresent');
const picker = page.locator('#default-picker');

await page.click('#default');

await ionPickerDidPresent.next();
await expect(picker).toBeVisible();
});

test('should present a previously presented picker', async ({ page }) => {
const ionPickerDidPresent = await page.spyOnEvent('ionPickerDidPresent');
const ionPickerDidDismiss = await page.spyOnEvent('ionPickerDidDismiss');
const picker = page.locator('#timeout-picker');

await page.click('#timeout');

await ionPickerDidDismiss.next();

await page.click('#timeout');

await ionPickerDidPresent.next();
await expect(picker).toBeVisible();
});
});
});

0 comments on commit df3aaff

Please sign in to comment.