@@ -51,17 +51,27 @@ test('values are added when a comma is last character entered', () => {
5151 < InputChips onChange = { onChangeMock } values = { [ ] } placeholder = "type here" />
5252 )
5353 const input = getByPlaceholderText ( 'type here' )
54- // values not yet added if user pastes comma separated list
55- fireEvent . change ( input , { target : { value : 'tag1,tag2' } } )
56- expect ( onChangeMock ) . not . toHaveBeenCalled ( )
5754
58- // if the last character is a comma, values are added
59- fireEvent . change ( input , { target : { value : 'tag1,tag2, ' } } )
55+ // if the last character entered is a comma, values are added
56+ fireEvent . change ( input , { target : { value : 'tag1,' } } )
6057 expect ( onChangeMock ) . toHaveBeenCalledTimes ( 1 )
61- expect ( onChangeMock ) . toHaveBeenCalledWith ( [ 'tag1' , 'tag2' ] )
58+ expect ( onChangeMock ) . toHaveBeenCalledWith ( [ 'tag1' ] )
6259 expect ( input ) . toHaveValue ( '' )
6360} )
6461
62+ test ( 'values are added when pasting' , ( ) => {
63+ const onChangeMock = jest . fn ( )
64+ const { getByPlaceholderText } = renderWithTheme (
65+ < InputChips onChange = { onChangeMock } values = { [ ] } placeholder = "type here" />
66+ )
67+ const input = getByPlaceholderText ( 'type here' )
68+ fireEvent . paste ( input )
69+ // If a paste is detected before the value change
70+ // no need for the last character to be a comma
71+ fireEvent . change ( input , { target : { value : 'tag1, tag2' } } )
72+ expect ( onChangeMock ) . toHaveBeenCalledWith ( [ 'tag1' , 'tag2' ] )
73+ } )
74+
6575test ( 'values are added on blur' , ( ) => {
6676 const onChangeMock = jest . fn ( )
6777 const { getByPlaceholderText } = renderWithTheme (
@@ -151,7 +161,8 @@ test('new values are validated', () => {
151161 expect ( input ) . toHaveValue ( 'tag2' )
152162 expect ( onInvalidMock ) . toHaveBeenCalledWith ( [ 'tag2' ] )
153163
154- fireEvent . change ( input , { target : { value : 'tag1,' } } )
164+ // value should be trimmed before validation
165+ fireEvent . change ( input , { target : { value : ' tag1,' } } )
155166 expect ( onChangeMock ) . toHaveBeenCalledTimes ( 1 )
156167 expect ( onChangeMock ) . toHaveBeenCalledWith ( [ 'tag1' ] )
157168 expect ( input ) . toHaveValue ( '' )
@@ -171,7 +182,8 @@ test('duplicate values are not added', () => {
171182 )
172183 const input = getByPlaceholderText ( 'type here' )
173184
174- fireEvent . change ( input , { target : { value : 'tag1,' } } )
185+ // value should be trimmed before validation
186+ fireEvent . change ( input , { target : { value : ' tag1,' } } )
175187 expect ( onChangeMock ) . toHaveBeenCalledTimes ( 0 )
176188 expect ( onDuplicateMock ) . toHaveBeenCalledWith ( [ 'tag1' ] )
177189 expect ( input ) . toHaveValue ( 'tag1' )
0 commit comments