test(picker-column): migrate tests to playwright (#25303)
@ -1,19 +0,0 @@
|
||||
import { testPickerColumn } from '../test.utils';
|
||||
|
||||
const TEST_TYPE = 'standalone';
|
||||
|
||||
test('picker-column: standalone', async () => {
|
||||
await testPickerColumn(TEST_TYPE, '#single-column-button');
|
||||
});
|
||||
|
||||
test('picker-column:multi-column standalone', async () => {
|
||||
await testPickerColumn(TEST_TYPE, '#multiple-column-button');
|
||||
});
|
||||
|
||||
test('picker-column:rtl: standalone', async () => {
|
||||
await testPickerColumn(TEST_TYPE, '#single-column-button', true);
|
||||
});
|
||||
|
||||
test('picker-column:multi-column:rtl standalone', async () => {
|
||||
await testPickerColumn(TEST_TYPE, '#multiple-column-button', true);
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
import { testPickerColumn } from '../test.utils';
|
||||
|
||||
test.describe('picker-column', () => {
|
||||
test.describe('single column', () => {
|
||||
test('should not have any visual regressions', async ({ page }) => {
|
||||
await page.goto('/src/components/picker-column/test/standalone');
|
||||
await testPickerColumn(page, '#single-column-button', 'single');
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('multiple columns', () => {
|
||||
test('should not have any visual regressions', async ({ page }) => {
|
||||
await page.goto('/src/components/picker-column/test/standalone');
|
||||
await testPickerColumn(page, '#multiple-column-button', 'multiple');
|
||||
});
|
||||
});
|
||||
});
|
After Width: | Height: | Size: 71 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 71 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 38 KiB |
@ -1,54 +1,45 @@
|
||||
import { newE2EPage } from '@stencil/core/testing';
|
||||
import { dragElementBy, generateE2EUrl, listenForEvent, waitForFunctionTestContext } from '@utils/test';
|
||||
import { expect } from '@playwright/test';
|
||||
import type { E2EPage } from '@utils/test/playwright';
|
||||
import { dragElementBy } from '@utils/test/playwright';
|
||||
|
||||
export const testPickerColumn = async (type: string, selector: string, rtl = false) => {
|
||||
try {
|
||||
const pageUrl = generateE2EUrl('picker-column', type, rtl);
|
||||
/**
|
||||
* Visual regression tests for picker-column.
|
||||
* @param page - The page to run the tests on.
|
||||
* @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) {
|
||||
const ionPickerDidPresentSpy = await page.spyOnEvent('ionPickerDidPresent');
|
||||
|
||||
const page = await newE2EPage({
|
||||
url: pageUrl,
|
||||
await page.click(buttonSelector);
|
||||
await ionPickerDidPresentSpy.next();
|
||||
|
||||
await page.waitForTimeout(100);
|
||||
|
||||
expect(await page.screenshot()).toMatchSnapshot(
|
||||
`picker-${description}-column-initial-${page.getSnapshotSettings()}.png`
|
||||
);
|
||||
|
||||
const columns = page.locator('.picker-opt-selected');
|
||||
const spy = await page.spyOnEvent('ionPickerColChange');
|
||||
|
||||
const screenshots = [];
|
||||
|
||||
for (let i = 0; i < (await columns.count()); i++) {
|
||||
const column = columns.nth(i);
|
||||
|
||||
await dragElementBy(column, page, 0, -100);
|
||||
await spy.next();
|
||||
|
||||
await page.waitForTimeout(100);
|
||||
|
||||
screenshots.push({
|
||||
name: `picker-${description}-column-diff-${i}-${page.getSnapshotSettings()}.png`,
|
||||
screenshot: await page.screenshot(),
|
||||
});
|
||||
|
||||
const screenshotCompares = [];
|
||||
|
||||
const openButton = await page.find(selector);
|
||||
await openButton.click();
|
||||
await page.waitForTimeout(250);
|
||||
|
||||
screenshotCompares.push(await page.compareScreenshot());
|
||||
|
||||
// Setup counter
|
||||
let colChangeCounter: any;
|
||||
|
||||
// Expose an event callback method
|
||||
const COL_CHANGE = 'onIonPickerColChange';
|
||||
await page.exposeFunction(COL_CHANGE, () => {
|
||||
colChangeCounter.count += 1;
|
||||
});
|
||||
|
||||
const columns = await page.$$('ion-picker-column');
|
||||
for (const column of Array.from(columns)) {
|
||||
colChangeCounter = { count: 0 };
|
||||
|
||||
// Attach a listener to element with a callback
|
||||
await listenForEvent(page, 'ionPickerColChange', column, COL_CHANGE);
|
||||
|
||||
// Simulate a column drag
|
||||
await dragElementBy(column, page, 0, 100);
|
||||
|
||||
// Wait for ionPickerColChange event to be emitted once
|
||||
await waitForFunctionTestContext(
|
||||
(payload: any) => {
|
||||
return payload.colChangeCounter.count === 1;
|
||||
},
|
||||
{ colChangeCounter }
|
||||
);
|
||||
}
|
||||
|
||||
for (const screenshotCompare of screenshotCompares) {
|
||||
expect(screenshotCompare).toMatchScreenshot();
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
for (const screenshot of screenshots) {
|
||||
expect(screenshot.screenshot).toMatchSnapshot(screenshot.name);
|
||||
}
|
||||
}
|
||||
|