test(item): migrate tests to playwright (#25479)

This commit is contained in:
Sean Perkins
2022-06-29 13:28:49 -04:00
committed by GitHub
parent b62dded144
commit 7ac215b2c8
334 changed files with 420 additions and 474 deletions

View File

@ -1,14 +0,0 @@
import { AxePuppeteer } from '@axe-core/puppeteer';
import { newE2EPage } from '@stencil/core/testing';
test('item: axe', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/a11y?ionic:_testing=true',
});
const results = await new AxePuppeteer(page)
// TODO(FW-404): Re-enable rule once select is updated to avoid nested-interactive
.disableRules('nested-interactive')
.analyze();
expect(results.violations.length).toEqual(0);
});

View File

@ -0,0 +1,15 @@
import AxeBuilder from '@axe-core/playwright';
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: axe', () => {
test('should not have accessibility violations', async ({ page }) => {
await page.goto(`/src/components/item/test/a11y`);
const results = await new AxeBuilder({ page })
// TODO(FW-404): Re-enable rule once select is updated to avoid nested-interactive
.disableRules('nested-interactive')
.analyze();
expect(results.violations).toEqual([]);
});
});

View File

@ -1,19 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('item: alignment', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/alignment?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});
test('item: alignment-rtl', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/alignment?ionic:_testing=true&rtl=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -25,10 +25,6 @@
<ion-content>
<ion-list>
<ion-list-header>Leading Icons</ion-list-header>
<ion-item>
<ion-icon slot="start" name="time"></ion-icon>
<ion-datetime display-format="DDDD MMMM D YYYY hh:mm:ss a" value="2019-10-01T15:43:40.394Z"></ion-datetime>
</ion-item>
<ion-item>
<ion-icon slot="start" name="radio-button-off"></ion-icon>
<ion-input placeholder="Choose Starting Point"></ion-input>
@ -44,10 +40,6 @@
<ion-list>
<ion-list-header>Default Labels</ion-list-header>
<ion-item>
<ion-label>Time</ion-label>
<ion-datetime display-format="DDDD MMMM D YYYY hh:mm:ss a" value="2019-10-01T15:43:40.394Z"></ion-datetime>
</ion-item>
<ion-item>
<ion-label>From</ion-label>
<ion-input placeholder="Choose Starting Point"></ion-input>
@ -63,10 +55,6 @@
<ion-list>
<ion-list-header>Fixed Labels</ion-list-header>
<ion-item>
<ion-label position="fixed">Time</ion-label>
<ion-datetime display-format="DDDD MMMM D YYYY hh:mm:ss a" value="2019-10-01T15:43:40.394Z"></ion-datetime>
</ion-item>
<ion-item>
<ion-label position="fixed">From</ion-label>
<ion-input placeholder="Choose Starting Point"></ion-input>
@ -82,10 +70,6 @@
<ion-list>
<ion-list-header>Floating Labels</ion-list-header>
<ion-item>
<ion-label position="floating">Time</ion-label>
<ion-datetime display-format="DDDD MMMM D YYYY hh:mm:ss a"></ion-datetime>
</ion-item>
<ion-item>
<ion-label position="floating">From</ion-label>
<ion-input></ion-input>
@ -101,10 +85,6 @@
<ion-list>
<ion-list-header>Stacked Labels</ion-list-header>
<ion-item>
<ion-label position="stacked">Time</ion-label>
<ion-datetime display-format="DDDD MMMM D YYYY hh:mm:ss a" value="2019-10-01T15:43:40.394Z"></ion-datetime>
</ion-item>
<ion-item>
<ion-label position="stacked">From</ion-label>
<ion-input placeholder="Choose Starting Point"></ion-input>
@ -120,10 +100,6 @@
<ion-list>
<ion-list-header>End Labels</ion-list-header>
<ion-item>
<ion-label slot="end">Time</ion-label>
<ion-datetime display-format="DDDD MMMM D YYYY hh:mm:ss a" value="2019-10-01T15:43:40.394Z"></ion-datetime>
</ion-item>
<ion-item>
<ion-label slot="end">From</ion-label>
<ion-input placeholder="Choose Starting Point"></ion-input>

View File

@ -0,0 +1,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: alignment', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/item/test/alignment`);
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-alignment-diff-${page.getSnapshotSettings()}.png`);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

View File

@ -1,19 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('item: basic', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/basic?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});
test('item: basic-rtl', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/basic?ionic:_testing=true&rtl=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -0,0 +1,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: basic', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/item/test/basic`);
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-diff-${page.getSnapshotSettings()}.png`);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

View File

@ -1,10 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('item: buttons', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/buttons?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -0,0 +1,18 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: buttons', () => {
test('should not have visual regressions', async ({ page }) => {
/**
* This test validates that in iOS mode the arrow indicators are
* added to the end of the ion-item row.
*
* In MD mode, these arrow indicators are not present.
*/
await page.goto(`/src/components/item/test/buttons`);
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-buttons-diff-${page.getSnapshotSettings()}.png`);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

