@@ -479,4 +479,149 @@ describe('Table.rowSelection', () => {
479479 expect ( wrapper . findAll ( 'thead tr div' ) . at ( 0 ) . text ( ) ) . toBe ( '单选' )
480480 } )
481481 } )
482+
483+ // https://github.com/ant-design/ant-design/issues/11384
484+ it ( 'should keep item even if in filter' , async ( ) => {
485+ const filterColumns = [
486+ {
487+ title : 'Name' ,
488+ dataIndex : 'name' ,
489+ filters : [
490+ {
491+ text : 'Jack' ,
492+ value : 'Jack' ,
493+ } ,
494+ {
495+ text : 'Lucy' ,
496+ value : 'Lucy' ,
497+ } ,
498+ ] ,
499+ filterDropdownVisible : true ,
500+ onFilter : ( value , record ) => record . name . indexOf ( value ) === 0 ,
501+ } ,
502+ ]
503+
504+ const onChange = jest . fn ( )
505+ const rowSelection = {
506+ onChange,
507+ }
508+
509+ const wrapper = mount ( Table , {
510+ propsData : {
511+ columns : filterColumns , dataSource : data , rowSelection : rowSelection ,
512+ } ,
513+ sync : false ,
514+ } )
515+
516+ const dropdownWrapper = mount ( {
517+ render ( ) {
518+ return wrapper . find ( { name : 'Trigger' } ) . vm . getComponent ( )
519+ } ,
520+ } , { sync : false } )
521+
522+ function clickItem ( ) {
523+ wrapper
524+ . findAll ( 'tbody .ant-table-selection-column .ant-checkbox-input' )
525+ . at ( 0 )
526+ . element . checked = true
527+ wrapper
528+ . findAll ( 'tbody .ant-table-selection-column .ant-checkbox-input' )
529+ . at ( 0 )
530+ . trigger ( 'change' )
531+ }
532+
533+ // Check Jack
534+ dropdownWrapper
535+ . findAll ( '.ant-dropdown-menu-item .ant-checkbox-wrapper' )
536+ . at ( 0 )
537+ . trigger ( 'click' )
538+ dropdownWrapper
539+ . find ( '.ant-table-filter-dropdown-btns .ant-table-filter-dropdown-link.confirm' )
540+ . trigger ( 'click' )
541+ await asyncExpect ( ( ) => {
542+ expect ( wrapper . findAll ( 'tbody tr' ) . length ) . toBe ( 1 )
543+ } )
544+ await asyncExpect ( ( ) => {
545+ clickItem ( )
546+ } )
547+ await asyncExpect ( ( ) => {
548+ expect ( onChange . mock . calls [ 0 ] [ 0 ] . length ) . toBe ( 1 )
549+ expect ( onChange . mock . calls [ 0 ] [ 1 ] . length ) . toBe ( 1 )
550+ } )
551+
552+ await asyncExpect ( ( ) => {
553+ dropdownWrapper
554+ . findAll ( '.ant-dropdown-menu-item .ant-checkbox-wrapper' )
555+ . at ( 0 )
556+ . trigger ( 'click' )
557+ } )
558+
559+ await asyncExpect ( ( ) => {
560+ // Check Lucy
561+ dropdownWrapper
562+ . findAll ( '.ant-dropdown-menu-item .ant-checkbox-wrapper' )
563+ . at ( 1 )
564+ . trigger ( 'click' )
565+ } )
566+ await asyncExpect ( ( ) => {
567+ dropdownWrapper
568+ . find ( '.ant-table-filter-dropdown-btns .ant-table-filter-dropdown-link.confirm' )
569+ . trigger ( 'click' )
570+ } )
571+ await asyncExpect ( ( ) => {
572+ expect ( wrapper . findAll ( 'tbody tr' ) . length ) . toBe ( 1 )
573+ } )
574+ await asyncExpect ( ( ) => {
575+ clickItem ( )
576+ } )
577+ await asyncExpect ( ( ) => {
578+ expect ( onChange . mock . calls [ 1 ] [ 0 ] . length ) . toBe ( 2 )
579+ expect ( onChange . mock . calls [ 1 ] [ 1 ] . length ) . toBe ( 2 )
580+ } )
581+ } )
582+
583+ it ( 'render correctly when set childrenColumnName' , async ( ) => {
584+ const newDatas = [
585+ {
586+ key : 1 ,
587+ name : 'Jack' ,
588+ children : [
589+ {
590+ key : 11 ,
591+ name : 'John Brown' ,
592+ } ,
593+ ] ,
594+ } ,
595+ {
596+ key : 2 ,
597+ name : 'Lucy' ,
598+ children : [
599+ {
600+ key : 21 ,
601+ name : 'Lucy Brown' ,
602+ } ,
603+ ] ,
604+ } ,
605+ ]
606+
607+ const wrapper = mount ( Table , {
608+ propsData : {
609+ columns : columns , dataSource : newDatas , rowSelection : { } , childrenColumnName : 'test' ,
610+ } ,
611+ sync : false ,
612+ } )
613+
614+ const checkboxes = wrapper . findAll ( 'input' )
615+ const checkboxAll = wrapper . find ( { name : 'SelectionCheckboxAll' } )
616+
617+ checkboxes . at ( 1 ) . element . checked = true
618+ checkboxes . at ( 1 ) . trigger ( 'change' )
619+ expect ( checkboxAll . vm . $data ) . toEqual ( { indeterminate : true , checked : false } )
620+
621+ checkboxes . at ( 2 ) . element . checked = true
622+ checkboxes . at ( 2 ) . trigger ( 'change' )
623+ await asyncExpect ( ( ) => {
624+ expect ( checkboxAll . vm . $data ) . toEqual ( { indeterminate : false , checked : true } )
625+ } )
626+ } )
482627} )
0 commit comments