|
1 |
| -import { test } from '@sand4rt/experimental-ct-web'; |
| 1 | +import { test } from '@playwright/test'; |
2 | 2 | import percySnapshot from '@percy/playwright';
|
3 |
| -import type { |
4 |
| - PropObject, WebComponentPropValues, WebComponentTestInput, |
5 |
| -} from '@justeattakeaway/pie-webc-testing/src/helpers/defs.ts'; |
6 |
| -import { |
7 |
| - getAllPropCombinations, splitCombinationsByPropertyValue, |
8 |
| -} from '@justeattakeaway/pie-webc-testing/src/helpers/get-all-prop-combos.ts'; |
9 |
| -import { |
10 |
| - createTestWebComponent, |
11 |
| -} from '@justeattakeaway/pie-webc-testing/src/helpers/rendering.ts'; |
12 |
| -import { |
13 |
| - WebComponentTestWrapper, |
14 |
| -} from '@justeattakeaway/pie-webc-testing/src/helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts'; |
15 | 3 | import { percyWidths } from '@justeattakeaway/pie-webc-testing/src/percy/breakpoints.ts';
|
16 |
| -import { IconHeartFilled } from '@justeattakeaway/pie-icons-webc'; |
17 | 4 | import { variants } from '../../src/defs.ts';
|
18 |
| -import { PieChip } from '../../src/index.ts'; |
| 5 | +import { BasePage } from '@justeattakeaway/pie-webc-testing/src/helpers/page-object/base-page.ts'; |
19 | 6 |
|
20 |
| -const props: PropObject = { |
21 |
| - variant: variants, |
22 |
| - disabled: [true, false], |
23 |
| - isSelected: [true, false], |
24 |
| - isLoading: [true, false], |
25 |
| - isDismissible: [true, false], |
26 |
| - iconSlot: ['', '<icon-heart-filled slot="icon"></icon-heart-filled>'], |
27 |
| -}; |
| 7 | +variants.forEach((variant) => test(`should render all prop variations for Variant: ${variant}`, async ({ page }) => { |
| 8 | + let basePage = new BasePage(page, `chip--${variant}-prop-variations`); |
28 | 9 |
|
29 |
| -// Renders a <pie-chip> HTML string with the given prop values |
30 |
| -const renderTestPieChip = (propVals: WebComponentPropValues) => `<pie-chip variant="${propVals.variant}" ${propVals.isDismissible ? 'isDismissible' : ''} ${propVals.isLoading ? 'isLoading' : ''} ${propVals.isSelected ? 'isSelected' : ''} ${propVals.disabled ? 'disabled' : ''}>${propVals.iconSlot} Hello world</pie-chip>`; |
31 |
| - |
32 |
| -const componentPropsMatrix: WebComponentPropValues[] = getAllPropCombinations(props); |
33 |
| -const componentPropsMatrixByVariant: Record<string, WebComponentPropValues[]> = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant'); |
34 |
| -const componentVariants: string[] = Object.keys(componentPropsMatrixByVariant); |
35 |
| - |
36 |
| -test.beforeEach(async ({ mount }, testInfo) => { |
37 |
| - testInfo.setTimeout(testInfo.timeout + 40000); |
38 |
| - |
39 |
| - // This ensures the chip and icon components are registered in the DOM for each test. |
40 |
| - // It appears to add them to a Playwright cache which we understand is required for the tests to work correctly. |
41 |
| - const chipComponent = await mount(PieChip); |
42 |
| - await chipComponent.unmount(); |
43 |
| - const iconComponent = await mount(IconHeartFilled); |
44 |
| - await iconComponent.unmount(); |
45 |
| -}); |
46 |
| - |
47 |
| -componentVariants.forEach((variant) => test(`should render all prop variations for Variant: ${variant}`, async ({ page, mount }) => { |
48 |
| - for (const combo of componentPropsMatrixByVariant[variant]) { |
49 |
| - const testComponent: WebComponentTestInput = createTestWebComponent(combo, renderTestPieChip); |
50 |
| - const propKeyValues = ` |
51 |
| - variant: ${testComponent.propValues.variant}, |
52 |
| - isSelected: ${testComponent.propValues.isSelected}, |
53 |
| - isLoading: ${testComponent.propValues.isLoading}, |
54 |
| - isDismissible: ${testComponent.propValues.isDismissible}, |
55 |
| - disabled: ${testComponent.propValues.disabled}, |
56 |
| - iconSlot: ${testComponent.propValues.iconSlot ? 'with icon' : 'no icon'}`; |
57 |
| - |
58 |
| - await mount( |
59 |
| - WebComponentTestWrapper, |
60 |
| - { |
61 |
| - props: { propKeyValues }, |
62 |
| - slots: { |
63 |
| - component: testComponent.renderedString.trim(), |
64 |
| - }, |
65 |
| - }, |
66 |
| - ); |
67 |
| - } |
| 10 | + basePage.load(); |
68 | 11 |
|
69 | 12 | // Follow up to remove in Jan
|
70 | 13 | await page.waitForTimeout(5000);
|
|
0 commit comments