@@ -37,61 +37,45 @@ test.describe('Mouse Behavior', () => {
37
37
THEN the popover should close` , async ( { page } ) => {
38
38
const { driver : d } = await setup ( page , 'basic' ) ;
39
39
40
- await expect ( d . getPopover ( ) ) . toBeHidden ( ) ;
41
- await d . getTrigger ( ) . click ( ) ;
42
-
43
- await expect ( d . getPopover ( ) ) . toBeVisible ( ) ;
40
+ await d . openPopover ( 'click' ) ;
44
41
45
42
await page . mouse . click ( 0 , 0 ) ;
46
43
47
44
await expect ( d . getPopover ( ) ) . toBeHidden ( ) ;
48
45
} ) ;
49
46
50
- test ( `GIVEN an open popover
51
- WHEN clicking the first trigger on the page and then clicking the second trigger
52
- THEN the first popover should close and the second one appear` , async ( { page } ) => {
47
+ test ( `GIVEN a pair of popovers in auto mode
48
+ WHEN clicking the first trigger
49
+ AND clicking the second trigger
50
+ THEN the first popover should close and the second one appear` , async ( {
51
+ page,
52
+ } ) => {
53
53
const { driver : d } = await setup ( page , 'auto' ) ;
54
54
55
55
const firstPopover = d . getPopover ( ) . nth ( 0 ) ;
56
56
const secondPopover = d . getPopover ( ) . nth ( 1 ) ;
57
- const firstTrigger = d . getTrigger ( ) . nth ( 0 ) ;
58
- const secondTrigger = d . getTrigger ( ) . nth ( 1 ) ;
59
57
60
- await expect ( firstPopover ) . toBeHidden ( ) ;
61
- await expect ( secondPopover ) . toBeHidden ( ) ;
62
-
63
- await firstTrigger . click ( { position : { x : 1 , y : 1 } } ) ;
64
- await expect ( firstPopover ) . toBeVisible ( ) ;
65
-
66
- await secondTrigger . click ( { position : { x : 1 , y : 1 } } ) ;
67
- await expect ( secondPopover ) . toBeVisible ( ) ;
58
+ await d . openPopover ( 'click' , 0 ) ;
59
+ await d . openPopover ( 'click' , 1 ) ;
68
60
69
61
await expect ( firstPopover ) . toBeHidden ( ) ;
62
+ await expect ( secondPopover ) . toBeVisible ( ) ;
70
63
} ) ;
71
64
72
65
test ( `GIVEN a pair of manual popovers
73
- WHEN clicking the first trigger on the page and then clicking the second trigger
74
- THEN then both popovers should be opened` , async ( { page } ) => {
66
+ WHEN clicking the first trigger on the page
67
+ AND then clicking the second trigger
68
+ THEN then both popovers should be opened` , async ( { page } ) => {
75
69
const { driver : d } = await setup ( page , 'manual' ) ;
76
70
77
- const firstPopover = d . getPopover ( ) . nth ( 0 ) ;
78
- const secondPopover = d . getPopover ( ) . nth ( 1 ) ;
79
- const firstTrigger = d . getTrigger ( ) . nth ( 0 ) ;
80
- const secondTrigger = d . getTrigger ( ) . nth ( 1 ) ;
81
-
82
- await expect ( firstPopover ) . toBeHidden ( ) ;
83
- await expect ( secondPopover ) . toBeHidden ( ) ;
84
-
85
- await firstTrigger . click ( { position : { x : 1 , y : 1 } } ) ;
86
- await secondTrigger . click ( { position : { x : 1 , y : 1 } } ) ;
87
-
88
- await expect ( firstPopover ) . toBeVisible ( ) ;
89
- await expect ( secondPopover ) . toBeVisible ( ) ;
71
+ await d . openPopover ( 'click' , 0 ) ;
72
+ await d . openPopover ( 'click' , 1 ) ;
90
73
} ) ;
91
74
92
75
test ( `GIVEN a pair of manual opened popovers
93
- WHEN clicking the first trigger on the page and then clicking the second trigger
94
- THEN then both popovers should be closed` , async ( { page } ) => {
76
+ WHEN clicking the first trigger on the page
77
+ AND clicking the second trigger
78
+ THEN both popovers should be closed` , async ( { page } ) => {
95
79
const { driver : d } = await setup ( page , 'manual' ) ;
96
80
97
81
const firstPopover = d . getPopover ( ) . nth ( 0 ) ;
@@ -102,9 +86,8 @@ test.describe('Mouse Behavior', () => {
102
86
await d . openPopover ( 'click' , 0 ) ;
103
87
await d . openPopover ( 'click' , 1 ) ;
104
88
105
- // Need to be explicit about where we're clicking. By default
106
- // the click action tries to click the center of the element
107
- // but in this case, the popover is covering it.
89
+ // Explicitly specifying click positions due to default behavior targeting the element's center,
90
+ // which is obscured by the popover in this scenario.
108
91
await firstTrigger . click ( { position : { x : 1 , y : 1 } } ) ;
109
92
await secondTrigger . click ( { position : { x : 1 , y : 1 } } ) ;
110
93
@@ -136,8 +119,8 @@ test.describe('Mouse Behavior', () => {
136
119
} ) ;
137
120
138
121
test ( `GIVEN a popover with a gutter configured
139
- WHEN opening the popover
140
- THEN the popover should be spaced 40px from the popover` , async ( { page } ) => {
122
+ WHEN opening the popover
123
+ THEN the popover should be spaced 40px from the popover` , async ( { page } ) => {
141
124
const { driver : d } = await setup ( page , 'gutter' ) ;
142
125
143
126
const popover = d . getPopover ( ) ;
@@ -210,7 +193,7 @@ test.describe('Keyboard Behavior', () => {
210
193
211
194
test ( `GIVEN an open popover
212
195
WHEN focusing on the button and pressing the 'Escape' key
213
- THEN the popover should close and the trigger be focused` , async ( { page } ) => {
196
+ THEN the popover should close and the trigger focused` , async ( { page } ) => {
214
197
const { driver : d } = await setup ( page , 'basic' ) ;
215
198
216
199
// Open the popover
@@ -241,100 +224,83 @@ test.describe('Keyboard Behavior', () => {
241
224
242
225
await expect ( d . getPopover ( ) ) . toBeVisible ( ) ;
243
226
} ) ;
244
- test ( `GIVEN an open auto popover
245
- WHEN the first trigger opens
246
- AND the focus changes to the second popover
247
- THEN the first popover should close and the second one appear` , async ( {
248
- page,
249
- } ) => {
250
- const { driver : d } = await setup ( page , 'auto' ) ;
251
227
252
- const firstPopover = d . getPopover ( ) . nth ( 0 ) ;
253
- const secondPopover = d . getPopover ( ) . nth ( 1 ) ;
254
- const firstTrigger = d . getTrigger ( ) . nth ( 0 ) ;
255
- const secondTrigger = d . getTrigger ( ) . nth ( 1 ) ;
228
+ test . describe ( 'auto' , ( ) => {
229
+ test ( `GIVEN a pair of auto popovers
230
+ WHEN one popover is open with the enter key
231
+ AND another popover is open with the enter key
232
+ THEN the first popover should close and the second one appear` , async ( { page } ) => {
233
+ const { driver : d } = await setup ( page , 'auto' ) ;
256
234
257
- await expect ( firstPopover ) . toBeHidden ( ) ;
258
- await expect ( secondPopover ) . toBeHidden ( ) ;
235
+ const firstPopover = d . getPopover ( ) . nth ( 0 ) ;
236
+ const secondPopover = d . getPopover ( ) . nth ( 1 ) ;
259
237
260
- await d . openPopover ( 'Enter' , 0 ) ;
261
- await firstTrigger . press ( 'Tab' ) ;
238
+ await expect ( firstPopover ) . toBeHidden ( ) ;
239
+ await expect ( secondPopover ) . toBeHidden ( ) ;
262
240
263
- await expect ( secondTrigger ) . toBeFocused ( ) ;
264
- await d . openPopover ( 'Enter' , 1 ) ;
241
+ await d . openPopover ( 'Enter' , 0 ) ;
242
+ await d . openPopover ( 'Enter' , 1 ) ;
265
243
266
- await expect ( firstPopover ) . toBeHidden ( ) ;
267
- } ) ;
268
-
269
- test ( `GIVEN a pair of manual popovers
270
- WHEN clicking the first trigger on the page and then clicking the second trigger
271
- THEN then both popovers should be opened` , async ( { page } ) => {
272
- const { driver : d } = await setup ( page , 'manual' ) ;
273
-
274
- await d . openPopover ( 'click' , 0 ) ;
275
- await d . openPopover ( 'click' , 1 ) ;
244
+ await expect ( firstPopover ) . toBeHidden ( ) ;
245
+ } ) ;
276
246
} ) ;
277
247
278
248
test ( `GIVEN a pair of manual opened popovers
279
- WHEN activating the first trigger on the page and then activating the second trigger
280
- THEN then both popovers should be closed` , async ( { page } ) => {
249
+ WHEN pressing enter on the first trigger on the page
250
+ AND the same on the second trigger
251
+ THEN then both popovers should be closed` , async ( { page } ) => {
281
252
const { driver : d } = await setup ( page , 'manual' ) ;
282
253
283
- const [ firstPopOver , secondPopOver ] = await d . getAllPopovers ( ) ;
284
- const [ firstPopoverTrigger , secondPopoverTrigger ] = await d . getAllTriggers ( ) ;
285
-
286
- // Arrange
287
- await firstPopoverTrigger . press ( 'Enter' ) ;
288
-
289
- await secondPopoverTrigger . press ( 'Enter' ) ;
254
+ const firstPopover = d . getPopover ( ) . nth ( 0 ) ;
255
+ const secondPopover = d . getPopover ( ) . nth ( 1 ) ;
256
+ const firstTrigger = d . getTrigger ( ) . nth ( 0 ) ;
257
+ const secondTrigger = d . getTrigger ( ) . nth ( 1 ) ;
290
258
291
- await expect ( firstPopOver ) . toBeVisible ( ) ;
292
- await expect ( secondPopOver ) . toBeVisible ( ) ;
259
+ await d . openPopover ( 'Enter' , 0 ) ;
260
+ await d . openPopover ( 'Enter' , 1 ) ;
293
261
294
- // Act
295
- await secondPopoverTrigger . press ( 'Enter' ) ;
296
- await expect ( secondPopOver ) . toBeHidden ( ) ;
262
+ await secondTrigger . press ( 'Enter' ) ;
263
+ await expect ( secondPopover ) . toBeHidden ( ) ;
297
264
298
265
// Assert
299
- await firstPopoverTrigger . press ( 'Enter' ) ;
300
- await expect ( firstPopOver ) . toBeHidden ( ) ;
266
+ await firstTrigger . press ( 'Enter' ) ;
267
+ await expect ( firstPopover ) . toBeHidden ( ) ;
301
268
} ) ;
302
269
303
- test ( `GIVEN a programmatic popover
304
- WHEN focusing the button on the page and then typing 'o'
305
- THEN the popover should open` , async ( { page } ) => {
270
+ test ( `GIVEN a popover
271
+ WHEN programmatically toggling the popover
272
+ THEN the popover should open` , async ( { page } ) => {
306
273
const { driver : d } = await setup ( page , 'programmatic' ) ;
307
274
308
275
const popover = d . getPopover ( ) ;
309
- const programmaticButtonTrigger = d . getProgrammaticButtonTrigger ( ) ;
276
+ const programmaticTrigger = page . getByRole ( 'button' ) ;
310
277
311
278
await expect ( popover ) . toBeHidden ( ) ;
312
279
313
- await programmaticButtonTrigger . press ( 'o' ) ;
280
+ await programmaticTrigger . press ( 'o' ) ;
314
281
315
282
await expect ( popover ) . toBeVisible ( ) ;
316
283
} ) ;
317
284
318
- test ( `GIVEN an open programmatic popover
319
- WHEN focusing the button on the page and then typing 'o'
320
- THEN the popover should close` , async ( { page } ) => {
285
+ test ( `GIVEN a popover
286
+ WHEN programmatically toggling the popover
287
+ THEN the popover should close` , async ( { page } ) => {
321
288
const { driver : d } = await setup ( page , 'programmatic' ) ;
322
289
290
+ // initial open
323
291
const popover = d . getPopover ( ) ;
324
- const programmaticButtonTrigger = d . getProgrammaticButtonTrigger ( ) ;
325
-
326
- await programmaticButtonTrigger . press ( 'o' ) ;
327
-
292
+ const programmaticTrigger = page . getByRole ( 'button' ) ;
293
+ await programmaticTrigger . press ( 'o' ) ;
328
294
await expect ( popover ) . toBeVisible ( ) ;
329
295
330
- await programmaticButtonTrigger . press ( 'o' ) ;
296
+ await programmaticTrigger . press ( 'o' ) ;
331
297
332
298
await expect ( popover ) . toBeHidden ( ) ;
333
299
} ) ;
334
300
335
301
test ( `GIVEN a popover with placement set to top
336
- WHEN opening the popover using the keyboard
337
- THEN the popover should appear to the right of the trigger` , async ( { page } ) => {
302
+ WHEN opening the popover using the keyboard
303
+ THEN the popover should appear to the right of the trigger` , async ( { page } ) => {
338
304
const { driver : d } = await setup ( page , 'placement' ) ;
339
305
340
306
const popover = d . getPopover ( ) ;
0 commit comments