@@ -371,38 +371,51 @@ describe('Table.Expand', () => {
371371
372372 // https://github.com/ant-design/ant-design/issues/23894
373373 it ( 'should be collapsible when use `expandIcon` & `expandRowByClick`' , ( ) => {
374- const data = [ { key : 0 , name : 'Lucy' , age : 27 , children : [ { key : 1 , name : 'Jack' , age : 28 } ] } ] ;
374+ const data = [ { key : 0 , name : 'Lucy' , age : 27 } ] ;
375375 const onExpand = jest . fn ( ) ;
376376 const wrapper = mount (
377377 createTable ( {
378378 expandable : {
379379 expandedRowRender,
380380 expandRowByClick : true ,
381- expandIcon : ( { onExpand : onIconExpand } ) => (
382- < span className = "custom-expand-icon" onClick = { onIconExpand } />
383- ) ,
384381 onExpand,
382+ expandIcon : ( { onExpand : onIconExpand , record } ) => (
383+ < span className = "custom-expand-icon" onClick = { ( ) => onIconExpand ( record ) } />
384+ ) ,
385385 } ,
386386 data,
387387 } ) ,
388388 ) ;
389+ expect ( wrapper . find ( '.rc-table-expanded-row' ) . length ) . toBe ( 0 ) ;
389390 wrapper
390391 . find ( '.custom-expand-icon' )
391392 . first ( )
392393 . simulate ( 'click' ) ;
393394 expect ( onExpand ) . toHaveBeenCalledWith ( true , data [ 0 ] ) ;
394395 expect ( onExpand ) . toHaveBeenCalledTimes ( 1 ) ;
396+ expect (
397+ wrapper
398+ . find ( '.rc-table-expanded-row' )
399+ . first ( )
400+ . getDOMNode ( ) . style . display ,
401+ ) . toBe ( '' ) ;
395402 wrapper
396403 . find ( '.custom-expand-icon' )
397404 . first ( )
398405 . simulate ( 'click' ) ;
399406 expect ( onExpand ) . toHaveBeenCalledWith ( false , data [ 0 ] ) ;
400407 expect ( onExpand ) . toHaveBeenCalledTimes ( 2 ) ;
408+ expect (
409+ wrapper
410+ . find ( '.rc-table-expanded-row' )
411+ . first ( )
412+ . getDOMNode ( ) . style . display ,
413+ ) . toBe ( 'none' ) ;
401414 } ) ;
402415
403416 // https://github.com/ant-design/ant-design/issues/23894
404417 it ( 'should be collapsible when `expandRowByClick` without custom `expandIcon`' , ( ) => {
405- const data = [ { key : 0 , name : 'Lucy' , age : 27 , children : [ { key : 1 , name : 'Jack' , age : 28 } ] } ] ;
418+ const data = [ { key : 0 , name : 'Lucy' , age : 27 } ] ;
406419 const onExpand = jest . fn ( ) ;
407420 const wrapper = mount (
408421 createTable ( {
@@ -427,4 +440,57 @@ describe('Table.Expand', () => {
427440 expect ( onExpand ) . toHaveBeenCalledWith ( false , data [ 0 ] ) ;
428441 expect ( onExpand ) . toHaveBeenCalledTimes ( 2 ) ;
429442 } ) ;
443+
444+ it ( 'should be collapsible when `expandRowByClick` with custom `expandIcon` and event.stopPropagation' , ( ) => {
445+ const data = [ { key : 0 , name : 'Lucy' , age : 27 } ] ;
446+ const onExpand = jest . fn ( ) ;
447+ const wrapper = mount (
448+ createTable ( {
449+ expandable : {
450+ expandedRowRender,
451+ expandRowByClick : true ,
452+ onExpand,
453+ expandIcon : ( { onExpand : onIconExpand , record } ) => (
454+ < span
455+ className = "custom-expand-icon"
456+ onClick = { e => {
457+ e . stopPropagation ( ) ;
458+ onIconExpand ( record ) ;
459+ } }
460+ />
461+ ) ,
462+ } ,
463+ data,
464+ } ) ,
465+ ) ;
466+ wrapper
467+ . find ( '.custom-expand-icon' )
468+ . first ( )
469+ . simulate ( 'click' ) ;
470+ expect ( onExpand ) . toHaveBeenCalledWith ( true , data [ 0 ] ) ;
471+ expect ( onExpand ) . toHaveBeenCalledTimes ( 1 ) ;
472+ wrapper
473+ . find ( '.custom-expand-icon' )
474+ . first ( )
475+ . simulate ( 'click' ) ;
476+ expect ( onExpand ) . toHaveBeenCalledWith ( false , data [ 0 ] ) ;
477+ expect ( onExpand ) . toHaveBeenCalledTimes ( 2 ) ;
478+ } ) ;
479+
480+ it ( 'support invalid expandIcon' , ( ) => {
481+ const data = [ { key : 0 , name : 'Lucy' , age : 27 } ] ;
482+ const onExpand = jest . fn ( ) ;
483+ const wrapper = mount (
484+ createTable ( {
485+ expandable : {
486+ expandedRowRender,
487+ expandRowByClick : true ,
488+ onExpand,
489+ expandIcon : ( ) => null ,
490+ } ,
491+ data,
492+ } ) ,
493+ ) ;
494+ expect ( wrapper . find ( '.rc-table-expanded-row' ) . length ) . toBe ( 0 ) ;
495+ } ) ;
430496} ) ;
0 commit comments