@@ -236,12 +236,56 @@ test.describe('Keyboard Behavior', () => {
236
236
await getTrigger ( ) . press ( 'ArrowDown' ) ;
237
237
await expect ( options [ 1 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
238
238
} ) ;
239
+
240
+ test ( `GIVEN an open hero select
241
+ WHEN the third option is highlighted and the up arrow key is pressed
242
+ THEN the second option should have data-highlighted` , async ( { page } ) => {
243
+ const { getTrigger, getListbox, getOptions } = await setup ( page , 'select-hero-test' ) ;
244
+
245
+ await getTrigger ( ) . focus ( ) ;
246
+ await getTrigger ( ) . press ( 'Enter' ) ;
247
+ // should be open initially
248
+ await expect ( getListbox ( ) ) . toBeVisible ( ) ;
249
+
250
+ // third option highlighted
251
+ const options = await getOptions ( ) ;
252
+ await expect ( options [ 0 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
253
+ await getTrigger ( ) . press ( 'ArrowDown' ) ;
254
+ await getTrigger ( ) . press ( 'ArrowDown' ) ;
255
+
256
+ await getTrigger ( ) . press ( 'ArrowUp' ) ;
257
+ await expect ( options [ 1 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
258
+ } ) ;
259
+
260
+ test ( `GIVEN an open hero select
261
+ WHEN the listbox is closed with a chosen option
262
+ AND the down arrow key is pressed
263
+ THEN the data-highlighted option should not change on re-open` , async ( {
264
+ page,
265
+ } ) => {
266
+ const { getTrigger, getListbox, getOptions } = await setup ( page , 'select-hero-test' ) ;
267
+
268
+ await getTrigger ( ) . focus ( ) ;
269
+ await getTrigger ( ) . press ( 'Enter' ) ;
270
+ // should be open initially
271
+ await expect ( getListbox ( ) ) . toBeVisible ( ) ;
272
+
273
+ // second option highlighted
274
+ const options = await getOptions ( ) ;
275
+ await getTrigger ( ) . press ( 'ArrowDown' ) ;
276
+ await expect ( options [ 1 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
277
+ await getTrigger ( ) . press ( 'Enter' ) ;
278
+ await expect ( getListbox ( ) ) . toBeHidden ( ) ;
279
+
280
+ await getTrigger ( ) . press ( 'ArrowDown' ) ;
281
+ await expect ( options [ 1 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
282
+ } ) ;
239
283
} ) ;
240
284
241
285
test . describe ( 'disabled' , ( ) => {
242
286
test ( `GIVEN an open hero select with the first option disabled
243
287
WHEN clicking the disabled option
244
- It should be disabled` , async ( { page } ) => {
288
+ It should have aria- disabled` , async ( { page } ) => {
245
289
const { getTrigger, getListbox, getOptions } = await setup (
246
290
page ,
247
291
'select-disabled-test' ,
@@ -258,7 +302,26 @@ test.describe('disabled', () => {
258
302
await expect ( options [ 0 ] ) . toBeDisabled ( ) ;
259
303
} ) ;
260
304
261
- test ( `GIVEN an open hero select by the enter key
305
+ test ( `GIVEN an open disable select with the first option disabled
306
+ WHEN clicking the disabled option
307
+ THEN the listbox should stay open` , async ( { page } ) => {
308
+ const { getTrigger, getListbox, getOptions } = await setup (
309
+ page ,
310
+ 'select-disabled-test' ,
311
+ ) ;
312
+
313
+ await getTrigger ( ) . focus ( ) ;
314
+ await getTrigger ( ) . press ( 'Enter' ) ;
315
+ // should be open initially
316
+ await expect ( getListbox ( ) ) . toBeVisible ( ) ;
317
+
318
+ const options = await getOptions ( ) ;
319
+ // eslint-disable-next-line playwright/no-force-option
320
+ await options [ 0 ] . click ( { force : true } ) ;
321
+ await expect ( getListbox ( ) ) . toBeVisible ( ) ;
322
+ } ) ;
323
+
324
+ test ( `GIVEN an open disabled select
262
325
WHEN first option is disabled
263
326
THEN the second option should have data-highlighted` , async ( { page } ) => {
264
327
const { getTrigger, getListbox, getOptions } = await setup (
@@ -273,4 +336,21 @@ test.describe('disabled', () => {
273
336
const options = await getOptions ( ) ;
274
337
await expect ( options [ 1 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
275
338
} ) ;
339
+
340
+ test ( `GIVEN an open disabled select
341
+ WHEN the last option is disabled and the end key is pressed
342
+ THEN the second last index should have data-highlighted` , async ( { page } ) => {
343
+ const { getTrigger, getListbox, getOptions } = await setup (
344
+ page ,
345
+ 'select-disabled-test' ,
346
+ ) ;
347
+
348
+ await getTrigger ( ) . focus ( ) ;
349
+ await getTrigger ( ) . press ( 'ArrowDown' ) ;
350
+ // should be open initially
351
+ await expect ( getListbox ( ) ) . toBeVisible ( ) ;
352
+ await getTrigger ( ) . press ( 'End' ) ;
353
+ const options = await getOptions ( ) ;
354
+ await expect ( options [ options . length - 2 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
355
+ } ) ;
276
356
} ) ;
0 commit comments