@@ -236,12 +236,56 @@ test.describe('Keyboard Behavior', () => {
236236 await getTrigger ( ) . press ( 'ArrowDown' ) ;
237237 await expect ( options [ 1 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
238238 } ) ;
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+ } ) ;
239283} ) ;
240284
241285test . describe ( 'disabled' , ( ) => {
242286 test ( `GIVEN an open hero select with the first option disabled
243287 WHEN clicking the disabled option
244- It should be disabled` , async ( { page } ) => {
288+ It should have aria- disabled` , async ( { page } ) => {
245289 const { getTrigger, getListbox, getOptions } = await setup (
246290 page ,
247291 'select-disabled-test' ,
@@ -258,7 +302,26 @@ test.describe('disabled', () => {
258302 await expect ( options [ 0 ] ) . toBeDisabled ( ) ;
259303 } ) ;
260304
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
262325 WHEN first option is disabled
263326 THEN the second option should have data-highlighted` , async ( { page } ) => {
264327 const { getTrigger, getListbox, getOptions } = await setup (
@@ -273,4 +336,21 @@ test.describe('disabled', () => {
273336 const options = await getOptions ( ) ;
274337 await expect ( options [ 1 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
275338 } ) ;
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+ } ) ;
276356} ) ;
0 commit comments