@@ -32,26 +32,20 @@ describe('ExamplePicker', () => {
3232 } )
3333
3434 expect ( wrapper . find ( '[data-testid="example-picker"]' ) . exists ( ) ) . toBe ( true )
35- expect ( wrapper . text ( ) ) . toContain ( 'First Example ' )
35+ expect ( wrapper . text ( ) ) . toContain ( 'Select an example ' )
3636 } )
3737
38- it ( 'generates correct options from examples ' , ( ) => {
38+ it ( 'renders dropdown button with correct text ' , ( ) => {
3939 const wrapper = mount ( ExamplePicker , {
4040 props : {
4141 examples : mockExamples ,
4242 modelValue : '' ,
4343 } ,
4444 } )
4545
46- const combobox = wrapper . findComponent ( { name : 'ScalarCombobox' } )
47- const options = combobox . props ( 'options' )
48-
49- expect ( options ) . toHaveLength ( 3 )
50- expect ( options ) . toEqual ( [
51- { id : 'example-1' , label : 'First Example' } ,
52- { id : 'example-2' , label : 'Second Example' } ,
53- { id : 'example-3' , label : 'example-3' } , // Falls back to key when no summary
54- ] )
46+ const button = wrapper . find ( '[data-testid="example-picker"]' )
47+ expect ( button . exists ( ) ) . toBe ( true )
48+ expect ( button . text ( ) ) . toContain ( 'Select an example' )
5549 } )
5650
5751 it ( 'handles empty examples object' , ( ) => {
@@ -62,10 +56,6 @@ describe('ExamplePicker', () => {
6256 } ,
6357 } )
6458
65- const combobox = wrapper . findComponent ( { name : 'ScalarCombobox' } )
66- const options = combobox . props ( 'options' )
67-
68- expect ( options ) . toHaveLength ( 0 )
6959 expect ( wrapper . text ( ) ) . toContain ( 'Select an example' )
7060 } )
7161
@@ -84,10 +74,8 @@ describe('ExamplePicker', () => {
8474 } ,
8575 } )
8676
87- const combobox = wrapper . findComponent ( { name : 'ScalarCombobox' } )
88- const options = combobox . props ( 'options' )
89-
90- expect ( options ) . toEqual ( [ { id : 'key-only' , label : 'key-only' } ] )
77+ // The button should show "Select an example" when no example is selected
78+ expect ( wrapper . text ( ) ) . toContain ( 'Select an example' )
9179 } )
9280
9381 it ( 'handles null key in getLabel function' , ( ) => {
@@ -110,40 +98,41 @@ describe('ExamplePicker', () => {
11098 } ,
11199 } )
112100
113- // Initially no example selected
114- expect ( wrapper . text ( ) ) . toContain ( 'First Example ' )
101+ // Initially shows "Select an example"
102+ expect ( wrapper . text ( ) ) . toContain ( 'Select an example ' )
115103
116104 // Set a selected example
117105 await wrapper . setProps ( {
118106 examples : mockExamples ,
119107 modelValue : 'example-1' ,
120108 } )
121109
122- // Simulate model update
123- const combobox = wrapper . findComponent ( { name : 'ScalarCombobox' } )
124- await combobox . vm . $emit ( 'update:modelValue' , { id : 'example-2' , label : 'Second Example' } )
125-
126110 await nextTick ( )
127111
128112 // The button should now show the selected example
129- expect ( wrapper . text ( ) ) . toContain ( 'Second Example' )
113+ expect ( wrapper . text ( ) ) . toContain ( 'First Example' )
130114 } )
131115
132- it ( 'emits model update when example is selected' , async ( ) => {
116+ it ( 'updates model value when example is selected' , async ( ) => {
133117 const wrapper = mount ( ExamplePicker , {
134118 props : {
135119 examples : mockExamples ,
136120 modelValue : '' ,
137121 } ,
138122 } )
139123
140- const combobox = wrapper . findComponent ( { name : 'ScalarCombobox' } )
141- const selectedOption = { id : 'example-2' , label : 'Second Example' }
124+ // Initially no example selected
125+ expect ( wrapper . vm . selectedExampleKey ) . toBe ( '' )
126+
127+ // Update the model value directly
128+ await wrapper . setProps ( {
129+ examples : mockExamples ,
130+ modelValue : 'example-2' ,
131+ } )
142132
143- await combobox . vm . $emit ( 'update:modelValue' , selectedOption )
133+ await nextTick ( )
144134
145- // Verify the selectExample method was called with the correct option
146- // This tests the internal logic of the component
135+ // Verify the selectedExampleKey was updated
147136 expect ( wrapper . vm . selectedExampleKey ) . toBe ( 'example-2' )
148137 } )
149138
@@ -170,44 +159,33 @@ describe('ExamplePicker', () => {
170159 } ,
171160 } )
172161
173- const combobox = wrapper . findComponent ( { name : 'ScalarCombobox' } )
174- const options = combobox . props ( 'options' )
175-
176- expect ( options ) . toEqual ( [
177- { id : 'example-with-dashes' , label : 'Dashed Example' } ,
178- { id : 'example_with_underscores' , label : 'Underscore Example' } ,
179- { id : 'example.with.dots' , label : 'Dotted Example' } ,
180- ] )
162+ // Test that getLabel works with special characters
163+ expect ( wrapper . vm . getLabel ( 'example-with-dashes' ) ) . toBe ( 'Dashed Example' )
164+ expect ( wrapper . vm . getLabel ( 'example_with_underscores' ) ) . toBe ( 'Underscore Example' )
165+ expect ( wrapper . vm . getLabel ( 'example.with.dots' ) ) . toBe ( 'Dotted Example' )
181166 } )
182167
183- it ( 'computes selected example correctly ' , ( ) => {
168+ it ( 'shows correct label for selected example' , ( ) => {
184169 const wrapper = mount ( ExamplePicker , {
185170 props : {
186171 examples : mockExamples ,
187- modelValue : '' ,
172+ modelValue : 'example-1 ' ,
188173 } ,
189174 } )
190175
191- const vm = wrapper . vm
192-
193- // Test when an example is selected
194- vm . selectedExampleKey = 'example-1'
195- expect ( vm . selectedExample ) . toEqual ( {
196- id : 'example-1' ,
197- label : 'First Example' ,
198- } )
176+ // Should show the summary when available
177+ expect ( wrapper . text ( ) ) . toContain ( 'First Example' )
199178
200- vm . selectedExampleKey = 'example-2'
201- expect ( vm . selectedExample ) . toEqual ( {
202- id : 'example-2' ,
203- label : 'Second Example' ,
179+ // Test with example that has no summary
180+ const wrapper2 = mount ( ExamplePicker , {
181+ props : {
182+ examples : mockExamples ,
183+ modelValue : 'example-3' ,
184+ } ,
204185 } )
205186
206- vm . selectedExampleKey = 'example-3'
207- expect ( vm . selectedExample ) . toEqual ( {
208- id : 'example-3' ,
209- label : 'example-3' ,
210- } )
187+ // Should fall back to the key when no summary
188+ expect ( wrapper2 . text ( ) ) . toContain ( 'example-3' )
211189 } )
212190
213191 it ( 'handles examples with null or undefined values' , ( ) => {
@@ -223,13 +201,22 @@ describe('ExamplePicker', () => {
223201 } ,
224202 } )
225203
226- const combobox = wrapper . findComponent ( { name : 'ScalarCombobox' } )
227- const options = combobox . props ( 'options' )
204+ // Should handle null/undefined gracefully in getLabel
205+ expect ( wrapper . vm . getLabel ( 'null-example' ) ) . toBe ( 'null-example' )
206+ expect ( wrapper . vm . getLabel ( 'undefined-example' ) ) . toBe ( 'undefined-example' )
207+ } )
208+
209+ it ( 'generates correct labels for all examples' , ( ) => {
210+ const wrapper = mount ( ExamplePicker , {
211+ props : {
212+ examples : mockExamples ,
213+ modelValue : '' ,
214+ } ,
215+ } )
228216
229- // Should handle null/undefined gracefully
230- expect ( options ) . toEqual ( [
231- { id : 'null-example' , label : 'null-example' } ,
232- { id : 'undefined-example' , label : 'undefined-example' } ,
233- ] )
217+ // Test that getLabel generates correct labels for all examples
218+ expect ( wrapper . vm . getLabel ( 'example-1' ) ) . toBe ( 'First Example' )
219+ expect ( wrapper . vm . getLabel ( 'example-2' ) ) . toBe ( 'Second Example' )
220+ expect ( wrapper . vm . getLabel ( 'example-3' ) ) . toBe ( 'example-3' ) // Falls back to key when no summary
234221 } )
235222} )
0 commit comments