@@ -39,6 +39,24 @@ describe('<Autocomplete />', () => {
3939 document . activeElement . blur ( ) ;
4040 expect ( input . value ) . to . equal ( '' ) ;
4141 } ) ;
42+
43+ it ( 'should apply the hasClearIcon class' , ( ) => {
44+ const { container } = render (
45+ < Autocomplete renderInput = { params => < TextField { ...params } /> } /> ,
46+ ) ;
47+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
48+ classes . hasClearIcon ,
49+ ) ;
50+ } ) ;
51+
52+ it ( 'should apply the hasPopupIcon class' , ( ) => {
53+ const { container } = render (
54+ < Autocomplete renderInput = { params => < TextField { ...params } /> } /> ,
55+ ) ;
56+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
57+ classes . hasPopupIcon ,
58+ ) ;
59+ } ) ;
4260 } ) ;
4361
4462 describe ( 'multiple' , ( ) => {
@@ -547,6 +565,71 @@ describe('<Autocomplete />', () => {
547565 ) ;
548566 expect ( queryByTitle ( 'Clear' ) ) . to . be . null ;
549567 } ) ;
568+
569+ it ( 'should not apply the hasClearIcon class' , ( ) => {
570+ const { container } = render (
571+ < Autocomplete
572+ disabled
573+ options = { [ 'one' , 'two' , 'three' ] }
574+ renderInput = { params => < TextField { ...params } /> }
575+ /> ,
576+ ) ;
577+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . not . to . have . class (
578+ classes . hasClearIcon ,
579+ ) ;
580+ } ) ;
581+
582+ it ( 'should still apply the hasPopupIcon class' , ( ) => {
583+ const { container } = render (
584+ < Autocomplete
585+ disabled
586+ options = { [ 'one' , 'two' , 'three' ] }
587+ renderInput = { params => < TextField { ...params } /> }
588+ /> ,
589+ ) ;
590+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
591+ classes . hasPopupIcon ,
592+ ) ;
593+ } ) ;
594+ } ) ;
595+
596+ describe ( 'prop: disableClearable' , ( ) => {
597+ it ( 'should not render the clear button' , ( ) => {
598+ const { queryByTitle } = render (
599+ < Autocomplete
600+ disableClearable
601+ options = { [ 'one' , 'two' , 'three' ] }
602+ renderInput = { params => < TextField { ...params } /> }
603+ /> ,
604+ ) ;
605+ expect ( queryByTitle ( 'Clear' ) ) . to . be . null ;
606+ } ) ;
607+
608+ it ( 'should still apply the hasPopupIcon class' , ( ) => {
609+ const { container } = render (
610+ < Autocomplete
611+ disableClearable
612+ options = { [ 'one' , 'two' , 'three' ] }
613+ renderInput = { params => < TextField { ...params } /> }
614+ /> ,
615+ ) ;
616+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
617+ classes . hasPopupIcon ,
618+ ) ;
619+ } ) ;
620+
621+ it ( 'should not apply the hasClearIcon class' , ( ) => {
622+ const { container } = render (
623+ < Autocomplete
624+ disableClearable
625+ options = { [ 'one' , 'two' , 'three' ] }
626+ renderInput = { params => < TextField { ...params } /> }
627+ /> ,
628+ ) ;
629+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . not . to . have . class (
630+ classes . hasClearIcon ,
631+ ) ;
632+ } ) ;
550633 } ) ;
551634 } ) ;
552635
@@ -835,6 +918,21 @@ describe('<Autocomplete />', () => {
835918 fireEvent . keyDown ( document . activeElement , { key : 'Enter' } ) ;
836919 expect ( container . querySelectorAll ( '[class*="MuiChip-root"]' ) ) . to . have . length ( 3 ) ;
837920 } ) ;
921+
922+ it ( 'should not apply hasPopupIcon class' , ( ) => {
923+ const handleChange = spy ( ) ;
924+ const options = [ { name : 'foo' } ] ;
925+ const { container } = render (
926+ < Autocomplete
927+ freeSolo
928+ onChange = { handleChange }
929+ options = { options }
930+ getOptionLabel = { option => option . name }
931+ renderInput = { params => < TextField { ...params } autoFocus /> }
932+ /> ,
933+ ) ;
934+ expect ( container ) . not . to . have . class ( classes . hasPopupIcon ) ;
935+ } ) ;
838936 } ) ;
839937
840938 describe ( 'prop: onInputChange' , ( ) => {
0 commit comments