@@ -235,6 +235,49 @@ describe("Autocomplete", () => {
235
235
expect ( autocomplete ) . toHaveFocus ( ) ;
236
236
} ) ;
237
237
238
+ it ( "should clear arbitrary value after clicking clear button" , async ( ) => {
239
+ const wrapper = render (
240
+ < Autocomplete aria-label = "Favorite Animal" data-testid = "autocomplete" label = "Favorite Animal" >
241
+ < AutocompleteItem key = "penguin" value = "penguin" >
242
+ Penguin
243
+ </ AutocompleteItem >
244
+ < AutocompleteItem key = "zebra" value = "zebra" >
245
+ Zebra
246
+ </ AutocompleteItem >
247
+ < AutocompleteItem key = "shark" value = "shark" >
248
+ Shark
249
+ </ AutocompleteItem >
250
+ </ Autocomplete > ,
251
+ ) ;
252
+
253
+ const autocomplete = wrapper . getByTestId ( "autocomplete" ) ;
254
+
255
+ // open the select listbox
256
+ await user . click ( autocomplete ) ;
257
+
258
+ // assert that the autocomplete listbox is open
259
+ expect ( autocomplete ) . toHaveAttribute ( "aria-expanded" , "true" ) ;
260
+
261
+ await user . keyboard ( "pe" ) ;
262
+
263
+ const { container} = wrapper ;
264
+
265
+ const clearButton = container . querySelector (
266
+ "[data-slot='inner-wrapper'] button:nth-of-type(1)" ,
267
+ ) ! ;
268
+
269
+ expect ( clearButton ) . not . toBeNull ( ) ;
270
+
271
+ // click the clear button
272
+ await user . click ( clearButton ) ;
273
+
274
+ // assert that the input has empty value
275
+ expect ( autocomplete ) . toHaveValue ( "" ) ;
276
+
277
+ // assert that input is focused
278
+ expect ( autocomplete ) . toHaveFocus ( ) ;
279
+ } ) ;
280
+
238
281
it ( "should keep the ListBox open after clicking clear button" , async ( ) => {
239
282
const wrapper = render (
240
283
< Autocomplete aria-label = "Favorite Animal" data-testid = "autocomplete" label = "Favorite Animal" >
0 commit comments