test(checkbox): migrate to generators (#27300)

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

Checkbox tests use legacy syntax

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

- Checkbox 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. -->
This commit is contained in:
Liam DeBeasi
2023-04-27 17:41:47 -04:00
committed by GitHub
parent a6bf51fe2f
commit 43a61b0e46
282 changed files with 458 additions and 395 deletions

View File

@ -1,17 +0,0 @@
import AxeBuilder from '@axe-core/playwright';
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('checkbox: a11y', () => {
test.beforeEach(async ({ skip }) => {
skip.rtl();
skip.mode('md');
});
test('should not have accessibility violations', async ({ page }) => {
await page.goto(`/src/components/checkbox/test/a11y`);
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
});
});

View File

@ -0,0 +1,14 @@
import AxeBuilder from '@axe-core/playwright';
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('checkbox: a11y'), () => {
test('should not have accessibility violations', async ({ page }) => {
await page.goto(`/src/components/checkbox/test/a11y`, config);
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
});
});
});

View File

@ -1,100 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('checkbox: basic visual tests', () => {
test('should render unchecked checkbox correctly', async ({ page }) => {
await page.setContent(`
<ion-checkbox>Unchecked</ion-checkbox>
`);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(`checkbox-unchecked-${page.getSnapshotSettings()}.png`);
});
test('should render checked checkbox correctly', async ({ page }) => {
await page.setContent(`
<ion-checkbox checked>Checked</ion-checkbox>
`);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(`checkbox-checked-${page.getSnapshotSettings()}.png`);
});
test('should render disabled checkbox correctly', async ({ page }) => {
await page.setContent(`
<ion-checkbox checked disabled>Disabled</ion-checkbox>
`);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(`checkbox-disabled-${page.getSnapshotSettings()}.png`);
});
test('should render custom checkmark-width correctly', async ({ page }) => {
await page.setContent(`
<ion-checkbox checked style="--checkmark-width: 7">Checkmark Width</ion-checkbox>
`);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(`checkbox-checkmark-width-${page.getSnapshotSettings()}.png`);
});
test('should render custom size correctly', async ({ page }) => {
await page.setContent(`
<ion-checkbox checked style="--size: 100px">Size</ion-checkbox>
`);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(`checkbox-size-${page.getSnapshotSettings()}.png`);
});
});
test.describe('checkbox: ionChange', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
skip.mode('ios');
});
test('should fire ionChange when interacting with checkbox', async ({ page }) => {
await page.setContent(`
<ion-checkbox aria-label="checkbox" value="my-checkbox"></ion-checkbox>
`);
const ionChange = await page.spyOnEvent('ionChange');
const checkbox = page.locator('ion-checkbox');
await checkbox.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: true });
await checkbox.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: false });
});
test('should fire ionChange when interacting with checkbox in item', async ({ page }) => {
await page.setContent(`
<ion-item>
<ion-checkbox aria-label="checkbox" value="my-checkbox"></ion-checkbox>
</ion-item>
`);
const ionChange = await page.spyOnEvent('ionChange');
const item = page.locator('ion-item');
await item.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: true });
await item.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: false });
});
test('should not fire when programmatically setting a value', async ({ page }) => {
await page.setContent(`
<ion-checkbox aria-label="checkbox" value="my-checkbox"></ion-checkbox>
`);
const ionChange = await page.spyOnEvent('ionChange');
const checkbox = page.locator('ion-checkbox');
await checkbox.evaluate((el: HTMLIonCheckboxElement) => (el.checked = true));
expect(ionChange).not.toHaveReceivedEvent();
});
});

View File

