@@ -182,15 +182,19 @@ describe('behavior', () => {
182
182
} ) ;
183
183
it ( 'should allow user to add multiple unique items from clipboard if submitkeys are present' , async ( ) => {
184
184
const onItemAdd = jest . fn ( ) ;
185
- const props = createTestProps ( { onItemAdded : onItemAdd , submitKeys : [ "," , ";" ] , values : [ "input3" ] } ) ;
185
+ const props = createTestProps ( {
186
+ onItemAdded : onItemAdd ,
187
+ submitKeys : [ ',' , ';' ] ,
188
+ values : [ 'input3' ]
189
+ } ) ;
186
190
const { user, getByRole, queryAllByRole } = renderWithUserInteraction (
187
191
< MultipleValueTextInput { ...props } />
188
192
) ;
189
193
const input = getByRole ( 'textbox' ) ;
190
194
const initialItems = queryAllByRole ( 'listitem' ) ;
191
195
expect ( initialItems . length ) . toBe ( 1 ) ;
192
196
await user . click ( input ) ;
193
- await user . paste ( " input1,input2;input3,input4,,input5,input1;" ) ;
197
+ await user . paste ( ' input1,input2;input3,input4,,input5,input1;' ) ;
194
198
await waitFor ( ( ) => {
195
199
expect ( onItemAdd ) . toHaveBeenCalledTimes ( 4 ) ;
196
200
// const items = queryAllByRole('listitem');
@@ -199,64 +203,87 @@ describe('behavior', () => {
199
203
// expect(items[1]).toHaveTextContent('input2');
200
204
// expect(items[2]).toHaveTextContent('input4');
201
205
// expect(items[3]).toHaveTextContent('input5');
202
- expect ( input ) . toHaveValue ( "" )
206
+ expect ( input ) . toHaveValue ( '' ) ;
203
207
} ) ;
204
208
} ) ;
205
209
it ( 'should allow user to view text from clipboard if submitkeys are not present' , async ( ) => {
206
210
const onItemAdd = jest . fn ( ) ;
207
- const props = createTestProps ( { onItemAdded : onItemAdd , submitKeys : [ "," , ";" ] } ) ;
211
+ const props = createTestProps ( { onItemAdded : onItemAdd , submitKeys : [ ',' , ';' ] } ) ;
208
212
const { user, getByRole, queryAllByRole } = renderWithUserInteraction (
209
213
< MultipleValueTextInput { ...props } />
210
214
) ;
211
215
const input = getByRole ( 'textbox' ) ;
212
216
const initialItems = queryAllByRole ( 'listitem' ) ;
213
217
expect ( initialItems . length ) . toBe ( 0 ) ;
214
218
await user . click ( input ) ;
215
- await user . paste ( " john doe" ) ;
219
+ await user . paste ( ' john doe' ) ;
216
220
await waitFor ( ( ) => {
217
221
expect ( onItemAdd ) . toHaveBeenCalledTimes ( 0 ) ;
218
222
const items = queryAllByRole ( 'listitem' ) ;
219
223
expect ( items ) . toHaveLength ( 0 ) ;
220
- expect ( input ) . toHaveValue ( " john doe" )
224
+ expect ( input ) . toHaveValue ( ' john doe' ) ;
221
225
} ) ;
222
226
} ) ;
223
227
it ( 'should ignore non-character submit keys from being recognized as delimiters in copied text' , async ( ) => {
224
228
const onItemAdd = jest . fn ( ) ;
225
- const props = createTestProps ( { onItemAdded : onItemAdd , submitKeys : [ "," , "Enter" , "Tab" ] } ) ;
229
+ const props = createTestProps ( {
230
+ onItemAdded : onItemAdd ,
231
+ submitKeys : [ ',' , 'Enter' , 'Tab' ]
232
+ } ) ;
226
233
const { user, getByRole, queryAllByRole } = renderWithUserInteraction (
227
234
< MultipleValueTextInput { ...props } />
228
235
) ;
229
236
const input = getByRole ( 'textbox' ) ;
230
237
const initialItems = queryAllByRole ( 'listitem' ) ;
231
238
expect ( initialItems . length ) . toBe ( 0 ) ;
232
239
await user . click ( input ) ;
233
- await user . paste ( " My Tablet is about to Enter the door" ) ;
240
+ await user . paste ( ' My Tablet is about to Enter the door' ) ;
234
241
await waitFor ( ( ) => {
235
242
expect ( onItemAdd ) . toHaveBeenCalledTimes ( 0 ) ;
236
243
const items = queryAllByRole ( 'listitem' ) ;
237
244
expect ( items ) . toHaveLength ( 0 ) ;
238
- expect ( input ) . toHaveValue ( " My Tablet is about to Enter the door" )
245
+ expect ( input ) . toHaveValue ( ' My Tablet is about to Enter the door' ) ;
239
246
} ) ;
240
247
} ) ;
241
248
it ( 'should selectively ignore non-character submit keys from being recognized as delimiters in copied text' , async ( ) => {
242
249
const onItemAdd = jest . fn ( ) ;
243
- const props = createTestProps ( { onItemAdded : onItemAdd , submitKeys : [ "," , "Enter" , "Tab" ] } ) ;
250
+ const props = createTestProps ( {
251
+ onItemAdded : onItemAdd ,
252
+ submitKeys : [ ',' , 'Enter' , 'Tab' ]
253
+ } ) ;
244
254
const { user, getByRole, queryAllByRole } = renderWithUserInteraction (
245
255
< MultipleValueTextInput { ...props } />
246
256
) ;
247
257
const input = getByRole ( 'textbox' ) ;
248
258
const initialItems = queryAllByRole ( 'listitem' ) ;
249
259
expect ( initialItems . length ) . toBe ( 0 ) ;
250
260
await user . click ( input ) ;
251
- await user . paste ( " My Tablet is about to Enter the door, value1, value2" ) ;
261
+ await user . paste ( ' My Tablet is about to Enter the door, value1, value2' ) ;
252
262
await waitFor ( ( ) => {
253
263
expect ( onItemAdd ) . toHaveBeenCalledTimes ( 3 ) ;
254
264
const items = queryAllByRole ( 'listitem' ) ;
255
265
expect ( items ) . toHaveLength ( 3 ) ;
256
266
expect ( items [ 0 ] ) . toHaveTextContent ( 'My Tablet is about to Enter the door' ) ;
257
267
expect ( items [ 1 ] ) . toHaveTextContent ( 'value1' ) ;
258
268
expect ( items [ 2 ] ) . toHaveTextContent ( 'value2' ) ;
259
- expect ( input ) . toHaveValue ( "" )
269
+ expect ( input ) . toHaveValue ( '' ) ;
270
+ } ) ;
271
+ } ) ;
272
+ it ( 'should dynamically update values from an external prop if provided' , async ( ) => {
273
+ const props = createTestProps ( ) ;
274
+ const { rerender, queryAllByRole } = renderWithUserInteraction (
275
+ < MultipleValueTextInput { ...props } />
276
+ ) ;
277
+ const initialItems = queryAllByRole ( 'listitem' ) ;
278
+ expect ( initialItems . length ) . toBe ( 0 ) ;
279
+ const updatedProps = createTestProps ( { values : [ 'test1' , 'test2' , 'test3' ] } ) ;
280
+ rerender ( < MultipleValueTextInput { ...updatedProps } /> ) ;
281
+ await waitFor ( ( ) => {
282
+ const items = queryAllByRole ( 'listitem' ) ;
283
+ expect ( items ) . toHaveLength ( 3 ) ;
284
+ expect ( items [ 0 ] ) . toHaveTextContent ( 'test1' ) ;
285
+ expect ( items [ 1 ] ) . toHaveTextContent ( 'test2' ) ;
286
+ expect ( items [ 2 ] ) . toHaveTextContent ( 'test3' ) ;
260
287
} ) ;
261
288
} ) ;
262
289
} ) ;
0 commit comments