@@ -213,25 +213,74 @@ describe('Select.Combobox', () => {
213
213
} ) ;
214
214
} ) ;
215
215
216
- it ( 'backfill' , ( ) => {
217
- const handleChange = jest . fn ( ) ;
218
- const handleSelect = jest . fn ( ) ;
219
- const wrapper = mount (
220
- < Select mode = "combobox" backfill open onChange = { handleChange } onSelect = { handleSelect } >
221
- < Option value = "One" > One</ Option >
222
- < Option value = "Two" > Two</ Option >
223
- </ Select > ,
224
- ) ;
225
- const input = wrapper . find ( 'input' ) ;
226
- input . simulate ( 'keyDown' , { which : KeyCode . DOWN } ) ;
227
- expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toEqual ( 'One' ) ;
228
- expect ( handleChange ) . not . toHaveBeenCalled ( ) ;
229
- expect ( handleSelect ) . not . toHaveBeenCalled ( ) ;
230
-
231
- input . simulate ( 'keyDown' , { which : KeyCode . ENTER } ) ;
232
- expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toEqual ( 'One' ) ;
233
- expect ( handleChange ) . toHaveBeenCalledWith ( 'One' , expect . objectContaining ( { value : 'One' } ) ) ;
234
- expect ( handleSelect ) . toHaveBeenCalledWith ( 'One' , expect . objectContaining ( { value : 'One' } ) ) ;
216
+ describe ( 'backfill' , ( ) => {
217
+ it ( 'basic' , ( ) => {
218
+ const handleChange = jest . fn ( ) ;
219
+ const handleSelect = jest . fn ( ) ;
220
+ const wrapper = mount (
221
+ < Select mode = "combobox" backfill open onChange = { handleChange } onSelect = { handleSelect } >
222
+ < Option value = "One" > One</ Option >
223
+ < Option value = "Two" > Two</ Option >
224
+ </ Select > ,
225
+ ) ;
226
+ const input = wrapper . find ( 'input' ) ;
227
+ input . simulate ( 'keyDown' , { which : KeyCode . DOWN } ) ;
228
+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toEqual ( 'One' ) ;
229
+ expect ( handleChange ) . not . toHaveBeenCalled ( ) ;
230
+ expect ( handleSelect ) . not . toHaveBeenCalled ( ) ;
231
+
232
+ input . simulate ( 'keyDown' , { which : KeyCode . ENTER } ) ;
233
+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toEqual ( 'One' ) ;
234
+ expect ( handleChange ) . toHaveBeenCalledWith ( 'One' , expect . objectContaining ( { value : 'One' } ) ) ;
235
+ expect ( handleSelect ) . toHaveBeenCalledWith ( 'One' , expect . objectContaining ( { value : 'One' } ) ) ;
236
+ } ) ;
237
+
238
+ // https://github.com/ant-design/ant-design/issues/25345
239
+ it ( 'dynamic options' , ( ) => {
240
+ const onChange = jest . fn ( ) ;
241
+
242
+ const Test = ( ) => {
243
+ const [ options , setOptions ] = React . useState ( [ ] ) ;
244
+ const onSearch = ( value : string ) => {
245
+ let res = [ ] ;
246
+
247
+ if ( ! value || value . indexOf ( '@' ) >= 0 ) {
248
+ res = [ ] ;
249
+ } else {
250
+ const email = `${ value } @gmail.com` ;
251
+ res = [ { value : email , label : email } ] ;
252
+ }
253
+ setOptions ( res ) ;
254
+ } ;
255
+ return (
256
+ < Select
257
+ backfill
258
+ mode = "combobox"
259
+ onChange = { onChange }
260
+ onSearch = { onSearch }
261
+ options = { options }
262
+ />
263
+ ) ;
264
+ } ;
265
+
266
+ const wrapper = mount ( < Test /> ) ;
267
+
268
+ function input ( ) {
269
+ return wrapper . find ( 'input' ) ;
270
+ }
271
+
272
+ input ( ) . simulate ( 'change' , { target : { value : 'light' } } ) ;
273
+ expectOpen ( wrapper ) ;
274
+ expect ( onChange ) . toHaveBeenCalledWith ( 'light' , expect . anything ( ) ) ;
275
+ onChange . mockReset ( ) ;
276
+
277
+ input ( ) . simulate ( 'keyDown' , { which : KeyCode . DOWN } ) ;
278
+ expect ( input ( ) . props ( ) . value ) . toEqual ( '[email protected] ' ) ;
279
+ expect ( onChange ) . not . toHaveBeenCalled ( ) ;
280
+
281
+ input ( ) . simulate ( 'keyDown' , { which : KeyCode . ENTER } ) ;
282
+ expect ( onChange ) . toHaveBeenCalledWith ( '[email protected] ' , expect . anything ( ) ) ;
283
+ } ) ;
235
284
} ) ;
236
285
237
286
it ( "should hide clear icon when value is ''" , ( ) => {
0 commit comments