@@ -6,7 +6,12 @@ import Select, { Option, SelectProps } from '../src';
6
6
import focusTest from './shared/focusTest' ;
7
7
import keyDownTest from './shared/keyDownTest' ;
8
8
import openControlledTest from './shared/openControlledTest' ;
9
- import { expectOpen , toggleOpen , selectItem , injectRunAllTimers } from './utils/common' ;
9
+ import {
10
+ expectOpen ,
11
+ toggleOpen ,
12
+ selectItem ,
13
+ injectRunAllTimers ,
14
+ } from './utils/common' ;
10
15
import allowClearTest from './shared/allowClearTest' ;
11
16
import throwOptionValue from './shared/throwOptionValue' ;
12
17
@@ -50,7 +55,9 @@ describe('Select.Combobox', () => {
50
55
) ;
51
56
52
57
expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( '' ) ;
53
- expect ( wrapper . find ( '.rc-select-selection-placeholder' ) . text ( ) ) . toEqual ( 'placeholder' ) ;
58
+ expect ( wrapper . find ( '.rc-select-selection-placeholder' ) . text ( ) ) . toEqual (
59
+ 'placeholder' ,
60
+ ) ;
54
61
wrapper . find ( 'input' ) . simulate ( 'change' , { target : { value : '1' } } ) ;
55
62
expect ( wrapper . find ( '.rc-select-selection-placeholder' ) . length ) . toBeFalsy ( ) ;
56
63
expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( '1' ) ;
@@ -139,7 +146,9 @@ describe('Select.Combobox', () => {
139
146
} ;
140
147
141
148
public render ( ) {
142
- const options = this . state . data . map ( item => < Option key = { item . key } > { item . label } </ Option > ) ;
149
+ const options = this . state . data . map ( item => (
150
+ < Option key = { item . key } > { item . label } </ Option >
151
+ ) ) ;
143
152
return (
144
153
< Select
145
154
mode = "combobox"
@@ -178,7 +187,9 @@ describe('Select.Combobox', () => {
178
187
} ;
179
188
180
189
public render ( ) {
181
- const options = this . state . data . map ( item => < Option key = { item . key } > { item . label } </ Option > ) ;
190
+ const options = this . state . data . map ( item => (
191
+ < Option key = { item . key } > { item . label } </ Option >
192
+ ) ) ;
182
193
return (
183
194
< Select
184
195
mode = "combobox"
@@ -207,7 +218,13 @@ describe('Select.Combobox', () => {
207
218
const handleChange = jest . fn ( ) ;
208
219
const handleSelect = jest . fn ( ) ;
209
220
const wrapper = mount (
210
- < Select mode = "combobox" backfill open onChange = { handleChange } onSelect = { handleSelect } >
221
+ < Select
222
+ mode = "combobox"
223
+ backfill
224
+ open
225
+ onChange = { handleChange }
226
+ onSelect = { handleSelect }
227
+ >
211
228
< Option value = "One" > One</ Option >
212
229
< Option value = "Two" > Two</ Option >
213
230
</ Select > ,
@@ -220,8 +237,14 @@ describe('Select.Combobox', () => {
220
237
221
238
input . simulate ( 'keyDown' , { which : KeyCode . ENTER } ) ;
222
239
expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toEqual ( 'One' ) ;
223
- expect ( handleChange ) . toHaveBeenCalledWith ( 'One' , expect . objectContaining ( { value : 'One' } ) ) ;
224
- expect ( handleSelect ) . toHaveBeenCalledWith ( 'One' , expect . objectContaining ( { value : 'One' } ) ) ;
240
+ expect ( handleChange ) . toHaveBeenCalledWith (
241
+ 'One' ,
242
+ expect . objectContaining ( { value : 'One' } ) ,
243
+ ) ;
244
+ expect ( handleSelect ) . toHaveBeenCalledWith (
245
+ 'One' ,
246
+ expect . objectContaining ( { value : 'One' } ) ,
247
+ ) ;
225
248
} ) ;
226
249
227
250
it ( "should hide clear icon when value is ''" , ( ) => {
@@ -311,7 +334,11 @@ describe('Select.Combobox', () => {
311
334
jest . useFakeTimers ( ) ;
312
335
const onDropdownVisibleChange = jest . fn ( ) ;
313
336
const wrapper = mount (
314
- < Select mode = "combobox" open onDropdownVisibleChange = { onDropdownVisibleChange } >
337
+ < Select
338
+ mode = "combobox"
339
+ open
340
+ onDropdownVisibleChange = { onDropdownVisibleChange }
341
+ >
315
342
< Option value = "One" > One</ Option >
316
343
< Option value = "Two" > Two</ Option >
317
344
</ Select > ,
@@ -324,4 +351,22 @@ describe('Select.Combobox', () => {
324
351
expect ( onDropdownVisibleChange ) . toHaveBeenCalledWith ( false ) ;
325
352
jest . useRealTimers ( ) ;
326
353
} ) ;
354
+
355
+ it ( 'should reset value by control' , ( ) => {
356
+ const onChange = jest . fn ( ) ;
357
+ const wrapper = mount (
358
+ < Select mode = "combobox" value = "" onChange = { onChange } >
359
+ < Option value = "One" > One</ Option >
360
+ < Option value = "Two" > Two</ Option >
361
+ </ Select > ,
362
+ ) ;
363
+
364
+ toggleOpen ( wrapper ) ;
365
+ selectItem ( wrapper ) ;
366
+ expect ( onChange ) . toHaveBeenCalled ( ) ;
367
+ wrapper . update ( ) ;
368
+ expectOpen ( wrapper , false ) ;
369
+
370
+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toEqual ( '' ) ;
371
+ } ) ;
327
372
} ) ;
0 commit comments