@@ -5,6 +5,7 @@ import describeConformance from '@material-ui/core/test-utils/describeConformanc
55import consoleErrorMock from 'test/utils/consoleErrorMock' ;
66import { spy } from 'sinon' ;
77import { createClientRender , fireEvent } from 'test/utils/createClientRender' ;
8+ import { createRender } from '@material-ui/core/test-utils/createRender' ;
89import Autocomplete from './Autocomplete' ;
910import TextField from '@material-ui/core/TextField' ;
1011
@@ -39,6 +40,24 @@ describe('<Autocomplete />', () => {
3940 document . activeElement . blur ( ) ;
4041 expect ( input . value ) . to . equal ( '' ) ;
4142 } ) ;
43+
44+ it ( 'should apply the hasClearIcon class' , ( ) => {
45+ const { container } = render (
46+ < Autocomplete renderInput = { params => < TextField { ...params } /> } /> ,
47+ ) ;
48+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
49+ classes . hasClearIcon ,
50+ ) ;
51+ } ) ;
52+
53+ it ( 'should apply the hasPopupIcon class' , ( ) => {
54+ const { container } = render (
55+ < Autocomplete renderInput = { params => < TextField { ...params } /> } /> ,
56+ ) ;
57+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
58+ classes . hasPopupIcon ,
59+ ) ;
60+ } ) ;
4261 } ) ;
4362
4463 describe ( 'multiple' , ( ) => {
@@ -547,6 +566,71 @@ describe('<Autocomplete />', () => {
547566 ) ;
548567 expect ( queryByTitle ( 'Clear' ) ) . to . be . null ;
549568 } ) ;
569+
570+ it ( 'should not apply the hasClearIcon class' , ( ) => {
571+ const { container } = render (
572+ < Autocomplete
573+ disabled
574+ options = { [ 'one' , 'two' , 'three' ] }
575+ renderInput = { params => < TextField { ...params } /> }
576+ /> ,
577+ ) ;
578+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . not . to . have . class (
579+ classes . hasClearIcon ,
580+ ) ;
581+ } ) ;
582+
583+ it ( 'should still apply the hasPopupIcon class' , ( ) => {
584+ const { container } = render (
585+ < Autocomplete
586+ disabled
587+ options = { [ 'one' , 'two' , 'three' ] }
588+ renderInput = { params => < TextField { ...params } /> }
589+ /> ,
590+ ) ;
591+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
592+ classes . hasPopupIcon ,
593+ ) ;
594+ } ) ;
595+ } ) ;
596+
597+ describe ( 'prop: disableClearable' , ( ) => {
598+ it ( 'should not render the clear button' , ( ) => {
599+ const { queryByTitle } = render (
600+ < Autocomplete
601+ disableClearable
602+ options = { [ 'one' , 'two' , 'three' ] }
603+ renderInput = { params => < TextField { ...params } /> }
604+ /> ,
605+ ) ;
606+ expect ( queryByTitle ( 'Clear' ) ) . to . be . null ;
607+ } ) ;
608+
609+ it ( 'should still apply the hasPopupIcon class' , ( ) => {
610+ const { container } = render (
611+ < Autocomplete
612+ disableClearable
613+ options = { [ 'one' , 'two' , 'three' ] }
614+ renderInput = { params => < TextField { ...params } /> }
615+ /> ,
616+ ) ;
617+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . to . have . class (
618+ classes . hasPopupIcon ,
619+ ) ;
620+ } ) ;
621+
622+ it ( 'should not apply the hasClearIcon class' , ( ) => {
623+ const { container } = render (
624+ < Autocomplete
625+ disableClearable
626+ options = { [ 'one' , 'two' , 'three' ] }
627+ renderInput = { params => < TextField { ...params } /> }
628+ /> ,
629+ ) ;
630+ expect ( container . querySelector ( '[class*="MuiAutocomplete-root"]' ) ) . not . to . have . class (
631+ classes . hasClearIcon ,
632+ ) ;
633+ } ) ;
550634 } ) ;
551635 } ) ;
552636
@@ -835,6 +919,21 @@ describe('<Autocomplete />', () => {
835919 fireEvent . keyDown ( document . activeElement , { key : 'Enter' } ) ;
836920 expect ( container . querySelectorAll ( '[class*="MuiChip-root"]' ) ) . to . have . length ( 3 ) ;
837921 } ) ;
922+
923+ it ( 'should not apply hasPopupIcon class' , ( ) => {
924+ const handleChange = spy ( ) ;
925+ const options = [ { name : 'foo' } ] ;
926+ const { container } = render (
927+ < Autocomplete
928+ freeSolo
929+ onChange = { handleChange }
930+ options = { options }
931+ getOptionLabel = { option => option . name }
932+ renderInput = { params => < TextField { ...params } autoFocus /> }
933+ /> ,
934+ ) ;
935+ expect ( container ) . not . to . have . class ( classes . hasPopupIcon ) ;
936+ } ) ;
838937 } ) ;
839938
840939 describe ( 'prop: onInputChange' , ( ) => {
0 commit comments