@@ -132,9 +132,12 @@ describe('Table.rowSelection', () => {
132
132
// https://github.com/ant-design/ant-design/issues/4020
133
133
it ( 'handles defaultChecked' , async ( ) => {
134
134
const rowSelection = {
135
- getCheckboxProps : record => ( {
136
- defaultChecked : record . key === 0 ,
137
- } ) ,
135
+ getCheckboxProps : record => {
136
+ return {
137
+ props : {
138
+ defaultChecked : record . key === 0 ,
139
+ } }
140
+ } ,
138
141
}
139
142
140
143
const wrapper = mount ( Table , getTableOptions ( { rowSelection } ) )
@@ -145,13 +148,13 @@ describe('Table.rowSelection', () => {
145
148
expect ( checkboxs . at ( 2 ) . vnode . data . domProps . checked ) . toBe ( false )
146
149
checkboxs . at ( 2 ) . element . checked = true
147
150
checkboxs . at ( 2 ) . trigger ( 'change' )
148
- } )
151
+ } , 0 )
149
152
150
153
await asyncExpect ( ( ) => {
151
154
const checkboxs = wrapper . findAll ( 'input' )
152
155
expect ( checkboxs . at ( 1 ) . vnode . data . domProps . checked ) . toBe ( true )
153
156
expect ( checkboxs . at ( 2 ) . vnode . data . domProps . checked ) . toBe ( true )
154
- } )
157
+ } , 1000 )
155
158
} )
156
159
157
160
it ( 'can be controlled' , async ( ) => {
@@ -268,133 +271,146 @@ describe('Table.rowSelection', () => {
268
271
expect ( handleSelectInvert ) . toBeCalledWith ( [ 1 , 2 , 3 ] )
269
272
} )
270
273
271
- // it('fires selection event', () => {
272
- // const handleSelectOdd = jest.fn()
273
- // const handleSelectEven = jest.fn()
274
- // const rowSelection = {
275
- // selections: [{
276
- // key: 'odd',
277
- // text: '奇数项',
278
- // onSelect: handleSelectOdd,
279
- // }, {
280
- // key: 'even',
281
- // text: '偶数项',
282
- // onSelect: handleSelectEven,
283
- // }],
284
- // }
285
- // const wrapper = mount(Table, getTableOptions({ rowSelection }))
286
-
287
- // const dropdownWrapper = mount({
288
- // render () {
289
- // return wrapper.find({ name: 'Trigger' }).vm.getComponent()
290
- // },
291
- // })
292
- // expect(dropdownWrapper.find('.ant-dropdown-menu-item').length).toBe(4)
293
-
294
- // dropdownWrapper.find('.ant-dropdown-menu-item > div').at(2).trigger('click')
295
- // expect(handleSelectOdd).toBeCalledWith([0, 1, 2, 3])
296
-
297
- // dropdownWrapper.find('.ant-dropdown-menu-item > div').at(3).trigger('click')
298
- // expect(handleSelectEven).toBeCalledWith([0, 1, 2, 3])
299
- // })
300
-
301
- // it('could hide default selection options', () => {
302
- // const rowSelection = {
303
- // hideDefaultSelections: true,
304
- // selections: [{
305
- // key: 'odd',
306
- // text: '奇数项',
307
- // }, {
308
- // key: 'even',
309
- // text: '偶数项',
310
- // }],
311
- // }
312
- // const wrapper = mount(Table, getTableOptions({ rowSelection }))
313
- // const dropdownWrapper = mount({
314
- // render () {
315
- // return wrapper.find({ name: 'Trigger' }).vm.getComponent()
316
- // },
317
- // })
318
- // expect(dropdownWrapper.find('.ant-dropdown-menu-item').length).toBe(2)
319
- // })
320
-
321
- // it('handle custom selection onSelect correctly when hide default selection options', () => {
322
- // const handleSelectOdd = jest.fn()
323
- // const handleSelectEven = jest.fn()
324
- // const rowSelection = {
325
- // hideDefaultSelections: true,
326
- // selections: [{
327
- // key: 'odd',
328
- // text: '奇数项',
329
- // onSelect: handleSelectOdd,
330
- // }, {
331
- // key: 'even',
332
- // text: '偶数项',
333
- // onSelect: handleSelectEven,
334
- // }],
335
- // }
336
- // const wrapper = mount(Table, getTableOptions({ rowSelection }))
337
-
338
- // const dropdownWrapper = mount({
339
- // render () {
340
- // return wrapper.find({ name: 'Trigger' }).vm.getComponent()
341
- // },
342
- // })
343
- // expect(dropdownWrapper.find('.ant-dropdown-menu-item').length).toBe(2)
344
-
345
- // dropdownWrapper.find('.ant-dropdown-menu-item > div').at(0).trigger('click')
346
- // expect(handleSelectOdd).toBeCalledWith([0, 1, 2, 3])
347
-
348
- // dropdownWrapper.find('.ant-dropdown-menu-item > div').at(1).trigger('click')
349
- // expect(handleSelectEven).toBeCalledWith([0, 1, 2, 3])
350
- // })
351
-
352
- // // https://github.com/ant-design/ant-design/issues/4245
353
- // it('handles disabled checkbox correctly when dataSource changes', () => {
354
- // const rowSelection = {
355
- // getCheckboxProps: record => ({ disabled: record.disabled }),
356
- // }
357
- // const wrapper = mount(Table, getTableOptions({ rowSelection }))
358
- // const newData = [
359
- // { key: 0, name: 'Jack', disabled: true },
360
- // { key: 1, name: 'Lucy', disabled: true },
361
- // ]
362
- // wrapper.setProps({ dataSource: newData })
363
- // wrapper.find('input').forEach((checkbox) => {
364
- // expect(checkbox.props().disabled).toBe(true)
365
- // })
366
- // })
367
-
368
- // // https://github.com/ant-design/ant-design/issues/4779
369
- // it('should not switch pagination when select record', () => {
370
- // const newData = []
371
- // for (let i = 0; i < 20; i += 1) {
372
- // newData.push({
373
- // key: i.toString(),
374
- // name: i.toString(),
375
- // })
376
- // }
377
- // const wrapper = mount(Table, getTableOptions({
378
- // rowSelection: {},
379
- // dataSource: newData,
380
- // }))
381
- // wrapper.find('Pager').last().trigger('click') // switch to second page
382
- // wrapper.find('input').first().trigger('change', { target: { checked: true }})
383
- // wrapper.update()
384
- // expect(renderedNames(wrapper)).toEqual(['10', '11', '12', '13', '14', '15', '16', '17', '18', '19'])
385
- // })
386
-
387
- // it('highlight selected row', () => {
388
- // const wrapper = mount(Table, getTableOptions())
389
- // wrapper.find('input').at(1).trigger('change', { target: { checked: true }})
390
- // expect(wrapper.find('tbody tr').at(0).hasClass('ant-table-row-selected')).toBe(true)
391
- // })
392
-
393
- // it('fix selection column on the left', () => {
394
- // const wrapper = mount(Table, getTableOptions({
395
- // rowSelection: { fixed: true },
396
- // }))
397
-
398
- // expect(wrapper).toMatchSnapshot()
399
- // })
274
+ it ( 'fires selection event' , ( ) => {
275
+ const handleSelectOdd = jest . fn ( )
276
+ const handleSelectEven = jest . fn ( )
277
+ const rowSelection = {
278
+ selections : [ {
279
+ key : 'odd' ,
280
+ text : '奇数项' ,
281
+ onSelect : handleSelectOdd ,
282
+ } , {
283
+ key : 'even' ,
284
+ text : '偶数项' ,
285
+ onSelect : handleSelectEven ,
286
+ } ] ,
287
+ }
288
+ const wrapper = mount ( Table , getTableOptions ( { rowSelection } ) )
289
+
290
+ const dropdownWrapper = mount ( {
291
+ render ( ) {
292
+ return wrapper . find ( { name : 'Trigger' } ) . vm . getComponent ( )
293
+ } ,
294
+ } , { sync : false } )
295
+ expect ( dropdownWrapper . findAll ( '.ant-dropdown-menu-item' ) . length ) . toBe ( 4 )
296
+
297
+ dropdownWrapper . findAll ( '.ant-dropdown-menu-item > div' ) . at ( 2 ) . trigger ( 'click' )
298
+ expect ( handleSelectOdd ) . toBeCalledWith ( [ 0 , 1 , 2 , 3 ] )
299
+
300
+ dropdownWrapper . findAll ( '.ant-dropdown-menu-item > div' ) . at ( 3 ) . trigger ( 'click' )
301
+ expect ( handleSelectEven ) . toBeCalledWith ( [ 0 , 1 , 2 , 3 ] )
302
+ } )
303
+
304
+ it ( 'could hide default selection options' , ( ) => {
305
+ const rowSelection = {
306
+ hideDefaultSelections : true ,
307
+ selections : [ {
308
+ key : 'odd' ,
309
+ text : '奇数项' ,
310
+ } , {
311
+ key : 'even' ,
312
+ text : '偶数项' ,
313
+ } ] ,
314
+ }
315
+ const wrapper = mount ( Table , getTableOptions ( { rowSelection } ) )
316
+ const dropdownWrapper = mount ( {
317
+ render ( ) {
318
+ return wrapper . find ( { name : 'Trigger' } ) . vm . getComponent ( )
319
+ } ,
320
+ } , { sync : false } )
321
+ expect ( dropdownWrapper . findAll ( '.ant-dropdown-menu-item' ) . length ) . toBe ( 2 )
322
+ } )
323
+
324
+ it ( 'handle custom selection onSelect correctly when hide default selection options' , ( ) => {
325
+ const handleSelectOdd = jest . fn ( )
326
+ const handleSelectEven = jest . fn ( )
327
+ const rowSelection = {
328
+ hideDefaultSelections : true ,
329
+ selections : [ {
330
+ key : 'odd' ,
331
+ text : '奇数项' ,
332
+ onSelect : handleSelectOdd ,
333
+ } , {
334
+ key : 'even' ,
335
+ text : '偶数项' ,
336
+ onSelect : handleSelectEven ,
337
+ } ] ,
338
+ }
339
+ const wrapper = mount ( Table , getTableOptions ( { rowSelection } ) )
340
+
341
+ const dropdownWrapper = mount ( {
342
+ render ( ) {
343
+ return wrapper . find ( { name : 'Trigger' } ) . vm . getComponent ( )
344
+ } ,
345
+ } , { sync : false } )
346
+ expect ( dropdownWrapper . findAll ( '.ant-dropdown-menu-item' ) . length ) . toBe ( 2 )
347
+
348
+ dropdownWrapper . findAll ( '.ant-dropdown-menu-item > div' ) . at ( 0 ) . trigger ( 'click' )
349
+ expect ( handleSelectOdd ) . toBeCalledWith ( [ 0 , 1 , 2 , 3 ] )
350
+
351
+ dropdownWrapper . findAll ( '.ant-dropdown-menu-item > div' ) . at ( 1 ) . trigger ( 'click' )
352
+ expect ( handleSelectEven ) . toBeCalledWith ( [ 0 , 1 , 2 , 3 ] )
353
+ } )
354
+
355
+ // https:// github.com/ant-design/ant-design/issues/4245
356
+ it ( 'handles disabled checkbox correctly when dataSource changes' , async ( ) => {
357
+ const rowSelection = {
358
+ getCheckboxProps : record => {
359
+ return { props : { disabled : record . disabled } }
360
+ } ,
361
+ }
362
+ const wrapper = mount ( Table , getTableOptions ( { rowSelection } ) )
363
+ const newData = [
364
+ { key : 7 , name : 'Jack' , disabled : true } ,
365
+ { key : 8 , name : 'Lucy' , disabled : true } ,
366
+ ]
367
+ await asyncExpect ( ( ) => {
368
+ wrapper . setProps ( { dataSource : newData } )
369
+ } )
370
+ await asyncExpect ( ( ) => {
371
+ wrapper . findAll ( 'input' ) . wrappers . forEach ( ( checkbox ) => {
372
+ expect ( checkbox . vnode . data . attrs . disabled ) . toBe ( true )
373
+ } )
374
+ } )
375
+ } )
376
+
377
+ // https://github.com/ant-design/ant-design/issues/4779
378
+ it ( 'should not switch pagination when select record' , async ( ) => {
379
+ const newData = [ ]
380
+ for ( let i = 0 ; i < 20 ; i += 1 ) {
381
+ newData . push ( {
382
+ key : i . toString ( ) ,
383
+ name : i . toString ( ) ,
384
+ } )
385
+ }
386
+ const wrapper = mount ( Table , getTableOptions ( {
387
+ rowSelection : { } ,
388
+ dataSource : newData ,
389
+ } ) )
390
+ const pager = wrapper . findAll ( { name : 'Pager' } )
391
+ pager . at ( pager . length - 1 ) . trigger ( 'click' ) // switch to second page
392
+ wrapper . findAll ( 'input' ) . at ( 0 ) . element . checked = true
393
+ wrapper . findAll ( 'input' ) . at ( 0 ) . trigger ( 'change' )
394
+ await asyncExpect ( ( ) => {
395
+ expect ( renderedNames ( wrapper ) ) . toEqual ( [ '10' , '11' , '12' , '13' , '14' , '15' , '16' , '17' , '18' , '19' ] )
396
+ } )
397
+ } )
398
+
399
+ it ( 'highlight selected row' , async ( ) => {
400
+ const wrapper = mount ( Table , getTableOptions ( ) )
401
+ wrapper . findAll ( 'input' ) . at ( 1 ) . element . checked = true
402
+ wrapper . findAll ( 'input' ) . at ( 1 ) . trigger ( 'change' )
403
+ await asyncExpect ( ( ) => {
404
+ expect ( wrapper . findAll ( 'tbody tr' ) . at ( 0 ) . classes ( ) ) . toContain ( 'ant-table-row-selected' )
405
+ } )
406
+ } )
407
+
408
+ it ( 'fix selection column on the left' , async ( ) => {
409
+ const wrapper = mount ( Table , getTableOptions ( {
410
+ rowSelection : { fixed : true } ,
411
+ } ) )
412
+ await asyncExpect ( ( ) => {
413
+ expect ( wrapper . html ( ) ) . toMatchSnapshot ( )
414
+ } )
415
+ } )
400
416
} )
0 commit comments