@@ -459,6 +459,77 @@ describe('Dropdown Component', () => {
459459      const  headerBottom  =  await  screen . findByTestId ( 'header-bottom-id' ) 
460460      expect ( headerBottom ) . toBeInTheDocument ( ) 
461461    } ) 
462+ 
463+     it ( 'clears search when dropdown is closed and reopened' ,  async ( )  =>  { 
464+       const  customItems  =  [ 
465+         {  id : 'apple' ,  label : 'Apple'  } , 
466+         {  id : 'banana' ,  label : 'Banana'  } , 
467+         {  id : 'orange' ,  label : 'Orange'  } , 
468+       ] 
469+       renderDropdown ( {  props : {  ...defaultProps ,  items : customItems ,  isSearchable : true  }  } ) 
470+       const  button  =  screen . getByText ( 'test-trigger-button' ) 
471+       await  userEvent . click ( button ) 
472+ 
473+       const  searchInput  =  screen . getByRole ( 'textbox' ) 
474+       await  userEvent . type ( searchInput ,  'app' ) 
475+ 
476+       expect ( screen . getByText ( 'Apple' ) ) . toBeInTheDocument ( ) 
477+       expect ( screen . queryByText ( 'Banana' ) ) . not . toBeInTheDocument ( ) 
478+ 
479+       // Close dropdown by clicking on the button again 
480+       await  userEvent . click ( button ) 
481+       await  waitFor ( ( )  =>  expect ( screen . queryByRole ( 'textbox' ) ) . not . toBeInTheDocument ( ) ) 
482+ 
483+       // Reopen dropdown 
484+       await  userEvent . click ( button ) 
485+       const  newSearchInput  =  screen . getByRole ( 'textbox' ) 
486+ 
487+       expect ( newSearchInput ) . toHaveValue ( '' ) 
488+       expect ( screen . getByText ( 'Apple' ) ) . toBeInTheDocument ( ) 
489+       expect ( screen . getByText ( 'Banana' ) ) . toBeInTheDocument ( ) 
490+       expect ( screen . getByText ( 'Orange' ) ) . toBeInTheDocument ( ) 
491+     } ) 
492+ 
493+     it ( 'clears search when dropdown is reopened after item is selected and' ,  async ( )  =>  { 
494+       const  onClick  =  jest . fn ( ) 
495+       const  customItems  =  [ 
496+         {  id : 'apple' ,  label : 'Apple'  } , 
497+         {  id : 'banana' ,  label : 'Banana'  } , 
498+         {  id : 'orange' ,  label : 'Orange'  } , 
499+       ] 
500+       renderDropdown ( { 
501+         props : { 
502+           ...defaultProps , 
503+           items : customItems , 
504+           isSearchable : true , 
505+           onClick, 
506+         } , 
507+       } ) 
508+       const  button  =  screen . getByText ( 'test-trigger-button' ) 
509+       await  userEvent . click ( button ) 
510+ 
511+       const  searchInput  =  screen . getByRole ( 'textbox' ) 
512+       await  userEvent . type ( searchInput ,  'app' ) 
513+ 
514+       expect ( screen . getByText ( 'Apple' ) ) . toBeInTheDocument ( ) 
515+       expect ( screen . queryByText ( 'Banana' ) ) . not . toBeInTheDocument ( ) 
516+ 
517+       const  appleItem  =  screen . getByRole ( 'menuitem' ,  {  name : 'Apple'  } ) 
518+       await  userEvent . click ( appleItem ) 
519+       await  waitFor ( ( )  =>  expect ( onClick ) . toHaveBeenCalled ( ) ) 
520+ 
521+       // Dropdown should close after selection 
522+       await  waitFor ( ( )  =>  expect ( screen . queryByRole ( 'textbox' ) ) . not . toBeInTheDocument ( ) ) 
523+ 
524+       // Reopen dropdown 
525+       await  userEvent . click ( button ) 
526+       const  newSearchInput  =  screen . getByRole ( 'textbox' ) 
527+ 
528+       expect ( newSearchInput ) . toHaveValue ( '' ) 
529+       expect ( screen . getByText ( 'Apple' ) ) . toBeInTheDocument ( ) 
530+       expect ( screen . getByText ( 'Banana' ) ) . toBeInTheDocument ( ) 
531+       expect ( screen . getByText ( 'Orange' ) ) . toBeInTheDocument ( ) 
532+     } ) 
462533  } ) 
463534
464535  describe ( 'with footer' ,  ( )  =>  { 
0 commit comments