5
5
const React = require ( 'react' )
6
6
const ReactDOM = require ( 'react-dom' )
7
7
const TestUtils = require ( 'react-dom/test-utils' )
8
- const keycode = require ( 'keycode' )
9
8
const sinon = require ( 'sinon' )
10
9
const fixture = require ( '../example/countries' )
11
10
const Subject = require ( '../dist-es5/ReactTags' )
@@ -62,7 +61,7 @@ function type (value) {
62
61
63
62
function key ( ) {
64
63
Array . from ( arguments ) . forEach ( ( value ) => {
65
- TestUtils . Simulate . keyDown ( $ ( 'input' ) , { value, keyCode : keycode ( value ) , key : value } )
64
+ TestUtils . Simulate . keyDown ( $ ( 'input' ) , { value, key : value } )
66
65
} )
67
66
}
68
67
@@ -155,13 +154,13 @@ describe('React Tags', () => {
155
154
it ( 'can allow new, non-suggested tags to be added' , ( ) => {
156
155
createInstance ( { allowNew : false } )
157
156
158
- type ( query ) ; key ( 'enter ' )
157
+ type ( query ) ; key ( 'Enter ' )
159
158
160
159
sinon . assert . notCalled ( props . handleAddition )
161
160
162
161
createInstance ( { allowNew : true } )
163
162
164
- type ( query ) ; key ( 'enter ' )
163
+ type ( query ) ; key ( 'Enter ' )
165
164
166
165
sinon . assert . calledOnce ( props . handleAddition )
167
166
sinon . assert . calledWith ( props . handleAddition , { name : query } )
@@ -170,7 +169,7 @@ describe('React Tags', () => {
170
169
it ( 'can add new tags when a delimiter character is entered' , ( ) => {
171
170
createInstance ( { allowNew : true , delimiterChars : [ ',' , ';' ] } )
172
171
173
- type ( 'foo,bar;baz' ) ; key ( 'enter ' )
172
+ type ( 'foo,bar;baz' ) ; key ( 'Enter ' )
174
173
175
174
sinon . assert . calledThrice ( props . handleAddition )
176
175
} )
@@ -258,22 +257,22 @@ describe('React Tags', () => {
258
257
const input = $ ( 'input' )
259
258
const results = $$ ( 'li[role="option"]' )
260
259
261
- key ( 'down ' )
260
+ key ( 'ArrowDown ' )
262
261
263
262
expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toEqual ( results [ 0 ] . id )
264
263
expect ( results [ 0 ] . className ) . toMatch ( / i s - a c t i v e / )
265
264
266
- key ( 'down ' , 'down ' )
265
+ key ( 'ArrowDown ' , 'ArrowDown ' )
267
266
268
267
expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toEqual ( results [ 2 ] . id )
269
268
expect ( results [ 2 ] . className ) . toMatch ( / i s - a c t i v e / )
270
269
271
- key ( 'down ' )
270
+ key ( 'ArrowDown ' )
272
271
273
272
expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toEqual ( results [ 0 ] . id )
274
273
expect ( results [ 0 ] . className ) . toMatch ( / i s - a c t i v e / )
275
274
276
- key ( 'up ' , 'up ' )
275
+ key ( 'ArrowUp ' , 'ArrowUp ' )
277
276
278
277
expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toEqual ( results [ 1 ] . id )
279
278
expect ( results [ 1 ] . className ) . toMatch ( / i s - a c t i v e / )
@@ -290,7 +289,7 @@ describe('React Tags', () => {
290
289
expect ( option . matches ( '[aria-disabled="true"]' ) ) . toBeTruthy ( )
291
290
} )
292
291
293
- key ( 'down ' , 'enter ' )
292
+ key ( 'ArrowDown ' , 'Enter ' )
294
293
295
294
sinon . assert . notCalled ( props . handleAddition )
296
295
} )
@@ -303,23 +302,23 @@ describe('React Tags', () => {
303
302
} )
304
303
305
304
it ( 'triggers addition for the selected suggestion when a delimiter is pressed' , ( ) => {
306
- key ( 'enter ' )
305
+ key ( 'Enter ' )
307
306
308
307
sinon . assert . notCalled ( props . handleAddition )
309
308
310
- type ( query ) ; key ( 'down ' , 'down ' , 'enter ' )
309
+ type ( query ) ; key ( 'ArrowDown ' , 'ArrowDown ' , 'Enter ' )
311
310
312
311
sinon . assert . calledOnce ( props . handleAddition )
313
312
sinon . assert . calledWith ( props . handleAddition , { id : 196 , name : 'United Kingdom' } )
314
313
} )
315
314
316
315
it ( 'triggers addition for an unselected but matching suggestion when a delimiter is pressed' , ( ) => {
317
- type ( 'united kingdom' ) ; key ( 'enter ' )
316
+ type ( 'united kingdom' ) ; key ( 'Enter ' )
318
317
sinon . assert . calledWith ( props . handleAddition , { id : 196 , name : 'United Kingdom' } )
319
318
} )
320
319
321
320
it ( 'clears the input when an addition is triggered' , ( ) => {
322
- type ( query ) ; key ( 'down ' , 'down ' , 'enter ' )
321
+ type ( query ) ; key ( 'ArrowDown ' , 'ArrowDown ' , 'Enter ' )
323
322
324
323
const input = $ ( 'input' )
325
324
@@ -345,14 +344,14 @@ describe('React Tags', () => {
345
344
} )
346
345
347
346
it ( 'deletes the last selected tag when backspace is pressed and query is empty' , ( ) => {
348
- type ( '' ) ; key ( 'backspace ' )
347
+ type ( '' ) ; key ( 'Backspace ' )
349
348
350
349
sinon . assert . calledOnce ( props . handleDelete )
351
350
sinon . assert . calledWith ( props . handleDelete , sinon . match ( instance . props . tags . length - 1 ) )
352
351
} )
353
352
354
353
it ( 'does not delete the last selected tag when backspace is pressed and query is not empty' , ( ) => {
355
- type ( 'uni' ) ; key ( 'backspace ' )
354
+ type ( 'uni' ) ; key ( 'Backspace ' )
356
355
sinon . assert . notCalled ( props . handleDelete )
357
356
} )
358
357
@@ -362,7 +361,7 @@ describe('React Tags', () => {
362
361
allowBackspace : false
363
362
} )
364
363
365
- type ( '' ) ; key ( 'backspace ' )
364
+ type ( '' ) ; key ( 'Backspace ' )
366
365
367
366
sinon . assert . notCalled ( props . handleDelete )
368
367
} )
0 commit comments