@@ -7,7 +7,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
77 await page . goto ( '/src/components/modal/test/inline' , config ) ;
88 const ionModalDidPresent = await page . spyOnEvent ( 'ionModalDidPresent' ) ;
99 const ionModalDidDismiss = await page . spyOnEvent ( 'ionModalDidDismiss' ) ;
10- const modal = page . locator ( 'ion-modal' ) ;
10+ const modal = page . locator ( 'ion-modal' ) . first ( ) ;
1111
1212 await page . click ( '#open-inline-modal' ) ;
1313
@@ -22,6 +22,67 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
2222 await expect ( modal ) . toBeHidden ( ) ;
2323 } ) ;
2424
25+ test ( 'it should dismiss child modals when parent modal is dismissed' , async ( { page } ) => {
26+ await page . goto ( '/src/components/modal/test/inline' , config ) ;
27+ const ionModalDidPresent = await page . spyOnEvent ( 'ionModalDidPresent' ) ;
28+ const ionModalDidDismiss = await page . spyOnEvent ( 'ionModalDidDismiss' ) ;
29+
30+ const parentModal = page . locator ( 'ion-modal' ) . first ( ) ;
31+ const childModal = page . locator ( '#child-modal' ) ;
32+
33+ // Open the parent modal
34+ await page . click ( '#open-inline-modal' ) ;
35+ await ionModalDidPresent . next ( ) ;
36+ await expect ( parentModal ) . toBeVisible ( ) ;
37+
38+ // Open the child modal
39+ await page . click ( '#open-child-modal' ) ;
40+ await ionModalDidPresent . next ( ) ;
41+ await expect ( childModal ) . toBeVisible ( ) ;
42+
43+ // Both modals should be visible
44+ await expect ( parentModal ) . toBeVisible ( ) ;
45+ await expect ( childModal ) . toBeVisible ( ) ;
46+
47+ // Dismiss the parent modal
48+ await page . click ( '#dismiss-parent' ) ;
49+
50+ // Wait for both modals to be dismissed
51+ await ionModalDidDismiss . next ( ) ; // child modal dismissed
52+ await ionModalDidDismiss . next ( ) ; // parent modal dismissed
53+
54+ // Both modals should be hidden
55+ await expect ( parentModal ) . toBeHidden ( ) ;
56+ await expect ( childModal ) . toBeHidden ( ) ;
57+ } ) ;
58+
59+ test ( 'it should only dismiss child modal when child dismiss button is clicked' , async ( { page } ) => {
60+ await page . goto ( '/src/components/modal/test/inline' , config ) ;
61+ const ionModalDidPresent = await page . spyOnEvent ( 'ionModalDidPresent' ) ;
62+ const ionModalDidDismiss = await page . spyOnEvent ( 'ionModalDidDismiss' ) ;
63+
64+ const parentModal = page . locator ( 'ion-modal' ) . first ( ) ;
65+ const childModal = page . locator ( '#child-modal' ) ;
66+
67+ // Open the parent modal
68+ await page . click ( '#open-inline-modal' ) ;
69+ await ionModalDidPresent . next ( ) ;
70+ await expect ( parentModal ) . toBeVisible ( ) ;
71+
72+ // Open the child modal
73+ await page . click ( '#open-child-modal' ) ;
74+ await ionModalDidPresent . next ( ) ;
75+ await expect ( childModal ) . toBeVisible ( ) ;
76+
77+ // Dismiss only the child modal
78+ await page . click ( '#dismiss-child' ) ;
79+ await ionModalDidDismiss . next ( ) ;
80+
81+ // Parent modal should still be visible, child modal should be hidden
82+ await expect ( parentModal ) . toBeVisible ( ) ;
83+ await expect ( childModal ) . toBeHidden ( ) ;
84+ } ) ;
85+
2586 test ( 'presenting should create a single root element with the ion-page class' , async ( { page } , testInfo ) => {
2687 testInfo . annotations . push ( {
2788 type : 'issue' ,
0 commit comments