@@ -5,6 +5,7 @@ import { VListItem } from '@/components/VList'
55
66// Utilities
77import { commands , generate , render , screen , userEvent } from '@test'
8+ import { getAllByRole } from '@testing-library/vue'
89import { cloneVNode , ref } from 'vue'
910
1011const variants = [ 'underlined' , 'outlined' , 'filled' , 'solo' , 'plain' ] as const
@@ -629,6 +630,55 @@ describe('VSelect', () => {
629630 items . value [ 0 ] . title = 'Bar'
630631 await expect . poll ( ( ) => screen . getByText ( 'Bar' ) ) . toBeVisible ( )
631632 } )
633+
634+ it ( 'adds a selection externally' , async ( ) => {
635+ const items = ref ( [ 'Foo' , 'Bar' ] )
636+ const selection = ref ( [ 'Foo' ] )
637+ const { element } = render ( ( ) => (
638+ < VSelect v-model = { selection . value } items = { items . value } multiple />
639+ ) )
640+
641+ await userEvent . click ( element )
642+ const menu = await screen . findByRole ( 'listbox' )
643+ await expect . element ( menu ) . toBeVisible ( )
644+
645+ selection . value . push ( 'Bar' )
646+ await expect . poll ( ( ) => screen . getAllByText ( 'Bar' ) ) . toHaveLength ( 2 )
647+ expect ( getAllByRole ( menu , 'option' , { selected : true } ) ) . toHaveLength ( 2 )
648+ } )
649+
650+ it ( 'removes a selection externally' , async ( ) => {
651+ const items = ref ( [ 'Foo' , 'Bar' ] )
652+ const selection = ref ( [ 'Foo' , 'Bar' ] )
653+ const { element } = render ( ( ) => (
654+ < VSelect v-model = { selection . value } items = { items . value } multiple />
655+ ) )
656+
657+ await userEvent . click ( element )
658+ const menu = await screen . findByRole ( 'listbox' )
659+ await expect . element ( menu ) . toBeVisible ( )
660+
661+ selection . value . splice ( 1 , 1 )
662+ await expect . poll ( ( ) => screen . getAllByText ( 'Bar' ) ) . toHaveLength ( 1 )
663+ expect ( getAllByRole ( menu , 'option' , { selected : true } ) ) . toHaveLength ( 1 )
664+ } )
665+
666+ it ( 'adds a selected item' , async ( ) => {
667+ const items = ref ( [ 'Foo' ] )
668+ const selection = ref ( [ 'Foo' ] )
669+ const { element } = render ( ( ) => (
670+ < VSelect v-model = { selection . value } items = { items . value } multiple />
671+ ) )
672+
673+ await userEvent . click ( element )
674+ const menu = await screen . findByRole ( 'listbox' )
675+ await expect . element ( menu ) . toBeVisible ( )
676+
677+ items . value . push ( 'Bar' )
678+ selection . value . push ( 'Bar' )
679+ await expect . poll ( ( ) => screen . getAllByText ( 'Bar' ) ) . toHaveLength ( 2 )
680+ expect ( getAllByRole ( menu , 'option' , { selected : true } ) ) . toHaveLength ( 2 )
681+ } )
632682 } )
633683
634684 describe ( 'Showcase' , ( ) => {
0 commit comments