@@ -140,28 +140,49 @@ describe('Select.Tags', () => {
140
140
expectOpen ( wrapper , false ) ;
141
141
} ) ;
142
142
143
- it ( 'paste content to split' , ( ) => {
144
- const onChange = jest . fn ( ) ;
145
- const wrapper = mount (
146
- < Select mode = "tags" tokenSeparators = { [ ' ' , '\n' ] } onChange = { onChange } >
147
- < Option value = "1" > 1</ Option >
148
- </ Select > ,
149
- ) ;
143
+ // Paste tests
144
+ [
145
+ {
146
+ tokenSeparators : [ ' ' , '\n' ] ,
147
+ clipboardText : '\n light\n bamboo\n ' ,
148
+ inputValue : ' light bamboo ' ,
149
+ } ,
150
+ {
151
+ tokenSeparators : [ '\r\n' ] ,
152
+ clipboardText : '\r\nlight\r\nbamboo\r\n' ,
153
+ inputValue : ' light bamboo ' ,
154
+ } ,
155
+ {
156
+ tokenSeparators : [ ' ' , '\r\n' ] ,
157
+ clipboardText : '\r\n light\r\n bamboo\r\n ' ,
158
+ inputValue : ' light bamboo ' ,
159
+ } ,
160
+ {
161
+ tokenSeparators : [ '\n' ] ,
162
+ clipboardText : '\nlight\nbamboo\n' ,
163
+ inputValue : ' light bamboo ' ,
164
+ } ,
165
+ ] . forEach ( ( { tokenSeparators, clipboardText, inputValue } ) => {
166
+ it ( `paste content to split (${ JSON . stringify ( tokenSeparators ) } )` , ( ) => {
167
+ const onChange = jest . fn ( ) ;
168
+ const wrapper = mount (
169
+ < Select mode = "tags" tokenSeparators = { tokenSeparators } onChange = { onChange } >
170
+ < Option value = "1" > 1</ Option >
171
+ </ Select > ,
172
+ ) ;
150
173
151
- wrapper . find ( 'input' ) . simulate ( 'paste' , {
152
- clipboardData : {
153
- getData : ( ) => `
154
- light
155
- bamboo
156
- ` ,
157
- } ,
174
+ wrapper . find ( 'input' ) . simulate ( 'paste' , {
175
+ clipboardData : {
176
+ getData : ( ) => clipboardText ,
177
+ } ,
178
+ } ) ;
179
+ wrapper . find ( 'input' ) . simulate ( 'change' , {
180
+ target : { value : inputValue } ,
181
+ } ) ;
182
+
183
+ expect ( onChange ) . toHaveBeenCalledWith ( [ 'light' , 'bamboo' ] , expect . anything ( ) ) ;
184
+ expect ( onChange ) . toHaveBeenCalledTimes ( 1 ) ;
158
185
} ) ;
159
- wrapper . find ( 'input' ) . simulate ( 'change' , {
160
- target : { value : ' light bamboo ' } ,
161
- } ) ;
162
-
163
- expect ( onChange ) . toHaveBeenCalledWith ( [ 'light' , 'bamboo' ] , expect . anything ( ) ) ;
164
- expect ( onChange ) . toHaveBeenCalledTimes ( 1 ) ;
165
186
} ) ;
166
187
167
188
it ( 'renders unlisted item in value' , ( ) => {
0 commit comments