@@ -5,11 +5,6 @@ import NestedTestComponent from "./_NestedTestComponent.svelte";
5
5
import { suppressConsoleLogs } from "$lib/test-utils/suppress-console-logs" ;
6
6
import { render } from "@testing-library/svelte" ;
7
7
import TestRenderer from "$lib/test-utils/TestRenderer.svelte" ;
8
- import Button from "$lib/internal/elements/Button.svelte" ;
9
- import Div from "$lib/internal/elements/Div.svelte" ;
10
- import Form from "$lib/internal/elements/Form.svelte" ;
11
- import P from "$lib/internal/elements/P.svelte" ;
12
- import Input from "$lib/internal/elements/Input.svelte" ;
13
8
import {
14
9
assertActiveElement ,
15
10
assertDialog ,
@@ -62,19 +57,15 @@ describe("Safe guards", () => {
62
57
it (
63
58
"should be possible to render a Dialog without crashing" ,
64
59
suppressConsoleLogs ( async ( ) => {
65
- render ( TestRenderer , {
66
- allProps : [
67
- Dialog ,
68
- { open : false , onClose : console . log } ,
69
- [
70
- [ Button , { } , "Trigger" ] ,
71
- [ DialogOverlay ] ,
72
- [ DialogTitle ] ,
73
- [ P , { } , "Contents" ] ,
74
- [ DialogDescription ] ,
75
- ] ,
76
- ] ,
77
- } ) ;
60
+ render ( svelte `
61
+ <Dialog open={false} on:close={console.log}>
62
+ <button>Trigger</button>
63
+ <DialogOverlay />
64
+ <DialogTitle />
65
+ <p>Contents</p>
66
+ <DialogDescription />
67
+ </Dialog>
68
+ ` )
78
69
79
70
assertDialog ( { state : DialogState . InvisibleUnmounted } ) ;
80
71
} )
@@ -221,16 +212,13 @@ describe("Rendering", () => {
221
212
222
213
it ( 'should be possible to always render the Dialog if we provide it a `static` prop (and disable focus trapping based on `open`)' , ( ) => {
223
214
let focusCounter = jest . fn ( )
224
- render (
225
- TestRenderer , {
226
- allProps : [
227
- [ Button , { } , "Trigger" ] ,
228
- [ Dialog , { open : false , onClose : console . log , static : true } , [
229
- [ P , { } , "Contents" ] ,
230
- [ TestTabSentinel , { onFocus : focusCounter } ]
231
- ] ] ,
232
- ]
233
- } )
215
+ render ( svelte `
216
+ <button>Trigger</button>
217
+ <Dialog open={false} on:close={console.log} static>
218
+ <p>Contents</p>
219
+ <TestTabSentinel onFocus={focusCounter} />
220
+ </Dialog>
221
+ ` )
234
222
235
223
236
224
// Let's verify that the Dialog is already there
@@ -240,14 +228,11 @@ describe("Rendering", () => {
240
228
241
229
it ( 'should be possible to use a different render strategy for the Dialog' , async ( ) => {
242
230
let focusCounter = jest . fn ( )
243
- render (
244
- TestRenderer , {
245
- allProps : [
246
- [ ManagedDialog , { unmount : false , buttonText : "Trigger" , buttonProps : { id : "trigger" } } , [
247
- [ Input , { onFocus : focusCounter } ] ,
248
- ] ] ,
249
- ]
250
- } )
231
+ render ( svelte `
232
+ <ManagedDialog unmount={false} buttonText="Trigger" buttonProps={{ id: "trigger" }}>
233
+ <input on:focus={focusCounter}>
234
+ </ManagedDialog>
235
+ ` )
251
236
252
237
assertDialog ( { state : DialogState . InvisibleHidden } )
253
238
expect ( focusCounter ) . toHaveBeenCalledTimes ( 0 )
@@ -268,17 +253,13 @@ describe("Rendering", () => {
268
253
it (
269
254
'should add a scroll lock to the html tag' ,
270
255
suppressConsoleLogs ( async ( ) => {
271
- render (
272
- TestRenderer , {
273
- allProps : [
274
- [ ManagedDialog , { buttonText : "Trigger" , buttonProps : { id : "trigger" } } , [
275
- [ Input , { id : "a" , type : "text" } ] ,
276
- [ Input , { id : "b" , type : "text" } ] ,
277
- [ Input , { id : "c" , type : "text" } ] ,
278
- ] ] ,
279
- ]
280
- } )
281
-
256
+ render ( svelte `
257
+ <ManagedDialog buttonText="Trigger" buttonProps={{ id: "trigger" }}>
258
+ <input id="a" type="text">
259
+ <input id="b" type="text">
260
+ <input id="c" type="text">
261
+ </ManagedDialog>
262
+ ` )
282
263
283
264
// No overflow yet
284
265
expect ( document . documentElement . style . overflow ) . toBe ( '' )
@@ -455,16 +436,13 @@ describe('Keyboard interactions', () => {
455
436
it (
456
437
'should be possible to close the dialog with Escape, when a field is focused' ,
457
438
suppressConsoleLogs ( async ( ) => {
458
- render (
459
- TestRenderer , {
460
- allProps : [
461
- [ ManagedDialog , { buttonText : "Trigger" , buttonProps : { id : "trigger" } } , [
462
- "Contents" ,
463
- [ Input , { id : "name" } ] ,
464
- [ TestTabSentinel ] ,
465
- ] ] ,
466
- ]
467
- } )
439
+ render ( svelte `
440
+ <ManagedDialog buttonText="Trigger" buttonProps={{ id: "trigger" }}>
441
+ Contents
442
+ <input id="name">
443
+ <TestTabSentinel />
444
+ </ManagedDialog>
445
+ ` )
468
446
469
447
assertDialog ( { state : DialogState . InvisibleUnmounted } )
470
448
@@ -488,16 +466,13 @@ describe('Keyboard interactions', () => {
488
466
it (
489
467
'should not be possible to close the dialog with Escape, when a field is focused but cancels the event' ,
490
468
async ( ) => {
491
- render (
492
- TestRenderer , {
493
- allProps : [
494
- [ ManagedDialog , { buttonText : "Trigger" , buttonProps : { id : "trigger" } } , [
495
- "Contents" ,
496
- [ Input , { id : "name" , onKeydown : ( e : CustomEvent ) => { e . preventDefault ( ) ; e . stopPropagation ( ) ; } } ] ,
497
- [ TestTabSentinel ] ,
498
- ] ] ,
499
- ]
500
- } )
469
+ render ( svelte `
470
+ <ManagedDialog buttonText="Trigger" buttonProps={{ id: "trigger" }}>
471
+ Contents
472
+ <input id="name" on:keydown={(e) => { e.preventDefault(); e.stopPropagation(); } }>
473
+ <TestTabSentinel />
474
+ </ManagedDialog>
475
+ ` )
501
476
502
477
assertDialog ( { state : DialogState . InvisibleUnmounted } )
503
478
@@ -551,18 +526,15 @@ describe('Mouse interactions', () => {
551
526
it (
552
527
'should not close the Dialog when clicking on contents of the DialogOverlay' ,
553
528
suppressConsoleLogs ( async ( ) => {
554
- render (
555
- TestRenderer , {
556
- allProps : [
557
- [ ManagedDialog , { buttonText : "Trigger" , buttonProps : { id : "trigger" } } , [
558
- [ DialogOverlay , { } , [
559
- [ Button , { } , "hi" ]
560
- ] ] ,
561
- "Contents" ,
562
- [ TestTabSentinel ] ,
563
- ] ] ,
564
- ]
565
- } )
529
+ render ( svelte `
530
+ <ManagedDialog buttonText="Trigger" buttonProps={{ id: "trigger" }}>
531
+ <DialogOverlay>
532
+ <button>hi</button>
533
+ </DialogOverlay>
534
+ Contents
535
+ <TestTabSentinel />
536
+ </ManagedDialog>
537
+ ` )
566
538
567
539
// Open dialog
568
540
await click ( document . getElementById ( 'trigger' ) )
@@ -611,16 +583,13 @@ describe('Mouse interactions', () => {
611
583
it (
612
584
'should be possible to close the dialog, and keep focus on the focusable element' ,
613
585
suppressConsoleLogs ( async ( ) => {
614
- render (
615
- TestRenderer , {
616
- allProps : [
617
- [ Button , { } , "Hello" ] ,
618
- [ ManagedDialog , { buttonText : "Trigger" , buttonProps : { id : "trigger" } } , [
619
- "Contents" ,
620
- [ TestTabSentinel ] ,
621
- ] ] ,
622
- ]
623
- } )
586
+ render ( svelte `
587
+ <button>Hello</button>
588
+ <ManagedDialog buttonText="Trigger" buttonProps={{ id: "trigger" }}>
589
+ Contents
590
+ <TestTabSentinel />
591
+ </ManagedDialog>
592
+ ` )
624
593
625
594
// Open dialog
626
595
await click ( getByText ( 'Trigger' ) )
@@ -643,18 +612,15 @@ describe('Mouse interactions', () => {
643
612
'should stop propagating click events when clicking on the DialogOverlay' ,
644
613
suppressConsoleLogs ( async ( ) => {
645
614
let wrapperFn = jest . fn ( )
646
- render (
647
- TestRenderer , {
648
- allProps : [
649
- [ Div , { onClick : wrapperFn } , [
650
- [ ManagedDialog , { initialOpen : true } , [
651
- "Contents" ,
652
- [ DialogOverlay ] ,
653
- [ TestTabSentinel ] ,
654
- ] ] ,
655
- ] ]
656
- ]
657
- } )
615
+ render ( svelte `
616
+ <div on:click={wrapperFn}>
617
+ <ManagedDialog initialOpen={true}>
618
+ Contents
619
+ <DialogOverlay />
620
+ <TestTabSentinel />
621
+ </ManagedDialog>
622
+ </div>
623
+ ` )
658
624
659
625
// Verify it is open
660
626
assertDialog ( { state : DialogState . Visible } )
@@ -677,18 +643,15 @@ describe('Mouse interactions', () => {
677
643
'should be possible to submit a form inside a Dialog' ,
678
644
suppressConsoleLogs ( async ( ) => {
679
645
let submitFn = jest . fn ( )
680
- render (
681
- TestRenderer , {
682
- allProps : [
683
- [ ManagedDialog , { initialOpen : true } , [
684
- [ Form , { onSubmit : submitFn } , [
685
- [ Input , { type : "hidden" , value : "abc" } ] ,
686
- [ Button , { type : "submit" } , "Submit" ]
687
- ] ] ,
688
- [ TestTabSentinel ] ,
689
- ] ] ,
690
- ]
691
- } )
646
+ render ( svelte `
647
+ <ManagedDialog initialOpen={true}>
648
+ <form on:submit={submitFn}>
649
+ <input type="hidden" value="abc">
650
+ <button type="submit">Submit</button>
651
+ </form>
652
+ <TestTabSentinel />
653
+ </ManagedDialog>
654
+ ` )
692
655
693
656
// Verify it is open
694
657
assertDialog ( { state : DialogState . Visible } )
@@ -705,17 +668,14 @@ describe('Mouse interactions', () => {
705
668
'should stop propagating click events when clicking on an element inside the Dialog' ,
706
669
suppressConsoleLogs ( async ( ) => {
707
670
let wrapperFn = jest . fn ( )
708
- render (
709
- TestRenderer , {
710
- allProps : [
711
- [ Div , { onClick : wrapperFn } , [
712
- [ ManagedDialog , { initialOpen : true , buttonInside : true , buttonText : "Inside" } , [
713
- "Contents" ,
714
- [ TestTabSentinel ] ,
715
- ] ] ,
716
- ] ]
717
- ]
718
- } )
671
+ render ( svelte `
672
+ <div on:click={wrapperFn}>
673
+ <ManagedDialog initialOpen={true} buttonInside={true} buttonText="Inside">
674
+ Contents
675
+ <TestTabSentinel />
676
+ </ManagedDialog>
677
+ </div>
678
+ ` )
719
679
720
680
// Verify it is open
721
681
assertDialog ( { state : DialogState . Visible } )
0 commit comments