@justeattakeaway/pie-button 0.24.1 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,113 +0,0 @@
1
- import { test } from '@sand4rt/experimental-ct-web';
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
- import { PieButton } from '@/index';
16
- import { sizes, variants } from '@/defs';
17
-
18
- const props: PropObject = {
19
- variant: variants,
20
- size: sizes,
21
- type: 'button', // Changing the type does not affect the appearance of the button
22
- isFullWidth: [true, false],
23
- disabled: [true, false],
24
- isLoading: [true, false],
25
- };
26
-
27
- // Renders a <pie-button> HTML string with the given prop values
28
- const renderTestPieButton = (propVals: WebComponentPropValues) => `<pie-button variant="${propVals.variant}" size="${propVals.size}" type="${propVals.type}" ${propVals.isFullWidth ? 'isFullWidth' : ''} ${propVals.disabled ? 'disabled' : ''} ${propVals.isLoading ? 'isLoading' : ''}>Hello world</pie-button>`;
29
-
30
- const componentPropsMatrix : WebComponentPropValues[] = getAllPropCombinations(props);
31
- const componentPropsMatrixByVariant: Record<string, WebComponentPropValues[]> = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant');
32
- const componentVariants: string[] = Object.keys(componentPropsMatrixByVariant);
33
-
34
- // This ensures the component is registered in the DOM for each test
35
- // This is not required if your tests mount the web component directly in the tests
36
- test.beforeEach(async ({ page, mount }) => {
37
- await mount(
38
- PieButton,
39
- {},
40
- );
41
-
42
- // Removing the element so it's not present in the tests (but is still registered in the DOM)
43
- await page.evaluate(() => {
44
- const element : Element | null = document.querySelector('pie-button');
45
- element?.remove();
46
- });
47
- });
48
-
49
- componentVariants.forEach((variant) => test(`Render all prop variations for Variant: ${variant}`, async ({ page, mount }) => {
50
- await Promise.all(componentPropsMatrixByVariant[variant].map(async (combo: WebComponentPropValues) => {
51
- const testComponent: WebComponentTestInput = createTestWebComponent(combo, renderTestPieButton);
52
- const propKeyValues = `size: ${testComponent.propValues.size}, isFullWidth: ${testComponent.propValues.isFullWidth}, disabled: ${testComponent.propValues.disabled}, isLoading: ${testComponent.propValues.isLoading}`;
53
- const darkMode = variant === 'inverse' || variant === 'ghost-inverse';
54
-
55
- await mount(
56
- WebComponentTestWrapper,
57
- {
58
- props: { propKeyValues, darkMode },
59
- slots: {
60
- component: testComponent.renderedString.trim(),
61
- },
62
- },
63
- );
64
- }));
65
-
66
- await percySnapshot(page, `PIE Button - Variant: ${variant}`);
67
- }));
68
-
69
- // TODO: Currently setting the slot to use a straight up SVG
70
- // This should be updated to use pie-icons-webc, but after some investigation, we think that we'll
71
- // need to convert the webc icons to use Lit, as currently the components don't work well in a Node env like Playwright
72
- // Atm, importing them like `import '@justeattakeaway/pie-icons-webc/icons/IconClose.js';` results in an `HTMLElement is not defined` error
73
- const plusSVG = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" focusable="false" fill="currentColor" viewBox="0 0 16 16" class="c-pieIcon c-pieIcon--plusCircle"><path d="M8.656 4.596H7.344v2.748H4.596v1.312h2.748v2.748h1.312V8.656h2.748V7.344H8.656V4.596Z"></path><path d="M12.795 3.205a6.781 6.781 0 1 0 0 9.625 6.79 6.79 0 0 0 0-9.625Zm-.927 8.662a5.469 5.469 0 1 1-7.734-7.735 5.469 5.469 0 0 1 7.734 7.736Z"></path></svg>';
74
- const chevronSVG = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" focusable="false" fill="currentColor" viewBox="0 0 16 16" class="c-pieIcon c-pieIcon--chevronDown"><path d="M2.82 5.044 8 10.399 13.197 5l.963.875-5.364 5.565a1.164 1.164 0 0 1-1.636 0L1.875 5.945l.945-.901Z"></path></svg>';
75
-
76
- sizes.forEach((size) => test(`Render icon slot variations for Size: ${size}`, async ({ page, mount }) => {
77
- const iconSlotVariations = [
78
- {
79
- 'icon-leading': plusSVG,
80
- },
81
- {
82
- 'icon-trailing': chevronSVG,
83
- },
84
- {
85
- 'icon-leading': plusSVG,
86
- 'icon-trailing': chevronSVG,
87
- },
88
- ];
89
-
90
- await Promise.all(iconSlotVariations.map(async (iconSlots) => {
91
- const iconLeading = iconSlots['icon-leading'] ? iconSlots['icon-leading'].replace('<svg', '<svg slot="icon-leading"') : '';
92
- const iconTrailing = iconSlots['icon-trailing'] ? iconSlots['icon-trailing'].replace('<svg', '<svg slot="icon-trailing"') : '';
93
-
94
- await mount(
95
- WebComponentTestWrapper,
96
- {
97
- props: {
98
- size,
99
- },
100
- slots: {
101
- component: `<pie-button size="${size}">
102
- ${iconLeading || ''}
103
- Hello, ${size} Button!
104
- ${iconTrailing || ''}
105
- </pie-button>`,
106
- },
107
- },
108
- );
109
- }));
110
-
111
- await percySnapshot(page, `PIE Button Leading Icon - Size: ${size}`);
112
- }));
113
-
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../../configs/pie-components-config/tsconfig.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "rootDir": ".",
6
- },
7
- "include": ["src/**/*.ts","./declaration.d.ts", "test/**/*.ts", "playwright-lit-visual.config.ts", "playwright-lit.config.ts"],
8
- }
package/vite.config.js DELETED
@@ -1,3 +0,0 @@
1
- import viteConfig from '@justeattakeaway/pie-components-config/vite.config';
2
-
3
- export default viteConfig;