@justeattakeaway/pie-modal 0.17.0 → 0.19.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,31 +0,0 @@
1
- import { ModalProps } from '@/defs';
2
-
3
- // Renders a <pie-modal> HTML string with the given prop values
4
- export const renderTestPieModal = ({
5
- heading = 'This is a modal heading',
6
- headingLevel = 'h2',
7
- isDismissible = true,
8
- isFullWidthBelowMid = false,
9
- isOpen = true,
10
- returnFocusAfterCloseSelector = undefined,
11
- size = 'medium',
12
- } : Partial<ModalProps> = {}) => `<pie-modal
13
- heading="${heading}"
14
- headingLevel="${headingLevel}"
15
- ${isFullWidthBelowMid ? 'isFullWidthBelowMid' : ''}
16
- ${isDismissible ? 'isDismissible' : ''}
17
- ${isOpen ? 'isOpen' : ''}
18
- ${returnFocusAfterCloseSelector ? `returnFocusAfterCloseSelector=${returnFocusAfterCloseSelector}` : ''}
19
- size="${size}">
20
- </pie-modal>`;
21
-
22
- // Creates some test page markup to test scroll locking
23
- export const createScrollablePageHTML = () => `<div>
24
- <h1>Test Page</h1>
25
- <p>Top of page copy</p>
26
- <p> Test copy </p>
27
- <ol>
28
- ${'<li>List item</li>'.repeat(200)}
29
- <li>Bottom of page copy</li>
30
- </ol>
31
- </div>`;
@@ -1,494 +0,0 @@
1
- import { test } from '@sand4rt/experimental-ct-web';
2
- import percySnapshot from '@percy/playwright';
3
- import { PieIconButton } from '@justeattakeaway/pie-icon-button';
4
- import { PieButton } from '@justeattakeaway/pie-button';
5
- import { positions } from '@/defs.ts';
6
- import { PieModal } from '@/index';
7
- import { ModalProps, sizes } from '@/defs';
8
-
9
- // Mount any components that are used inside pie-modal so that
10
- // they have been registered with the browser before the tests run.
11
- // There is likely a nicer way to do this but this will temporarily
12
- // unblock tests.
13
- test.beforeEach(async ({ mount }) => {
14
- await (await mount(PieButton)).unmount();
15
- await (await mount(PieIconButton)).unmount();
16
- });
17
-
18
- sizes.forEach((size) => {
19
- test(`should render correctly with size = ${size}`, async ({ page, mount }) => {
20
- await mount(PieModal, {
21
- props: {
22
- heading: 'This is a modal heading',
23
- isOpen: true,
24
- size,
25
- leadingAction: {
26
- text: 'Confirm',
27
- variant: 'primary',
28
- ariaLabel: 'Confirmation text',
29
- },
30
- } as ModalProps,
31
- });
32
-
33
- await percySnapshot(page, `Modal - size = ${size}`);
34
- });
35
- });
36
-
37
- test.describe('Prop: `isFullWidthBelowMid`', () => {
38
- test.describe('when true', () => {
39
- test('should be full width for a modal with size = medium', async ({ page, mount }) => {
40
- await mount(PieModal, {
41
- props: {
42
- heading: 'This is a modal heading',
43
- isFullWidthBelowMid: true,
44
- isOpen: true,
45
- size: 'medium',
46
- leadingAction: {
47
- text: 'Confirm',
48
- variant: 'primary',
49
- ariaLabel: 'Confirmation text',
50
- },
51
- } as ModalProps,
52
- });
53
-
54
- await percySnapshot(page, 'Modal - isFullWidthBelowMid = true, size = medium');
55
- });
56
-
57
- test('should not be full width when size = small', async ({ page, mount }) => {
58
- await mount(PieModal, {
59
- props: {
60
- heading: 'This is a modal heading',
61
- isFullWidthBelowMid: true,
62
- isOpen: true,
63
- size: 'small',
64
- leadingAction: {
65
- text: 'Confirm',
66
- variant: 'primary',
67
- ariaLabel: 'Confirmation text',
68
- },
69
- } as ModalProps,
70
- });
71
-
72
- await percySnapshot(page, 'Modal - isFullWidthBelowMid = true, size = small');
73
- });
74
- });
75
-
76
- test.describe('when false', () => {
77
- (['small', 'medium'] as Array<ModalProps['size']>)
78
- .forEach((size) => {
79
- test(`should not be full width for a modal with size = ${size}`, async ({ page, mount }) => {
80
- await mount(PieModal, {
81
- props: {
82
- heading: 'This is a modal heading',
83
- isFullWidthBelowMid: false,
84
- isOpen: true,
85
- size,
86
- leadingAction: {
87
- text: 'Confirm',
88
- variant: 'primary',
89
- ariaLabel: 'Confirmation text',
90
- },
91
- } as ModalProps,
92
- });
93
-
94
- await percySnapshot(page, `Modal - isFullWidthBelowMid = false, size = ${size}`);
95
- });
96
- });
97
- });
98
- });
99
-
100
- test.describe('Prop: `isDismissible`', () => {
101
- test.describe('when true', () => {
102
- test('should display a close button within the modal', async ({ mount, page }) => {
103
- await mount(PieModal, {
104
- props: {
105
- heading: 'This is a modal heading',
106
- isDismissible: true,
107
- isOpen: true,
108
- leadingAction: {
109
- text: 'Confirm',
110
- variant: 'primary',
111
- ariaLabel: 'Confirmation text',
112
- },
113
- } as ModalProps,
114
- });
115
-
116
- await percySnapshot(page, 'Modal with close button displayed - isDismissible: `true`');
117
- });
118
- });
119
-
120
- test.describe('when false', () => {
121
- test('should not display a close button', async ({ mount, page }) => {
122
- await mount(PieModal, {
123
- props: {
124
- heading: 'This is a modal heading',
125
- isDismissible: false,
126
- isOpen: true,
127
- leadingAction: {
128
- text: 'Confirm',
129
- variant: 'primary',
130
- ariaLabel: 'Confirmation text',
131
- },
132
- } as ModalProps,
133
- });
134
-
135
- await percySnapshot(page, 'Modal without close button - isDismissible: `false`');
136
- });
137
- });
138
- });
139
-
140
- const directions = ['ltr', 'rtl', 'auto'] as const;
141
-
142
- test.describe('Prop: `hasBackButton`', () => {
143
- directions.forEach((dir) => {
144
- test.describe('when true', () => {
145
- test(`should display a back button within the modal and dir is ${dir}`, async ({ mount, page }) => {
146
- await mount(PieModal, {
147
- props: {
148
- heading: 'This is a modal heading',
149
- hasBackButton: true,
150
- isOpen: true,
151
- dir,
152
- leadingAction: {
153
- text: 'Confirm',
154
- variant: 'primary',
155
- ariaLabel: 'Confirmation text',
156
- },
157
- } as ModalProps,
158
- });
159
-
160
- await percySnapshot(page, `Modal with back button displayed - hasBackButton: ${true} - dir: ${dir}`);
161
- });
162
- });
163
-
164
- test.describe('when false', () => {
165
- test(`should not display a back button and dir is ${dir}`, async ({ mount, page }) => {
166
- await mount(PieModal, {
167
- props: {
168
- heading: 'This is a modal heading',
169
- hasBackButton: false,
170
- isOpen: true,
171
- dir,
172
- leadingAction: {
173
- text: 'Confirm',
174
- variant: 'primary',
175
- ariaLabel: 'Confirmation text',
176
- },
177
- } as ModalProps,
178
- });
179
-
180
- await percySnapshot(page, `Modal without back button - hasBackButton: ${false} - dir: ${dir}`);
181
- });
182
- });
183
- });
184
- });
185
-
186
- test.describe('Prop: `heading`', () => {
187
- test('should display & render long headings correctly', async ({ page, mount }) => {
188
- await mount(PieModal, {
189
- props: {
190
- heading: 'This is a modal heading but super long and should span multiple lines, hopefully this should never happen on production!',
191
- isOpen: true,
192
- size: 'medium',
193
- hasBackButton: true,
194
- isDismissible: true,
195
- leadingAction: {
196
- text: 'Confirm',
197
- variant: 'primary',
198
- ariaLabel: 'Confirmation text',
199
- },
200
- } as ModalProps,
201
- });
202
-
203
- await percySnapshot(page, 'Modal - Long heading');
204
- });
205
- });
206
-
207
- test.describe('Prop: `isLoading`', () => {
208
- test('should display loading spinner when `isLoading` is true', async ({ mount, page }) => {
209
- await mount(PieModal, {
210
- props: {
211
- heading: 'This is a modal heading',
212
- hasBackButton: true,
213
- isDismissible: true,
214
- isOpen: true,
215
- isLoading: true,
216
- leadingAction: {
217
- text: 'Confirm',
218
- variant: 'primary',
219
- ariaLabel: 'Confirmation text',
220
- },
221
- } as ModalProps,
222
- });
223
-
224
- await percySnapshot(page, `Modal displays loading spinner - isLoading: ${true}`);
225
- });
226
- });
227
-
228
- test.describe('Prop: `leadingAction`', () => {
229
- test.describe('when prop is passed into component', () => {
230
- test('should display `leadingAction` when props are passed correctly', async ({ mount, page }) => {
231
- await mount(PieModal, {
232
- props: {
233
- heading: 'This is a modal heading',
234
- isOpen: true,
235
- leadingAction: {
236
- text: 'Confirm',
237
- variant: 'primary',
238
- ariaLabel: 'Confirmation text',
239
- },
240
- } as ModalProps,
241
- });
242
-
243
- await percySnapshot(page, 'Modal displays leadingAction');
244
- });
245
- });
246
-
247
- test.describe('when prop is provided but the optional child properties of `leadingAction` are not provided', () => {
248
- test('should falls back to defaults', async ({ mount, page }) => {
249
- await mount(PieModal, {
250
- props: {
251
- heading: 'This is a modal heading',
252
- isOpen: true,
253
- leadingAction: {
254
- text: 'Confirm',
255
- },
256
- } as ModalProps,
257
- });
258
-
259
- await percySnapshot(page, 'Modal falls back to default property `primary`');
260
- });
261
- });
262
-
263
- test.describe('when prop is provided but the `text` child property of `leadingAction` is empty', () => {
264
- test('should not render leadingAction markup', async ({ mount, page }) => {
265
- await mount(PieModal, {
266
- props: {
267
- heading: 'This is a modal heading',
268
- isOpen: true,
269
- leadingAction: {
270
- text: '',
271
- },
272
- } as ModalProps,
273
- });
274
-
275
- await percySnapshot(page, 'Modal will not render `leadingAction` button when `text` is empty');
276
- });
277
- });
278
-
279
- test.describe('when prop is not passed into component', () => {
280
- test('should not display `leadingAction`', async ({ mount, page }) => {
281
- await mount(PieModal, {
282
- props: {
283
- heading: 'This is a modal heading',
284
- isOpen: true,
285
- } as ModalProps,
286
- });
287
-
288
- await percySnapshot(page, 'Modal does not display leadingAction');
289
- });
290
- });
291
- });
292
-
293
- test.describe('Prop: `supportingAction`', () => {
294
- test.describe('when `leadingAction` prop exists', () => {
295
- test('should display `supportingAction` correctly', async ({ mount, page }) => {
296
- await mount(PieModal, {
297
- props: {
298
- heading: 'This is a modal heading',
299
- isOpen: true,
300
- leadingAction: {
301
- text: 'Confirm',
302
- variant: 'primary',
303
- ariaLabel: 'Confirmation text',
304
- },
305
- supportingAction: {
306
- text: 'Cancel',
307
- variant: 'ghost',
308
- ariaLabel: 'Cancellation text',
309
- },
310
- } as ModalProps,
311
- });
312
-
313
- await percySnapshot(page, 'Modal displays supportingAction alongside leadingAction');
314
- });
315
-
316
- test.describe('when prop is provided but the optional child properties of `supportingAction` are not provided', () => {
317
- test('should fall back to default property', async ({ mount, page }) => {
318
- await mount(PieModal, {
319
- props: {
320
- heading: 'This is a modal heading',
321
- isOpen: true,
322
- leadingAction: {
323
- text: 'Confirm',
324
- variant: 'primary',
325
- ariaLabel: 'Confirmation text',
326
- },
327
- supportingAction: {
328
- text: 'Cancel',
329
- ariaLabel: 'Confirmation text',
330
- },
331
- } as ModalProps,
332
- });
333
-
334
- await percySnapshot(page, 'Modal falls back to default variant property `ghost`');
335
- });
336
- });
337
-
338
- test.describe('when `supportingAction` prop is provided but the `text` child property of `supportingAction` is empty', () => {
339
- test('should not render supportingAction markup', async ({ mount, page }) => {
340
- await mount(PieModal, {
341
- props: {
342
- heading: 'This is a modal heading',
343
- isOpen: true,
344
- leadingAction: {
345
- text: 'Confirm',
346
- variant: 'primary',
347
- ariaLabel: 'Confirmation text',
348
- },
349
- supportingAction: {
350
- text: '',
351
- },
352
- } as ModalProps,
353
- });
354
-
355
- await percySnapshot(page, 'Modal will not render `supportingAction` button when `text` is empty');
356
- });
357
- });
358
-
359
- test.describe('when `supportingAction` is not supplied', () => {
360
- test('should not render supportingAction markup', async ({ mount, page }) => {
361
- await mount(PieModal, {
362
- props: {
363
- heading: 'This is a modal heading',
364
- isOpen: true,
365
- leadingAction: {
366
- text: 'Confirm',
367
- variant: 'primary',
368
- ariaLabel: 'Confirmation text',
369
- },
370
- } as ModalProps,
371
- });
372
-
373
- await percySnapshot(page, 'Modal will not render `supportingAction` when it is not supplied');
374
- });
375
- });
376
- });
377
-
378
- test.describe('when `leadingAction` prop does not exist and `supportingAction` is supplied', () => {
379
- test('should not render supportingAction markup', async ({ mount, page }) => {
380
- await mount(PieModal, {
381
- props: {
382
- heading: 'This is a modal heading',
383
- isOpen: true,
384
- supportingAction: {
385
- text: 'Cancel',
386
- variant: 'ghost',
387
- ariaLabel: 'Cancellation text',
388
- },
389
- } as ModalProps,
390
- });
391
-
392
- await percySnapshot(page, 'Modal will not render `supportingAction` when `leadingAction` is not supplied');
393
- });
394
- });
395
- });
396
-
397
- test.describe('Prop: `position`', () => {
398
- positions.forEach((position) => {
399
- test(`should be positioned in the correct part of the page when position is: ${position}`, async ({ mount, page }) => {
400
- await mount(PieModal, {
401
- props: {
402
- heading: 'This is a modal heading',
403
- isOpen: true,
404
- position,
405
- leadingAction: {
406
- text: 'Confirm',
407
- variant: 'primary',
408
- ariaLabel: 'Confirmation text',
409
- },
410
- } as ModalProps,
411
- });
412
-
413
- await percySnapshot(page, `Modal position: ${position}`);
414
- });
415
- });
416
- });
417
-
418
- test.describe('Prop: `isFooterPinned`', () => {
419
- [true, false].forEach((isFooterPinned) => {
420
- test(`when isFooterPinned is: ${isFooterPinned}`, async ({ mount, page }) => {
421
- await mount(PieModal, {
422
- props: {
423
- heading: 'This is a modal heading',
424
- isOpen: true,
425
- isFooterPinned,
426
- leadingAction: {
427
- text: 'Confirm',
428
- variant: 'primary',
429
- ariaLabel: 'Confirmation text',
430
- },
431
- } as ModalProps,
432
- slots: {
433
- default: `Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus in magni
434
- quis obcaecati laboriosam est vero, perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor
435
- sit amet consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus in magni quis obcaecati laboriosam est vero,
436
- perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor sit amet consectetur adipisicing elit.
437
-
438
- Deleniti fugit id exercitationem repellendus in magni quis obcaecati laboriosam est vero, perspiciatis ratione porro dolore
439
- repudiandae ea numquam! Ipsa, fugiat aut. Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus
440
- in magni quis obcaecati laboriosam est vero, perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor sit amet
441
- consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus in magni quis obcaecati laboriosam est vero, perspiciatis ratione
442
- porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti fugit id
443
- exercitationem repellendus in magni quis obcaecati laboriosam est vero,
444
- perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.
445
-
446
- Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus in magni
447
- quis obcaecati laboriosam est vero, perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor
448
- sit amet consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus in magni quis obcaecati laboriosam est vero,
449
- perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor sit amet consectetur adipisicing elit.
450
-
451
- Deleniti fugit id exercitationem repellendus in magni quis obcaecati laboriosam est vero, perspiciatis ratione porro dolore
452
- repudiandae ea numquam! Ipsa, fugiat aut. Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus
453
- in magni quis obcaecati laboriosam est vero, perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor sit amet
454
- consectetur adipisicing elit. Deleniti fugit id exercitationem repellendus in magni quis obcaecati laboriosam est vero, perspiciatis ratione
455
- porro dolore repudiandae ea numquam! Ipsa, fugiat aut.Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti fugit id
456
- exercitationem repellendus in magni quis obcaecati laboriosam est vero,
457
- perspiciatis ratione porro dolore repudiandae ea numquam! Ipsa, fugiat aut.`,
458
- },
459
- });
460
-
461
- await percySnapshot(page, `Modal isFooterPinned: ${isFooterPinned}`);
462
- });
463
- });
464
- });
465
-
466
- test.describe('Prop: `hasStackedActions`', () => {
467
- test.describe('when true', () => {
468
- (['small', 'medium', 'large'] as Array<ModalProps['size']>)
469
- .forEach((size) => {
470
- test(`should display actions full width (at narrow viewports – with leading action on top) for a modal with size = ${size}`, async ({ page, mount }) => {
471
- await mount(PieModal, {
472
- props: {
473
- heading: 'This is a modal heading',
474
- hasStackedActions: true,
475
- isOpen: true,
476
- size,
477
- leadingAction: {
478
- text: 'Confirm',
479
- variant: 'primary',
480
- ariaLabel: 'Confirmation text',
481
- },
482
- supportingAction: {
483
- text: 'Cancel',
484
- variant: 'ghost',
485
- ariaLabel: 'Cancel and close modal',
486
- },
487
- } as ModalProps,
488
- });
489
-
490
- await percySnapshot(page, `Modal - hasStackedActions = true, size = ${size}`);
491
- });
492
- });
493
- });
494
- });
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;