View File

@ -1,10 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('item: colors', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/colors?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -0,0 +1,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: colors', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/item/test/colors`);
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-colors-diff-${page.getSnapshotSettings()}.png`);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

View File

@ -1,96 +0,0 @@
import type { E2EPage } from '@stencil/core/testing';
import { newE2EPage } from '@stencil/core/testing';
describe('item: counter', () => {
describe('custom formatter', () => {
let page: E2EPage;
beforeEach(async () => {
page = await newE2EPage({
url: '/src/components/item/test/counter?ionic:_testing=true',
});
});
it('should format on load', async () => {
const itemCounter = await page.find('#customFormatter >>> .item-counter');
expect(itemCounter.textContent).toBe('20 characters left');
});
it('should format on input', async () => {
const input = await page.find('#customFormatter ion-input');
await input.click();
await input.type('abcde');
await page.waitForChanges();
const itemCounter = await page.find('#customFormatter >>> .item-counter');
expect(itemCounter.textContent).toBe('15 characters left');
});
it('should format after changing the counterFormatter', async () => {
let itemCounter = await page.find('#customFormatter >>> .item-counter');
expect(itemCounter.textContent).toBe('20 characters left');
await page.$eval('#customFormatter', (el: any) => {
el.counterFormatter = () => {
return 'test label';
};
});
await page.waitForChanges();
itemCounter = await page.find('#customFormatter >>> .item-counter');
expect(itemCounter.textContent).toBe('test label');
});
describe('when an exception occurs', () => {
const logs = [];
beforeEach(async () => {
page = await newE2EPage({
html: `
<ion-item counter="true"">
<ion-input maxlength="20" value=""></ion-input>
</ion-item>`,
});
page.on('console', (ev) => {
if (ev.type() === 'error') {
logs.push(ev.text());
}
});
const itemCounter = await page.find('ion-item >>> .item-counter');
expect(itemCounter.textContent).toBe('0 / 20');
await page.$eval('ion-item', (el: any) => {
el.counterFormatter = () => {
throw new Error('This is an expected error');
};
});
await page.waitForChanges();
});
it('should default the formatting to length / maxlength', async () => {
const input = await page.find('ion-input');
await input.click();
await input.type('abcde');
const itemCounter = await page.find('ion-item >>> .item-counter');
expect(itemCounter.textContent).toBe('5 / 20');
});
it('should log an error', () => {
expect(logs.length).toBeGreaterThan(0);
expect(logs[0]).toMatch('[Ionic Error]: Exception in provided `counterFormatter`.');
});
});
});
});

View File

@ -3,10 +3,50 @@ import { test } from '@utils/test/playwright';
test.describe('item: counter', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/item/test/counter`);
await page.goto('/src/components/item/test/counter');
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-counter-diff-${page.getSnapshotSettings()}.png`);
});
test.describe('custom formatter', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/src/components/item/test/counter');
});
test('should format on load', async ({ page }) => {
const itemCounter = page.locator('#customFormatter .item-counter');
expect(await itemCounter.textContent()).toBe('20 characters left');
});
test('should format on input', async ({ page }) => {
const input = page.locator('#customFormatter ion-input');
await input.click();
await input.type('abcde');
await page.waitForChanges();
const itemCounter = page.locator('#customFormatter .item-counter');
expect(await itemCounter.textContent()).toBe('15 characters left');
});
test('should format after changing the counterFormatter', async ({ page }) => {
const itemCounter = page.locator('#customFormatter .item-counter');
expect(await itemCounter.textContent()).toBe('20 characters left');
await page.$eval('#customFormatter', (el: any) => {
el.counterFormatter = () => {
return 'test label';
};
});
await page.waitForChanges();
expect(await itemCounter.textContent()).toBe('test label');
});
});
});

View File

@ -1,10 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('item: CSS variables', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/css-variables?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -0,0 +1,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: CSS variables', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/item/test/css-variables`);
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-css-vars-diff-${page.getSnapshotSettings()}.png`);
});
});

View File

@ -1,19 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('item: disabled', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/disabled?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});
test('item: disabled-rtl', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/disabled?ionic:_testing=true&rtl=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -0,0 +1,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: disabled state', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/item/test/disabled`);
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-disabled-diff-${page.getSnapshotSettings()}.png`);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

View File

@ -1,10 +0,0 @@
import { newE2EPage } from '@stencil/core/testing';
test('item: dividers', async () => {
const page = await newE2EPage({
url: '/src/components/item/test/dividers?ionic:_testing=true',
});
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});

View File

@ -0,0 +1,12 @@
import { expect } from '@playwright/test';
import { test } from '@utils/test/playwright';
test.describe('item: dividers', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/src/components/item/test/dividers`);
await page.setIonViewport();
expect(await page.screenshot()).toMatchSnapshot(`item-dividers-diff-${page.getSnapshotSettings()}.png`);
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

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