@justeattakeaway/pie-webc-core 0.24.2 → 0.25.1

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.
package/README.md CHANGED
@@ -46,6 +46,8 @@ export class MyComponent extends RtlMixin(LitElement) implements MyComponentProp
46
46
  // ...
47
47
  }
48
48
  ```
49
+ ## Internals
50
+ The folder `internals` contains Typescript files that are to be imported into Pie Web Components and build into the bundles for each component. Everything else in this package is designed to be a one-time imported externalised dependency in applications using the web components to prevent duplication of code. The code in `internals` is the exception to this that contains things that must be included in each component bundle.
49
51
 
50
52
  ## Dependencies
51
53
 
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-webc-core",
3
- "version": "0.24.2",
3
+ "version": "0.25.1",
4
4
  "description": "PIE design system base classes, mixins and utilities for web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "author": "Just Eat Takeaway.com - Design System Team",
8
8
  "license": "Apache-2.0",
9
+ "files": [
10
+ "src/decorators",
11
+ "src/functions",
12
+ "src/interfaces",
13
+ "src/mixins",
14
+ "src/types",
15
+ "index.ts"
16
+ ],
9
17
  "scripts": {
10
18
  "build": "run -T vite build",
11
19
  "lint:scripts": "run -T eslint .",
12
20
  "lint:scripts:fix": "run -T eslint . --fix",
13
21
  "test": "run -T vitest run --config ../../../vite.config.js",
14
22
  "test:ci": "yarn test",
15
- "test:browsers-setup": "npx playwright-lit-setup",
16
23
  "test:browsers": "npx playwright test -c ./playwright-lit.config.ts",
17
24
  "test:browsers:ci": "yarn test:browsers",
18
25
  "test:watch": "run -T vitest"
@@ -21,7 +28,7 @@
21
28
  "lit": "3.2.0"
22
29
  },
23
30
  "devDependencies": {
24
- "@justeattakeaway/pie-components-config": "0.18.0"
31
+ "@justeattakeaway/pie-components-config": "0.19.1"
25
32
  },
26
33
  "volta": {
27
34
  "extends": "../../../package.json"
package/.eslintignore DELETED
@@ -1,5 +0,0 @@
1
- .turbo
2
- dist
3
- node_modules
4
- test-results
5
- lit-browsers-report
@@ -1,7 +0,0 @@
1
- vite v5.3.6 building for production...
2
- transforming...
3
- ✓ 16 modules transformed.
4
- rendering chunks...
5
- computing gzip size...
6
- dist/index.js 2.69 kB │ gzip: 1.22 kB
7
- ✓ built in 104ms
package/CHANGELOG.md DELETED
@@ -1,208 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.24.2
4
-
5
- ### Patch Changes
6
-
7
- - [Fixed] - Imports to align with new linting rule ([#1622](https://github.com/justeattakeaway/pie/pull/1622)) by [@xander-marjoram](https://github.com/xander-marjoram)
8
-
9
- [Removed] - Empty lines at the start of some files
10
-
11
- ## 0.24.1
12
-
13
- ### Patch Changes
14
-
15
- - [Changed] - Suggested package updates for security ([#1953](https://github.com/justeattakeaway/pie/pull/1953)) by [@xander-marjoram](https://github.com/xander-marjoram)
16
-
17
- ## 0.24.0
18
-
19
- ### Minor Changes
20
-
21
- - [Changed] - Update default props generic helper type to include all props by default ([#1582](https://github.com/justeattakeaway/pie/pull/1582)) by [@xander-marjoram](https://github.com/xander-marjoram)
22
-
23
- [Changed] - Naming of generic type
24
- [Added] - JSDoc comment
25
-
26
- ## 0.23.0
27
-
28
- ### Minor Changes
29
-
30
- - [Added] - Generic type for components default props ([#1451](https://github.com/justeattakeaway/pie/pull/1451)) by [@fernandofranca](https://github.com/fernandofranca)
31
-
32
- ## 0.22.0
33
-
34
- ### Minor Changes
35
-
36
- - [Changed] - Updated Lit from 3.1.2 to 3.1.3 ([#1427](https://github.com/justeattakeaway/pie/pull/1427)) by [@jamieomaguire](https://github.com/jamieomaguire)
37
-
38
- ## 0.21.1
39
-
40
- ### Patch Changes
41
-
42
- - [Removed] - Unneeded `bundledJetDeps` array (patch versions are required because pie-components-config is a dev dependency) ([#1378](https://github.com/justeattakeaway/pie/pull/1378)) by [@xander-marjoram](https://github.com/xander-marjoram)
43
-
44
- ## 0.21.0
45
-
46
- ### Minor Changes
47
-
48
- - [Added] - Bundle visualiser that runs during build for webc icons, webc core and our components ([#1391](https://github.com/justeattakeaway/pie/pull/1391)) by [@jamieomaguire](https://github.com/jamieomaguire)
49
-
50
- ## 0.20.0
51
-
52
- ### Minor Changes
53
-
54
- - [Changed] - Update tsconfig target to es2021 ([#1341](https://github.com/justeattakeaway/pie/pull/1341)) by [@jamieomaguire](https://github.com/jamieomaguire)
55
-
56
- ## 0.19.1
57
-
58
- ### Patch Changes
59
-
60
- - [Changed] - Updated lit to `3.1.2` ([#1300](https://github.com/justeattakeaway/pie/pull/1300)) by [@renovate](https://github.com/apps/renovate)
61
-
62
- ## 0.19.0
63
-
64
- ### Minor Changes
65
-
66
- - [Added] - dispatchCustomEvent helper function. ([#1272](https://github.com/justeattakeaway/pie/pull/1272)) by [@dandel10n](https://github.com/dandel10n)
67
-
68
- ## 0.18.0
69
-
70
- ### Minor Changes
71
-
72
- - [Added] - PIEInputElement interface ([#1257](https://github.com/justeattakeaway/pie/pull/1257)) by [@fernandofranca](https://github.com/fernandofranca)
73
-
74
- ## 0.17.1
75
-
76
- ### Patch Changes
77
-
78
- - [Changed] - Updated Lit to 3.1.1 ([#1178](https://github.com/justeattakeaway/pie/pull/1178)) by [@renovate](https://github.com/apps/renovate)
79
-
80
- ## 0.17.0
81
-
82
- ### Minor Changes
83
-
84
- - [Added] - new wrapNativeEvent function to standardise how we structure custom versions of native browser events such as 'change' ([#1173](https://github.com/justeattakeaway/pie/pull/1173)) by [@jamieomaguire](https://github.com/jamieomaguire)
85
-
86
- ## 0.16.0
87
-
88
- ### Minor Changes
89
-
90
- - [Removed] - unused LitElementMixin type as we do not need it anywhere ([#1145](https://github.com/justeattakeaway/pie/pull/1145)) by [@jamieomaguire](https://github.com/jamieomaguire)
91
-
92
- - [Changed] - Added `@justeattakeaway/pie-wrapper-react` as a devDependency as `build` now relies on the publish `add-react-wrapper` executable ([#1144](https://github.com/justeattakeaway/pie/pull/1144)) by [@siggerzz](https://github.com/siggerzz)
93
-
94
- - [Changed] - Use proper interface keyword for RTLmixin interface. Was using a class before which is incorrect. ([#1145](https://github.com/justeattakeaway/pie/pull/1145)) by [@jamieomaguire](https://github.com/jamieomaguire)
95
-
96
- ## 0.15.0
97
-
98
- ### Minor Changes
99
-
100
- - [Changed] - Updated LitElement imports where it is only used as a type to include the 'type' keyword (fixes a TS error in some consumers) ([#1143](https://github.com/justeattakeaway/pie/pull/1143)) by [@jamieomaguire](https://github.com/jamieomaguire)
101
-
102
- ## 0.14.0
103
-
104
- ### Minor Changes
105
-
106
- - [Added] - Form Control Mixin for adding native form association behaviour to web components ([#1142](https://github.com/justeattakeaway/pie/pull/1142)) by [@jamieomaguire](https://github.com/jamieomaguire)
107
-
108
- - [Changed] - Re organised test structure and added playwright testing ([#1142](https://github.com/justeattakeaway/pie/pull/1142)) by [@jamieomaguire](https://github.com/jamieomaguire)
109
-
110
- ## 0.13.0
111
-
112
- ### Minor Changes
113
-
114
- - [Added] - Build webc-core using vite ([#1037](https://github.com/justeattakeaway/pie/pull/1037)) by [@xander-marjoram](https://github.com/xander-marjoram)
115
-
116
- - [Changed] - Move lit dependency from storybook to webc-core ([#1037](https://github.com/justeattakeaway/pie/pull/1037)) by [@xander-marjoram](https://github.com/xander-marjoram)
117
-
118
- ## 0.12.0
119
-
120
- ### Minor Changes
121
-
122
- - [Changed] - `@validPropertyValues` and `@requiredProperty` decorators to support Lit 3. ([#1027](https://github.com/justeattakeaway/pie/pull/1027)) by [@raoufswe](https://github.com/raoufswe)
123
-
124
- ## 0.12.0-next.0
125
-
126
- ### Minor Changes
127
-
128
- - [Changed] - `@validPropertyValues` and `@requiredProperty` decorators to support Lit 3. ([#1025](https://github.com/justeattakeaway/pie/pull/1025)) by [@raoufswe](https://github.com/raoufswe)
129
-
130
- ## 0.11.0
131
-
132
- ### Minor Changes
133
-
134
- - [Added] - defineCustomElement helper function to protect against duplicate component registration errors ([#905](https://github.com/justeattakeaway/pie/pull/905)) by [@jamieomaguire](https://github.com/jamieomaguire)
135
-
136
- ## 0.10.0
137
-
138
- ### Minor Changes
139
-
140
- - [Fixed] - License removed from packages ([#869](https://github.com/justeattakeaway/pie/pull/869)) by [@kevinrodrigues](https://github.com/kevinrodrigues)
141
-
142
- ## 0.9.1
143
-
144
- ### Patch Changes
145
-
146
- - [Changed] - Align author field for all packages ([#852](https://github.com/justeattakeaway/pie/pull/852)) by [@xander-marjoram](https://github.com/xander-marjoram)
147
-
148
- ## 0.9.0
149
-
150
- ### Minor Changes
151
-
152
- - [Changed] - Rewrite RTL mixin to remove the dir property. The LitElement base class is a subclass of HTMLElement, so a Lit component inherits all of the standard HTMLElement properties and methods. This means that the dir property is already available on the component and we don't need to add it again. [Reference](https://lit.dev/docs/components/defining/#a-lit-component-is-an-html-element). During SSR, if no dir is provided, it will be inferred from the document.documentElement once it's instantiated on the client. ([#818](https://github.com/justeattakeaway/pie/pull/818)) by [@jamieomaguire](https://github.com/jamieomaguire)
153
-
154
- - [Changed] - Removed the DependantMap type and replaced all references with Lit's own PropertyValues helper. This provides exactly the same strongly typed map for a component's properties which makes our own type a little redundant. [Reference](https://lit.dev/docs/components/lifecycle/#typescript-types-for-changedproperties) ([#818](https://github.com/justeattakeaway/pie/pull/818)) by [@jamieomaguire](https://github.com/jamieomaguire)
155
-
156
- ## 0.8.0
157
-
158
- ### Minor Changes
159
-
160
- - [Changed] - Update RTL mixin to infer dir by default and document ([#745](https://github.com/justeattakeaway/pie/pull/745)) by [@raoufswe](https://github.com/raoufswe)
161
-
162
- ## 0.7.0
163
-
164
- ### Minor Changes
165
-
166
- - [Changed] - Add js/ts linting and fix errors ([#653](https://github.com/justeattakeaway/pie/pull/653)) by [@jamieomaguire](https://github.com/jamieomaguire)
167
-
168
- ## 0.6.0
169
-
170
- ### Minor Changes
171
-
172
- - [Changed] - Improve TS typings in RTL mixin and provde extendable prop interface for components ([#623](https://github.com/justeattakeaway/pie/pull/623)) by [@jamieomaguire](https://github.com/jamieomaguire)
173
-
174
- ## 0.5.0
175
-
176
- ### Minor Changes
177
-
178
- - [Removed] - Function for CSS loading in Safari visual tests due to fix on Percy side. ([#575](https://github.com/justeattakeaway/pie/pull/575)) by [@JoshuaNg2332](https://github.com/JoshuaNg2332)
179
-
180
- ## 0.4.0
181
-
182
- ### Minor Changes
183
-
184
- - [Added] - New function to fix CSS loading in Safari Percy tests ([#534](https://github.com/justeattakeaway/pie/pull/534)) by [@siggerzz](https://github.com/siggerzz)
185
-
186
- ## 0.3.0
187
-
188
- ### Minor Changes
189
-
190
- - [Added] - new WebComponentTestWrapper test component for adding labels to visual tests ([#519](https://github.com/justeattakeaway/pie/pull/519)) by [@jamieomaguire](https://github.com/jamieomaguire)
191
-
192
- - [Added] - a helper module to generate all prop variants of a given component ([#499](https://github.com/justeattakeaway/pie/pull/499)) by [@jamieomaguire](https://github.com/jamieomaguire)
193
-
194
- - [Added] - `required` property decorator ([#530](https://github.com/justeattakeaway/pie/pull/530)) by [@raoufswe](https://github.com/raoufswe)
195
-
196
- - [Changed] - Make pie-webc-core public ([#523](https://github.com/justeattakeaway/pie/pull/523)) by [@jamieomaguire](https://github.com/jamieomaguire)
197
-
198
- ## 0.2.0
199
-
200
- ### Minor Changes
201
-
202
- - [Added] - Property validation decorator ([#491](https://github.com/justeattakeaway/pie/pull/491)) by [@jamieomaguire](https://github.com/jamieomaguire)
203
-
204
- ## 0.1.0
205
-
206
- ### Minor Changes
207
-
208
- - [Added] - RTL Mixin and base project ([#478](https://github.com/justeattakeaway/pie/pull/478)) by [@jamieomaguire](https://github.com/jamieomaguire)
package/declaration.d.ts DELETED
@@ -1,9 +0,0 @@
1
- declare module '*.scss' {
2
- const content: Record<string, string>;
3
- export default content;
4
- }
5
-
6
- declare module '*.scss?inline' {
7
- const content: Record<string, string>;
8
- export default content;
9
- }
@@ -1,18 +0,0 @@
1
- import { defineConfig, devices } from '@sand4rt/experimental-ct-web';
2
- import { getPlaywrightConfig as getPlaywrightConfigOG } from '@justeattakeaway/pie-components-config';
3
- import type { PlaywrightTestConfig } from '@playwright/test';
4
-
5
- const getPlaywrightConfig = () : PlaywrightTestConfig => ({
6
- ...getPlaywrightConfigOG(),
7
- projects: [
8
- {
9
- name: 'component:chrome',
10
- use: {
11
- ...devices['Desktop Chrome'],
12
- },
13
- testMatch: ['**/test/**/*.browser.spec.ts'],
14
- },
15
- ],
16
- });
17
-
18
- export default defineConfig(getPlaywrightConfig());
@@ -1,73 +0,0 @@
1
- import {
2
- beforeEach,
3
- afterEach,
4
- describe,
5
- it,
6
- expect,
7
- vi,
8
- } from 'vitest';
9
-
10
- import { requiredProperty } from '../../decorators/required-property';
11
-
12
- describe('requiredProperty', () => {
13
- let consoleErrorSpy: unknown;
14
-
15
- beforeEach(() => {
16
- // eslint-disable-next-line @typescript-eslint/no-empty-function
17
- consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
18
- });
19
-
20
- afterEach(() => {
21
- vi.restoreAllMocks();
22
- });
23
-
24
- // Mock class to test the decorator
25
- class MockComponent {
26
- @requiredProperty('mock-component')
27
- color?: string | null;
28
- }
29
-
30
- it('should log an error if the property is undefined', () => {
31
- // Arrange
32
- const mockComponent = new MockComponent();
33
-
34
- // Act
35
- mockComponent.color = undefined;
36
-
37
- // Assert
38
- expect(consoleErrorSpy).toHaveBeenCalled();
39
- });
40
-
41
- it('should log an error if the property is null', () => {
42
- // Arrange
43
- const mockComponent = new MockComponent();
44
-
45
- // Act
46
- mockComponent.color = null;
47
-
48
- // Assert
49
- expect(consoleErrorSpy).toHaveBeenCalled();
50
- });
51
-
52
- it('should log an error if the property is an empty string', () => {
53
- // Arrange
54
- const mockComponent = new MockComponent();
55
-
56
- // Act
57
- mockComponent.color = '';
58
-
59
- // Assert
60
- expect(consoleErrorSpy).toHaveBeenCalled();
61
- });
62
-
63
- it('should not log an error if the property is a non-empty string', () => {
64
- // Arrange
65
- const mockComponent = new MockComponent();
66
-
67
- // Act
68
- mockComponent.color = 'blue';
69
-
70
- // Assert
71
- expect(consoleErrorSpy).not.toHaveBeenCalled();
72
- });
73
- });
@@ -1,68 +0,0 @@
1
- import {
2
- beforeEach,
3
- afterEach,
4
- describe,
5
- it,
6
- expect,
7
- vi,
8
- } from 'vitest';
9
-
10
- import { validPropertyValues } from '../../decorators/valid-property-values';
11
-
12
- describe('validPropertyValues', () => {
13
- let consoleErrorSpy: unknown;
14
-
15
- beforeEach(() => {
16
- // eslint-disable-next-line @typescript-eslint/no-empty-function
17
- consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
18
- });
19
-
20
- afterEach(() => {
21
- vi.restoreAllMocks();
22
- });
23
-
24
- // Mock class to test the decorator
25
- class MockComponent {
26
- @validPropertyValues('mock-component', ['red', 'green', 'blue'], 'red')
27
- color = 'red';
28
- }
29
-
30
- it('should allow value to be updated with a valid value', () => {
31
- // Arrange
32
- const mockComponent = new MockComponent();
33
-
34
- // Act
35
- mockComponent.color = 'green';
36
-
37
- // Assert
38
- expect(mockComponent.color).toBe('green');
39
- expect(consoleErrorSpy).not.toHaveBeenCalled();
40
- });
41
-
42
- it('should fallback to the default value if an invalid value is assigned', () => {
43
- // Arrange
44
- const mockComponent = new MockComponent();
45
-
46
- // Act
47
- mockComponent.color = 'yellow';
48
-
49
- // Assert
50
- expect(mockComponent.color).toBe('red');
51
- expect(consoleErrorSpy).toHaveBeenCalled();
52
- });
53
-
54
- it('should log an error message if an invalid value is assigned', () => {
55
- // Arrange
56
- const mockComponent = new MockComponent();
57
-
58
- // Act
59
- mockComponent.color = 'yellow';
60
-
61
- // Assert
62
- expect(consoleErrorSpy).toHaveBeenCalledWith(
63
- '<mock-component> Invalid value "yellow" provided for property "color".',
64
- 'Must be one of: red | green | blue.',
65
- 'Falling back to default value: "red"',
66
- );
67
- });
68
- });
@@ -1,81 +0,0 @@
1
- /* eslint-disable max-classes-per-file */
2
- import { LitElement } from 'lit';
3
- import {
4
- vi, expect, it,
5
- } from 'vitest';
6
- import { defineCustomElement } from '../../functions/defineCustomElement';
7
-
8
- it('should call console.warn when a component is defined twice', () => {
9
- // Arrange
10
- class MockComponentA extends LitElement {}
11
-
12
- const warnSpy = vi.spyOn(console, 'warn');
13
- const errorSpy = vi.spyOn(console, 'error');
14
-
15
- // Act
16
- defineCustomElement('mock-component-a', MockComponentA);
17
- defineCustomElement('mock-component-a', MockComponentA);
18
-
19
- // Assert
20
- const [[warning]] = warnSpy.mock.calls;
21
-
22
- expect(warnSpy).toHaveBeenCalledOnce();
23
- expect(warning).toMatch('PIE Web Component: "mock-component-a" has already been defined. Please ensure the component is only being defined once in your application.');
24
- expect(errorSpy).not.toHaveBeenCalled();
25
- expect(customElements.get('mock-component-a')).toBe(MockComponentA);
26
- });
27
-
28
- it('should define the component without warnings when called once', () => {
29
- // Arrange
30
- class MockComponentB extends LitElement {}
31
-
32
- const warnSpy = vi.spyOn(console, 'warn');
33
- const errorSpy = vi.spyOn(console, 'error');
34
-
35
- // Act
36
- defineCustomElement('mock-component-b', MockComponentB);
37
-
38
- // Assert
39
- expect(warnSpy).not.toHaveBeenCalled();
40
- expect(errorSpy).not.toHaveBeenCalled();
41
- expect(customElements.get('mock-component-b')).toBe(MockComponentB);
42
- });
43
-
44
- it('should warn when defining the same component name with a different class', () => {
45
- // Arrange
46
- class MockComponentC extends LitElement {}
47
-
48
- class MockComponentD extends LitElement {}
49
-
50
- const warnSpy = vi.spyOn(console, 'warn');
51
- const errorSpy = vi.spyOn(console, 'error');
52
-
53
- // Act
54
- defineCustomElement('mock-component-c', MockComponentC);
55
- defineCustomElement('mock-component-c', MockComponentD);
56
-
57
- // Assert
58
- const [[warning]] = warnSpy.mock.calls;
59
-
60
- expect(warnSpy).toHaveBeenCalledOnce();
61
- expect(warning).toMatch('PIE Web Component: "mock-component-c" has already been defined. Please ensure the component is only being defined once in your application.');
62
- expect(errorSpy).not.toHaveBeenCalled();
63
- expect(customElements.get('mock-component-c')).toBe(MockComponentC);
64
- });
65
-
66
- it('Should correctly accept component classes that use multiple levels of inheritance', () => {
67
- // Arrange
68
- class MockComponentE extends LitElement {}
69
- class MockComponentF extends MockComponentE {}
70
-
71
- const warnSpy = vi.spyOn(console, 'warn');
72
- const errorSpy = vi.spyOn(console, 'error');
73
-
74
- // Act
75
- defineCustomElement('mock-component-f', MockComponentF);
76
-
77
- // Assert
78
- expect(warnSpy).not.toHaveBeenCalled();
79
- expect(errorSpy).not.toHaveBeenCalled();
80
- expect(customElements.get('mock-component-f')).toBe(MockComponentF);
81
- });
@@ -1,28 +0,0 @@
1
- import { LitElement, html } from 'lit';
2
- import { property } from 'lit/decorators.js';
3
- import { defineCustomElement } from '../../../functions/defineCustomElement.js';
4
- import { dispatchCustomEvent } from '../../../functions/dispatchCustomEvent.js';
5
-
6
- const componentSelector = 'dispatch-custom-event-mock';
7
-
8
- export class MockComponent extends LitElement {
9
- @property({ type: String })
10
- public eventName = 'pie-mock-event';
11
-
12
- render () {
13
- return html`
14
- <button
15
- @click="${() => dispatchCustomEvent(this, this.eventName)}"
16
- data-test-id="dispatch-custom-event-mock">
17
- Component with the event to dispatch
18
- </button>`;
19
- }
20
- }
21
-
22
- declare global {
23
- interface HTMLElementTagNameMap {
24
- [componentSelector]: MockComponent;
25
- }
26
- }
27
-
28
- defineCustomElement(componentSelector, MockComponent);
@@ -1,45 +0,0 @@
1
- import { test, expect } from '@sand4rt/experimental-ct-web';
2
- import { MockComponent } from './MockComponent.ts';
3
-
4
- test.describe('dispatchCustomEvent function', () => {
5
- test('should dispatch an event when clicked', async ({ mount, page }) => {
6
- // Arrange
7
- const events : Array<Event> = [];
8
-
9
- await mount(MockComponent, {
10
- on: {
11
- 'pie-mock-event': (event: Event) => events.push(event),
12
- },
13
- });
14
-
15
- // Act
16
- await page.locator('[data-test-id="dispatch-custom-event-mock"]').click();
17
-
18
- // Assert
19
- expect(events).toHaveLength(1);
20
- });
21
-
22
- test('should call console.warn when event name do not start with "pie-"', async ({ mount, page }) => {
23
- // Arrange
24
- let result = '';
25
- const expected = 'A custom event name should start with `pie-`';
26
-
27
- await mount(MockComponent, {
28
- props: {
29
- eventName: 'mock-event',
30
- },
31
- });
32
-
33
- page.on('console', (msg) => {
34
- if (msg.type() === 'warning') {
35
- result = msg.text();
36
- }
37
- });
38
-
39
- // Act
40
- await page.locator('[data-test-id="dispatch-custom-event-mock"]').click();
41
-
42
- // Assert
43
- expect(result).toMatch(expected);
44
- });
45
- });
@@ -1,19 +0,0 @@
1
- import { LitElement, html } from 'lit';
2
- import { FormControlMixin } from '../../../mixins/formControl/formControlMixin.ts';
3
- import { defineCustomElement } from '../../../functions/defineCustomElement.ts';
4
-
5
- const componentSelector = 'form-control-mixin-mock';
6
-
7
- export class MockComponent extends FormControlMixin(LitElement) {
8
- render () {
9
- return html`<div>Form Control Component</div>`;
10
- }
11
- }
12
-
13
- declare global {
14
- interface HTMLElementTagNameMap {
15
- [componentSelector]: MockComponent;
16
- }
17
- }
18
-
19
- defineCustomElement(componentSelector, MockComponent);
@@ -1,76 +0,0 @@
1
- import { test, expect } from '@sand4rt/experimental-ct-web';
2
- import { MockComponent } from './MockComponent.ts';
3
-
4
- test.describe('FormControlMixin', () => {
5
- // IMPORTANT: Mounting and Unmounting the component before each test ensures that any tests that do not explicitly
6
- // mount the component will still have it available in Playwright's cache (loaded and registered in the test browser)
7
- test.beforeEach(async ({ mount }) => {
8
- const component = await mount(MockComponent);
9
- await component.unmount();
10
- });
11
-
12
- test.describe('form property', () => {
13
- test.describe('when no form exists', () => {
14
- test('should not have an associated form', async ({ page, mount }) => {
15
- // Arrange
16
- await mount(MockComponent);
17
-
18
- const isFormAssociated = await page.evaluate(() => {
19
- const component = document.querySelector('form-control-mixin-mock');
20
- const form = component?.form;
21
-
22
- return !!form;
23
- });
24
-
25
- // Assert
26
- expect(isFormAssociated).toBe(false);
27
- });
28
- });
29
-
30
- test.describe('when inside of a form', () => {
31
- test('should return the associated form', async ({ page }) => {
32
- // Arrange
33
- await page.setContent(`
34
- <form id="testForm" action="/foo" method="POST">
35
- <input type="text" id="username" name="username" required>
36
- <input type="password" id="password" name="password" required>
37
- <form-control-mixin-mock></form-control-mixin-mock>
38
- </form>
39
- `);
40
-
41
- const formId = await page.evaluate(() => {
42
- const component = document.querySelector('form-control-mixin-mock');
43
- const form = component?.form;
44
-
45
- return form?.id;
46
- });
47
-
48
- // Assert
49
- expect(formId).toContain('testForm');
50
- });
51
- });
52
-
53
- test.describe('when not inside of an existing form', () => {
54
- test('should not have an associated form', async ({ page }) => {
55
- // Arrange
56
- await page.setContent(`
57
- <form id="siblingForm" action="/foo" method="POST">
58
- <input type="text" id="username" name="username" required>
59
- <input type="password" id="password" name="password" required>
60
- </form>
61
- <form-control-mixin-mock></form-control-mixin-mock>
62
- `);
63
-
64
- const isFormAssociated = await page.evaluate(() => {
65
- const component = document.querySelector('form-control-mixin-mock');
66
- const form = component?.form;
67
-
68
- return !!form;
69
- });
70
-
71
- // Assert
72
- expect(isFormAssociated).toBe(false);
73
- });
74
- });
75
- });
76
- });
@@ -1,92 +0,0 @@
1
- import {
2
- LitElement, html, nothing,
3
- } from 'lit';
4
-
5
- import {
6
- describe,
7
- it,
8
- expect,
9
- vi,
10
- } from 'vitest';
11
-
12
- import { RtlMixin } from '../../../index';
13
-
14
- const scenarios = [
15
- { dir: 'ltr', isRTL: false },
16
- { dir: 'rtl', isRTL: true },
17
- { dir: 'auto', isRTL: false }
18
- ];
19
-
20
- vi.mock('lit', async () => ({
21
- ...((await vi.importActual('lit')) as Array<unknown>),
22
- isServer: false,
23
- }));
24
-
25
- describe('RtlMixin', () => {
26
- const componentSelector = 'rtl-mixin-mock';
27
-
28
- class MockComponent extends RtlMixin(LitElement) {
29
- render () {
30
- const { isRTL, dir } = this;
31
- return html`<div dir="${dir || nothing}">${isRTL ? 'RTL Mode' : 'LTR Mode'}</div>`;
32
- }
33
- }
34
-
35
- customElements.define(componentSelector, MockComponent);
36
-
37
- function getMockInstance (): MockComponent {
38
- return document.body.querySelector(componentSelector) as MockComponent;
39
- }
40
-
41
- describe('when running in the browser', () => {
42
- describe('when the dir attribute is set via the component', () => {
43
- scenarios.forEach(({ dir, isRTL }) => {
44
- it(`should reflect ${isRTL ? 'RTL' : 'LTR'} if the component dir attribute is set to ${dir}`, () => {
45
- // Arrange
46
- document.body.innerHTML = `<rtl-mixin-mock dir="${dir}"></rtl-mixin-mock>`;
47
- const component = getMockInstance();
48
-
49
- // Assert
50
- expect(component.isRTL).toBe(isRTL);
51
- });
52
- });
53
- });
54
-
55
- describe('when the dir attribute is set via the root document and no attribute provided to the component', () => {
56
- scenarios.forEach(({ dir, isRTL }) => {
57
- it(`should reflect ${isRTL ? 'RTL' : 'LTR'} if the root document dir attribute is set to ${dir}`, () => {
58
- // Arrange
59
- document.documentElement.setAttribute('dir', dir);
60
- document.body.innerHTML = '<rtl-mixin-mock></rtl-mixin-mock>'; // component doesn't set dir
61
- const component = getMockInstance();
62
-
63
- // Assert
64
- expect(component.isRTL).toBe(isRTL);
65
- });
66
- });
67
- });
68
-
69
- it('should prefer the dir value of the component over the root document when both are set', () => {
70
- // Arrange
71
- const rootDir = 'ltr';
72
- const componentDir = 'rtl';
73
- document.documentElement.setAttribute('dir', rootDir);
74
- document.body.innerHTML = `<rtl-mixin-mock dir="${componentDir}"></rtl-mixin-mock>`;
75
- const component = getMockInstance();
76
-
77
- // Assert
78
- expect(component.isRTL).toBeTruthy();
79
- });
80
-
81
- it('should reflect the root document dir attribute if `auto` is provided to the component', () => {
82
- // Arrange
83
- const rootDir = 'ltr';
84
- document.documentElement.setAttribute('dir', rootDir);
85
- document.body.innerHTML = '<rtl-mixin-mock dir="auto"></rtl-mixin-mock>';
86
- const component = getMockInstance();
87
-
88
- // Assert
89
- expect(component.isRTL).toBeFalsy();
90
- });
91
- });
92
- });
@@ -1,62 +0,0 @@
1
- import {
2
- LitElement, html, nothing,
3
- } from 'lit';
4
-
5
- import {
6
- describe,
7
- it,
8
- expect,
9
- vi,
10
- } from 'vitest';
11
-
12
- import { RtlMixin } from '../../../index';
13
-
14
- const scenarios = [
15
- { dir: 'ltr', isRTL: false },
16
- { dir: 'rtl', isRTL: true },
17
- { dir: 'auto', isRTL: false }
18
- ];
19
-
20
- vi.mock('lit', async () => ({
21
- ...((await vi.importActual('lit')) as Array<unknown>),
22
- isServer: true,
23
- }));
24
-
25
- describe('RtlMixin', () => {
26
- const componentSelector = 'rtl-mixin-mock';
27
-
28
- class MockComponent extends RtlMixin(LitElement) {
29
- render () {
30
- const { isRTL, dir } = this;
31
- return html`<div dir="${dir || nothing}">${isRTL ? 'RTL Mode' : 'LTR Mode'}</div>`;
32
- }
33
- }
34
-
35
- customElements.define(componentSelector, MockComponent);
36
-
37
- function getMockInstance (): MockComponent {
38
- return document.body.querySelector(componentSelector) as MockComponent;
39
- }
40
-
41
- describe('when running on the server', () => {
42
- it('should return false for isRTL when dir is not set', () => {
43
- // Arrange
44
- document.body.innerHTML = '<rtl-mixin-mock></rtl-mixin-mock>';
45
- const component = getMockInstance();
46
-
47
- // Assert
48
- expect(component.isRTL).toBeFalsy();
49
- });
50
-
51
- scenarios.forEach(({ dir, isRTL }) => {
52
- it(`should reflect ${isRTL ? 'RTL' : 'LTR'} if the component dir attribute is set to ${dir} when running on the server`, () => {
53
- // Arrange
54
- document.body.innerHTML = `<rtl-mixin-mock dir="${dir}"></rtl-mixin-mock>`;
55
- const component = getMockInstance();
56
-
57
- // Assert
58
- expect(component.isRTL).toBe(isRTL);
59
- });
60
- });
61
- });
62
- });
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "@justeattakeaway/pie-components-config/tsconfig.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "rootDir": ".",
6
- },
7
- "include": ["src/**/*.ts", "./declaration.d.ts", "test/**/*.ts", "index.ts", "playwright-lit.config.ts"],
8
- }
package/vite.config.js DELETED
@@ -1,32 +0,0 @@
1
- import { defineConfig } from 'vite';
2
- import { visualizer } from 'rollup-plugin-visualizer';
3
-
4
- export default defineConfig({
5
- build: {
6
- lib: {
7
- entry: {
8
- index: 'src/index.ts',
9
- },
10
- formats: ['es'],
11
- },
12
- rollupOptions: {
13
- external: (id) => /^lit/.test(id),
14
- },
15
- },
16
- test: {
17
- dir: '.',
18
- environment: 'jsdom',
19
- globals: true,
20
- exclude: [
21
- '**/test/{accessibility,component,system,visual}/*.spec.{js,ts}',
22
- '**/test/**/*.browser.spec.{js,ts}',
23
- '**/node_modules/**/*'
24
- ],
25
- },
26
- plugins: [
27
- visualizer({
28
- gzipSize: true,
29
- brotliSize: true,
30
- })
31
- ],
32
- });