@ -0,0 +1,123 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs().forEach(({ title, screenshot, config }) => {
test.describe(title('checkbox: basic visual tests'), () => {
test('should render unchecked checkbox correctly', async ({ page }) => {
await page.setContent(
`
<ion-checkbox>Unchecked</ion-checkbox>
`,
config
);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-unchecked`));
});
test('should render checked checkbox correctly', async ({ page }) => {
await page.setContent(
`
<ion-checkbox checked>Checked</ion-checkbox>
`,
config
);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-checked`));
});
test('should render disabled checkbox correctly', async ({ page }) => {
await page.setContent(
`
<ion-checkbox checked disabled>Disabled</ion-checkbox>
`,
config
);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-disabled`));
});
test('should render custom checkmark-width correctly', async ({ page }) => {
await page.setContent(
`
<ion-checkbox checked style="--checkmark-width: 7">Checkmark Width</ion-checkbox>
`,
config
);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-checkmark-width`));
});
test('should render custom size correctly', async ({ page }) => {
await page.setContent(
`
<ion-checkbox checked style="--size: 100px">Size</ion-checkbox>
`,
config
);
const checkbox = page.locator('ion-checkbox');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-size`));
});
});
});
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('checkbox: ionChange'), () => {
test('should fire ionChange when interacting with checkbox', async ({ page }) => {
await page.setContent(
`
<ion-checkbox aria-label="checkbox" value="my-checkbox"></ion-checkbox>
`,
config
);
const ionChange = await page.spyOnEvent('ionChange');
const checkbox = page.locator('ion-checkbox');
await checkbox.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: true });
await checkbox.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: false });
});
test('should fire ionChange when interacting with checkbox in item', async ({ page }) => {
await page.setContent(
`
<ion-item>
<ion-checkbox aria-label="checkbox" value="my-checkbox"></ion-checkbox>
</ion-item>
`,
config
);
const ionChange = await page.spyOnEvent('ionChange');
const item = page.locator('ion-item');
await item.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: true });
await item.click();
expect(ionChange).toHaveReceivedEventDetail({ value: 'my-checkbox', checked: false });
});
test('should not fire when programmatically setting a value', async ({ page }) => {
await page.setContent(
`
<ion-checkbox aria-label="checkbox" value="my-checkbox"></ion-checkbox>
`,
config
);
const ionChange = await page.spyOnEvent('ionChange');
const checkbox = page.locator('ion-checkbox');
await checkbox.evaluate((el: HTMLIonCheckboxElement) => (el.checked = true));
expect(ionChange).not.toHaveReceivedEvent();
});
});
});

View File

@ -1,26 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('checkbox: color', () => {
test.beforeEach(({ skip }) => {
skip.rtl();
});
test('should apply color when checked', async ({ page }) => {
await page.setContent(`
<ion-checkbox color="danger" checked="true">Label</ion-checkbox>
`);
const checkbox = page.locator('ion-checkbox');
expect(await checkbox.screenshot()).toMatchSnapshot(`checkbox-color-checked-${page.getSnapshotSettings()}.png`);
});
test('should not apply color when unchecked', async ({ page }) => {
await page.setContent(`
<ion-checkbox color="danger">Label</ion-checkbox>
`);
const checkbox = page.locator('ion-checkbox');
expect(await checkbox.screenshot()).toMatchSnapshot(`checkbox-color-unchecked-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -0,0 +1,30 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('checkbox: color'), () => {
test('should apply color when checked', async ({ page }) => {
await page.setContent(
`
<ion-checkbox color="danger" checked="true">Label</ion-checkbox>
`,
config
);
const checkbox = page.locator('ion-checkbox');
expect(await checkbox.screenshot()).toMatchSnapshot(screenshot(`checkbox-color-checked`));
});
test('should not apply color when unchecked', async ({ page }) => {
await page.setContent(
`
<ion-checkbox color="danger">Label</ion-checkbox>
`,
config
);
const checkbox = page.locator('ion-checkbox');
expect(await checkbox.screenshot()).toMatchSnapshot(screenshot(`checkbox-color-unchecked`));
});
});
});

View File

@ -1,13 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('checkbox: indeterminate', () => {
test('should not have visual regressions', async ({ page, skip }) => {
skip.rtl();
await page.goto(`/src/components/checkbox/test/indeterminate`);
const checkbox = page.locator('ion-checkbox:first-child');
await expect(checkbox).toHaveScreenshot(`checkbox-indeterminate-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -0,0 +1,13 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('checkbox: indeterminate'), () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/checkbox/test/indeterminate`, config);
const checkbox = page.locator('ion-checkbox:first-child');
await expect(checkbox).toHaveScreenshot(screenshot(`checkbox-indeterminate`));
});
});
});

View File

@ -1,37 +0,0 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('checkbox: item', () => {
test('should render correctly in list', async ({ page }) => {
await page.setContent(`
<ion-list>
<ion-item>
<ion-checkbox>Enable Notifications</ion-checkbox>
</ion-item>
</ion-list>
`);
const list = page.locator('ion-list');
expect(await list.screenshot()).toMatchSnapshot(`checkbox-list-${page.getSnapshotSettings()}.png`);
});
test('should render correctly in inset list', async ({ page }) => {
await page.setContent(`
<ion-list inset="true">
<ion-item>
<ion-checkbox>Enable Notifications</ion-checkbox>
</ion-item>
</ion-list>
`);
const list = page.locator('ion-list');
expect(await list.screenshot()).toMatchSnapshot(`checkbox-inset-list-${page.getSnapshotSettings()}.png`);
});
test('label should have correct contrast when used in an item', async ({ page, skip }) => {
skip.rtl();
await page.setContent(`
<ion-item color="primary">
<ion-checkbox>Enable Notifications</ion-checkbox>
</ion-item>
`);
const item = page.locator('ion-item');
expect(await item.screenshot()).toMatchSnapshot(`checkbox-item-color-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -0,0 +1,52 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs().forEach(({ title, screenshot, config }) => {
test.describe(title('checkbox: item with list'), () => {
test('should render correctly in list', async ({ page }) => {
await page.setContent(
`
<ion-list>
<ion-item>
<ion-checkbox>Enable Notifications</ion-checkbox>
</ion-item>
</ion-list>
`,
config
);
const list = page.locator('ion-list');
expect(await list.screenshot()).toMatchSnapshot(screenshot(`checkbox-list`));
});
test('should render correctly in inset list', async ({ page }) => {
await page.setContent(
`
<ion-list inset="true">
<ion-item>
<ion-checkbox>Enable Notifications</ion-checkbox>
</ion-item>
</ion-list>
`,
config
);
const list = page.locator('ion-list');
expect(await list.screenshot()).toMatchSnapshot(screenshot(`checkbox-inset-list`));
});
});
});
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('checkbox: label in item'), () => {
test('label should have correct contrast when used in an item', async ({ page }) => {
await page.setContent(
`
<ion-item color="primary">
<ion-checkbox>Enable Notifications</ion-checkbox>
</ion-item>
`,
config
);
const item = page.locator('ion-item');
expect(await item.screenshot()).toMatchSnapshot(screenshot(`checkbox-item-color`));
});
});
});

Some files were not shown because too many files have changed in this diff Show More