@@ -10,6 +10,23 @@ const defaultOptions = [
1010 { value : 'e' , label : 'Option E' }
1111]
1212
13+ // Helper to count visible tags in the combobox trigger
14+ // Tags have removable buttons with aria-label="Remove"
15+ const getVisibleTagCount = ( ) => {
16+ return screen . queryAllByLabelText ( 'Remove' ) . length
17+ }
18+
19+ // Helper to check if a tag with specific text is visible
20+ const hasVisibleTag = ( label : string ) => {
21+ // Tags are rendered as ATag components with removable buttons
22+ // The tag text appears alongside the Remove button
23+ const removeButtons = screen . queryAllByLabelText ( 'Remove' )
24+ return removeButtons . some ( button => {
25+ const tag = button . closest ( '[class*="a-tag"]' ) || button . parentElement
26+ return tag ?. textContent ?. includes ( label )
27+ } )
28+ }
29+
1330describe ( 'Combobox.vue - Multi-select tag display' , ( ) => {
1431 describe ( 'maxTags prop' , ( ) => {
1532 it ( 'displays all tags when maxTags is undefined' , ( ) => {
@@ -20,11 +37,13 @@ describe('Combobox.vue - Multi-select tag display', () => {
2037 }
2138 } )
2239
23- expect ( screen . getByText ( 'Option A' ) ) . toBeInTheDocument ( )
24- expect ( screen . getByText ( 'Option B' ) ) . toBeInTheDocument ( )
25- expect ( screen . getByText ( 'Option C' ) ) . toBeInTheDocument ( )
26- expect ( screen . getByText ( 'Option D' ) ) . toBeInTheDocument ( )
27- expect ( screen . getByText ( 'Option E' ) ) . toBeInTheDocument ( )
40+ // All 5 tags should be visible (each has a Remove button)
41+ expect ( getVisibleTagCount ( ) ) . toBe ( 5 )
42+ expect ( hasVisibleTag ( 'Option A' ) ) . toBe ( true )
43+ expect ( hasVisibleTag ( 'Option B' ) ) . toBe ( true )
44+ expect ( hasVisibleTag ( 'Option C' ) ) . toBe ( true )
45+ expect ( hasVisibleTag ( 'Option D' ) ) . toBe ( true )
46+ expect ( hasVisibleTag ( 'Option E' ) ) . toBe ( true )
2847 } )
2948
3049 it ( 'limits visible tags to maxTags count' , ( ) => {
@@ -36,11 +55,13 @@ describe('Combobox.vue - Multi-select tag display', () => {
3655 }
3756 } )
3857
39- expect ( screen . getByText ( 'Option A' ) ) . toBeInTheDocument ( )
40- expect ( screen . getByText ( 'Option B' ) ) . toBeInTheDocument ( )
41- expect ( screen . queryByText ( 'Option C' ) ) . not . toBeInTheDocument ( )
42- expect ( screen . queryByText ( 'Option D' ) ) . not . toBeInTheDocument ( )
43- expect ( screen . queryByText ( 'Option E' ) ) . not . toBeInTheDocument ( )
58+ // Only 2 tags should be visible
59+ expect ( getVisibleTagCount ( ) ) . toBe ( 2 )
60+ expect ( hasVisibleTag ( 'Option A' ) ) . toBe ( true )
61+ expect ( hasVisibleTag ( 'Option B' ) ) . toBe ( true )
62+ expect ( hasVisibleTag ( 'Option C' ) ) . toBe ( false )
63+ expect ( hasVisibleTag ( 'Option D' ) ) . toBe ( false )
64+ expect ( hasVisibleTag ( 'Option E' ) ) . toBe ( false )
4465 } )
4566
4667 it ( 'shows collapsed indicator when tags exceed maxTags' , ( ) => {
@@ -76,9 +97,12 @@ describe('Combobox.vue - Multi-select tag display', () => {
7697 }
7798 } )
7899
79- expect ( screen . queryByText ( 'Option A' ) ) . not . toBeInTheDocument ( )
80- expect ( screen . queryByText ( 'Option B' ) ) . not . toBeInTheDocument ( )
81- expect ( screen . queryByText ( 'Option C' ) ) . not . toBeInTheDocument ( )
100+ // With maxTags: 0, no tags should be visible (no Remove buttons)
101+ expect ( getVisibleTagCount ( ) ) . toBe ( 0 )
102+ expect ( hasVisibleTag ( 'Option A' ) ) . toBe ( false )
103+ expect ( hasVisibleTag ( 'Option B' ) ) . toBe ( false )
104+ expect ( hasVisibleTag ( 'Option C' ) ) . toBe ( false )
105+ // The collapsed indicator should be shown
82106 expect ( screen . getByText ( '+3 more' ) ) . toBeInTheDocument ( )
83107 } )
84108 } )
0 commit comments