@@ -4,7 +4,7 @@ import { Confirm } from './shared/Confirm'
4
4
5
5
describe ( 'end()' , ( ) => {
6
6
describe ( 'inside' , ( ) => {
7
- test ( 'removes target ' , async ( ) => {
7
+ test ( 'removes one ' , async ( ) => {
8
8
const screen = render ( < Confirm . Root /> )
9
9
Confirm . call ( { message : 'foo' } )
10
10
await screen . getByRole ( 'button' , { name : / n o / i } ) . click ( )
@@ -22,9 +22,68 @@ describe('end()', () => {
22
22
)
23
23
await expect . element ( screen . getByRole ( 'dialog' ) ) . not . toBeInTheDocument ( )
24
24
} )
25
+ describe ( 'removes only specific target' , ( ) => {
26
+ test ( 'first one' , async ( ) => {
27
+ const screen = render ( < Confirm . Root /> )
28
+ Confirm . call ( { message : 'first one' } )
29
+ Confirm . call ( { message : 'middle one' } )
30
+ Confirm . call ( { message : 'last one' } )
31
+ await screen
32
+ . getByRole ( 'dialog' , { name : / f i r s t o n e / i } )
33
+ . getByRole ( 'button' , { name : / n o / i } )
34
+ . click ( )
35
+ await expect
36
+ . element ( screen . getByRole ( 'dialog' , { name : / f i r s t o n e / i } ) )
37
+ . not . toBeInTheDocument ( )
38
+ await expect
39
+ . element ( screen . getByRole ( 'dialog' , { name : / m i d d l e o n e / i } ) )
40
+ . toBeInTheDocument ( )
41
+ await expect
42
+ . element ( screen . getByRole ( 'dialog' , { name : / l a s t o n e / i } ) )
43
+ . toBeInTheDocument ( )
44
+ } )
45
+ test ( 'middle one' , async ( ) => {
46
+ const screen = render ( < Confirm . Root /> )
47
+ Confirm . call ( { message : 'first one' } )
48
+ Confirm . call ( { message : 'middle one' } )
49
+ Confirm . call ( { message : 'last one' } )
50
+ await screen
51
+ . getByRole ( 'dialog' , { name : / m i d d l e o n e / i } )
52
+ . getByRole ( 'button' , { name : / n o / i } )
53
+ . click ( )
54
+ await expect
55
+ . element ( screen . getByRole ( 'dialog' , { name : / f i r s t o n e / i } ) )
56
+ . toBeInTheDocument ( )
57
+ await expect
58
+ . element ( screen . getByRole ( 'dialog' , { name : / m i d d l e o n e / i } ) )
59
+ . not . toBeInTheDocument ( )
60
+ await expect
61
+ . element ( screen . getByRole ( 'dialog' , { name : / l a s t o n e / i } ) )
62
+ . toBeInTheDocument ( )
63
+ } )
64
+ test ( 'last one' , async ( ) => {
65
+ const screen = render ( < Confirm . Root /> )
66
+ Confirm . call ( { message : 'first one' } )
67
+ Confirm . call ( { message : 'middle one' } )
68
+ Confirm . call ( { message : 'last one' } )
69
+ await screen
70
+ . getByRole ( 'dialog' , { name : / l a s t o n e / i } )
71
+ . getByRole ( 'button' , { name : / n o / i } )
72
+ . click ( )
73
+ await expect
74
+ . element ( screen . getByRole ( 'dialog' , { name : / f i r s t o n e / i } ) )
75
+ . toBeInTheDocument ( )
76
+ await expect
77
+ . element ( screen . getByRole ( 'dialog' , { name : / m i d d l e o n e / i } ) )
78
+ . toBeInTheDocument ( )
79
+ await expect
80
+ . element ( screen . getByRole ( 'dialog' , { name : / l a s t o n e / i } ) )
81
+ . not . toBeInTheDocument ( )
82
+ } )
83
+ } )
25
84
} )
26
85
describe ( 'outside' , ( ) => {
27
- test ( 'removes target ' , async ( ) => {
86
+ test ( 'removes one ' , async ( ) => {
28
87
const screen = render ( < Confirm . Root /> )
29
88
const promise = Confirm . call ( { message : 'foo' } )
30
89
Confirm . end ( promise , false )
@@ -37,5 +96,55 @@ describe('end()', () => {
37
96
Confirm . end ( false )
38
97
await expect . element ( screen . getByRole ( 'dialog' ) ) . not . toBeInTheDocument ( )
39
98
} )
99
+ describe ( 'removes only specific target' , ( ) => {
100
+ test ( 'first one' , async ( ) => {
101
+ const screen = render ( < Confirm . Root /> )
102
+ const firstPromise = Confirm . call ( { message : 'first one' } )
103
+ Confirm . call ( { message : 'middle one' } )
104
+ Confirm . call ( { message : 'last one' } )
105
+ Confirm . end ( firstPromise , false )
106
+ await expect
107
+ . element ( screen . getByRole ( 'dialog' , { name : / f i r s t o n e / i } ) )
108
+ . not . toBeInTheDocument ( )
109
+ await expect
110
+ . element ( screen . getByRole ( 'dialog' , { name : / m i d d l e o n e / i } ) )
111
+ . toBeInTheDocument ( )
112
+ await expect
113
+ . element ( screen . getByRole ( 'dialog' , { name : / l a s t o n e / i } ) )
114
+ . toBeInTheDocument ( )
115
+ } )
116
+ test ( 'middle one' , async ( ) => {
117
+ const screen = render ( < Confirm . Root /> )
118
+ Confirm . call ( { message : 'first one' } )
119
+ const middlePromise = Confirm . call ( { message : 'middle one' } )
120
+ Confirm . call ( { message : 'last one' } )
121
+ Confirm . end ( middlePromise , false )
122
+ await expect
123
+ . element ( screen . getByRole ( 'dialog' , { name : / f i r s t o n e / i } ) )
124
+ . toBeInTheDocument ( )
125
+ await expect
126
+ . element ( screen . getByRole ( 'dialog' , { name : / m i d d l e o n e / i } ) )
127
+ . not . toBeInTheDocument ( )
128
+ await expect
129
+ . element ( screen . getByRole ( 'dialog' , { name : / l a s t o n e / i } ) )
130
+ . toBeInTheDocument ( )
131
+ } )
132
+ test ( 'last one' , async ( ) => {
133
+ const screen = render ( < Confirm . Root /> )
134
+ Confirm . call ( { message : 'first one' } )
135
+ Confirm . call ( { message : 'middle one' } )
136
+ const lastPromise = Confirm . call ( { message : 'last one' } )
137
+ Confirm . end ( lastPromise , false )
138
+ await expect
139
+ . element ( screen . getByRole ( 'dialog' , { name : / f i r s t o n e / i } ) )
140
+ . toBeInTheDocument ( )
141
+ await expect
142
+ . element ( screen . getByRole ( 'dialog' , { name : / m i d d l e o n e / i } ) )
143
+ . toBeInTheDocument ( )
144
+ await expect
145
+ . element ( screen . getByRole ( 'dialog' , { name : / l a s t o n e / i } ) )
146
+ . not . toBeInTheDocument ( )
147
+ } )
148
+ } )
40
149
} )
41
150
} )
0 commit comments