@@ -271,7 +271,7 @@ describe('vscode-single-select', () => {
271271
272272 //#region keyboard interactions
273273
274- it ( 'the value should be changed when the arrow down key pressed while the dropdown is closed' , async ( ) => {
274+ it ( 'the dropdown should be opened when the arrow down key pressed while the dropdown is closed' , async ( ) => {
275275 const el = ( await fixture ( html `
276276 < vscode-single-select >
277277 < vscode-option selected > Lorem</ vscode-option >
@@ -280,27 +280,15 @@ describe('vscode-single-select', () => {
280280 </ vscode-single-select >
281281 ` ) ) as VscodeSingleSelect ;
282282
283- const spy = sinon . spy ( el , 'dispatchEvent' ) ;
284-
285- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
286- await el . updateComplete ;
283+ el . focus ( ) ;
284+ await sendKeys ( { press : 'ArrowDown' } ) ;
287285
288286 const dropdown = el . shadowRoot ?. querySelector ( '.dropdown' ) ;
289287
290- expect ( dropdown ?. classList . contains ( 'open' ) ) . to . be . false ;
291- expect ( el . value ) . to . eq ( 'Ipsum' ) ;
292- expect ( el . selectedIndex ) . to . eq ( 1 ) ;
293-
294- const dispatchedEvent = spy . args [ 1 ] [ 0 ] as CustomEvent ;
295-
296- expect ( dispatchedEvent . type ) . to . eq ( 'vsc-change' ) ;
297- expect ( dispatchedEvent . detail ) . to . eql ( {
298- selectedIndex : 1 ,
299- value : 'Ipsum' ,
300- } ) ;
288+ expect ( dropdown ?. classList . contains ( 'open' ) ) . to . be . true ;
301289 } ) ;
302290
303- it ( 'the value should be changed when the arrow up key pressed while the dropdown is closed' , async ( ) => {
291+ it ( 'the dropdown should be opened when the arrow up key pressed while the dropdown is closed' , async ( ) => {
304292 const el = ( await fixture ( html `
305293 < vscode-single-select >
306294 < vscode-option > Lorem</ vscode-option >
@@ -309,26 +297,12 @@ describe('vscode-single-select', () => {
309297 </ vscode-single-select >
310298 ` ) ) as VscodeSingleSelect ;
311299
312- const spy = sinon . spy ( el , 'dispatchEvent' ) ;
313-
314- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowUp' } ) ) ;
315- await el . updateComplete ;
300+ el . focus ( ) ;
301+ await sendKeys ( { press : 'ArrowUp' } ) ;
316302
317303 const dropdown = el . shadowRoot ?. querySelector ( '.dropdown' ) ;
318- const text = el . shadowRoot ?. querySelector ( '.text' ) ;
319-
320- expect ( dropdown ?. classList . contains ( 'open' ) ) . to . be . false ;
321- expect ( text ) . lightDom . to . eq ( 'Ipsum' ) ;
322- expect ( el . value ) . to . eq ( 'Ipsum' ) ;
323- expect ( el . selectedIndex ) . to . eq ( 1 ) ;
324-
325- const dispatchedEvent = spy . args [ 1 ] [ 0 ] as CustomEvent ;
326304
327- expect ( dispatchedEvent . type ) . to . eq ( 'vsc-change' ) ;
328- expect ( dispatchedEvent . detail ) . to . eql ( {
329- selectedIndex : 1 ,
330- value : 'Ipsum' ,
331- } ) ;
305+ expect ( dropdown ?. classList . contains ( 'open' ) ) . to . be . true ;
332306 } ) ;
333307
334308 it ( 'dropdown should be opened when "Space" key pressed' , async ( ) => {
@@ -352,13 +326,14 @@ describe('vscode-single-select', () => {
352326 </ vscode-single-select >
353327 ` ) ) as VscodeSingleSelect ;
354328
355- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' } ) ) ;
356- await el . updateComplete ;
329+ el . focus ( ) ;
330+ await sendKeys ( { press : 'Enter' } ) ;
357331
358332 const dropdown = el . shadowRoot ?. querySelector ( '.dropdown' ) ;
333+ const combobox = el . shadowRoot ?. querySelector ( '[role="combobox"]' ) ;
359334
360335 expect ( dropdown ?. classList . contains ( 'open' ) ) . to . be . true ;
361- expect ( el . getAttribute ( 'aria-expanded' ) ) . to . eq ( 'true' ) ;
336+ expect ( combobox ? .getAttribute ( 'aria-expanded' ) ) . to . eq ( 'true' ) ;
362337 } ) ;
363338
364339 it ( 'dropdown should be closed and selected option should be changed when "Enter" key pressed' , async ( ) => {
@@ -373,18 +348,13 @@ describe('vscode-single-select', () => {
373348 const spy = sinon . spy ( ) ;
374349 el . addEventListener ( 'change' , spy ) ;
375350
376- el . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
377- await el . updateComplete ;
378- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
379- await el . updateComplete ;
380- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
381- await el . updateComplete ;
382- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
383- await el . updateComplete ;
384-
385- const text = el . shadowRoot ?. querySelector ( '.text' ) ;
351+ el . focus ( ) ;
352+ await sendKeys ( { press : 'ArrowDown' } ) ;
353+ await sendKeys ( { press : 'ArrowDown' } ) ;
354+ await sendKeys ( { press : 'ArrowDown' } ) ;
355+ await sendKeys ( { press : 'Enter' } ) ;
386356
387- expect ( text ) . lightDom . to . eq ( 'Dolor' ) ;
357+ expect ( el . shadowRoot ?. querySelector ( '. text' ) ) . lightDom . to . eq ( 'Dolor' ) ;
388358 expect ( el . value ) . to . eq ( 'Dolor' ) ;
389359 expect ( el . selectedIndex ) . to . eq ( 2 ) ;
390360 expect ( spy . calledWithMatch ( { type : 'change' } ) ) . to . be . true ;
@@ -508,18 +478,11 @@ describe('vscode-single-select', () => {
508478 < vscode-option > Austria</ vscode-option >
509479 </ vscode-single-select >
510480 ` ) ) as VscodeSingleSelect ;
511- await el . updateComplete ;
512481
513- const input = el . shadowRoot ?. querySelector (
514- '.combobox-input'
515- ) as HTMLInputElement ;
516- input . value = 'au' ;
517- input . dispatchEvent ( new InputEvent ( 'input' ) ) ;
518- await el . updateComplete ;
519-
520- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
521- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
522- await el . updateComplete ;
482+ el . focus ( ) ;
483+ await sendKeys ( { type : 'au' } ) ;
484+ await sendKeys ( { down : 'ArrowDown' } ) ;
485+ await sendKeys ( { down : 'ArrowDown' } ) ;
523486
524487 const options = Array . from (
525488 el . shadowRoot ?. querySelectorAll (
@@ -540,27 +503,14 @@ describe('vscode-single-select', () => {
540503 < vscode-option > Austria</ vscode-option >
541504 </ vscode-single-select >
542505 ` ) ) as VscodeSingleSelect ;
543- await el . updateComplete ;
544-
545- const spy = sinon . spy ( el , 'dispatchEvent' ) ;
546-
547- const input = el . shadowRoot ?. querySelector (
548- '.combobox-input'
549- ) as HTMLInputElement ;
550- input . value = 'au' ;
551- input . dispatchEvent ( new InputEvent ( 'input' ) ) ;
552- await el . updateComplete ;
553506
554- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'ArrowDown' } ) ) ;
555- await el . updateComplete ;
556-
557- el . dispatchEvent ( new KeyboardEvent ( 'keydown' , { key : 'Enter' } ) ) ;
558- await el . updateComplete ;
507+ el . focus ( ) ;
559508
560- const dispatchedChangeEvent = spy . args [ 2 ] [ 0 ] as Event ;
509+ await sendKeys ( { type : 'au' } ) ;
510+ await sendKeys ( { down : 'ArrowDown' } ) ;
511+ await sendKeys ( { down : 'Enter' } ) ;
561512
562513 expect ( el . value ) . to . eq ( 'Antigua and Barbuda' ) ;
563- expect ( dispatchedChangeEvent . type ) . to . eq ( 'change' ) ;
564514 } ) ;
565515
566516 it ( 'select an option with the arrow down key, opens the dropdown with the enter key, scroll to the selected option' , async ( ) => {
0 commit comments