@@ -933,6 +933,107 @@ describe('NestedFilterGroup', () => {
933933 ) ;
934934 } ) ;
935935
936+ it ( 'should keep a child with selections collapsed after its row unmounts and remounts' , async ( ) => {
937+ const { key } = manyChildFilters [ 0 ] ;
938+ renderWithMantine (
939+ < NestedFilterGroup
940+ { ...defaultNestedProps }
941+ childFilters = { manyChildFilters }
942+ selectedValues = { {
943+ [ key ] : { included : new Set ( [ 'val' ] ) , excluded : new Set ( ) } ,
944+ } }
945+ isDefaultExpanded = { true }
946+ /> ,
947+ ) ;
948+ const childTestId = `nested-filter-group-${ key } ` ;
949+ const child = ( ) => within ( screen . getByTestId ( childTestId ) ) ;
950+ expect ( child ( ) . getByTestId ( 'filter-group-panel' ) ) . toHaveAttribute (
951+ 'aria-hidden' ,
952+ 'false' ,
953+ ) ;
954+
955+ await userEvent . click ( child ( ) . getByTestId ( 'filter-group-control' ) ) ;
956+ expect ( child ( ) . getByTestId ( 'filter-group-panel' ) ) . toHaveAttribute (
957+ 'aria-hidden' ,
958+ 'true' ,
959+ ) ;
960+
961+ const search = screen . getByPlaceholderText ( 'Search keys...' ) ;
962+ await userEvent . type ( search , 'k8s' ) ;
963+ expect ( screen . queryByTestId ( childTestId ) ) . toBeNull ( ) ;
964+ await userEvent . clear ( search ) ;
965+
966+ expect ( child ( ) . getByTestId ( 'filter-group-panel' ) ) . toHaveAttribute (
967+ 'aria-hidden' ,
968+ 'true' ,
969+ ) ;
970+ } ) ;
971+
972+ it ( 'should expand a collapsed child when a filter for it is added elsewhere' , async ( ) => {
973+ const props = {
974+ ...defaultNestedProps ,
975+ childFilters : manyChildFilters ,
976+ isDefaultExpanded : true ,
977+ } ;
978+ const { rerender } = renderWithMantine ( < NestedFilterGroup { ...props } /> ) ;
979+ const { key } = manyChildFilters [ 0 ] ;
980+ const child = ( ) =>
981+ within ( screen . getByTestId ( `nested-filter-group-${ key } ` ) ) ;
982+
983+ await userEvent . click ( child ( ) . getByTestId ( 'filter-group-control' ) ) ;
984+ await userEvent . click ( child ( ) . getByTestId ( 'filter-group-control' ) ) ;
985+ expect ( child ( ) . getByTestId ( 'filter-group-panel' ) ) . toHaveAttribute (
986+ 'aria-hidden' ,
987+ 'true' ,
988+ ) ;
989+
990+ rerender (
991+ < TestProviders >
992+ < NestedFilterGroup
993+ { ...props }
994+ selectedValues = { {
995+ [ key ] : { included : new Set ( [ 'val' ] ) , excluded : new Set ( ) } ,
996+ } }
997+ />
998+ </ TestProviders > ,
999+ ) ;
1000+
1001+ expect ( child ( ) . getByTestId ( 'filter-group-panel' ) ) . toHaveAttribute (
1002+ 'aria-hidden' ,
1003+ 'false' ,
1004+ ) ;
1005+ } ) ;
1006+
1007+ it ( 'should keep a child expanded when its filter is removed' , ( ) => {
1008+ const props = {
1009+ ...defaultNestedProps ,
1010+ childFilters : manyChildFilters ,
1011+ isDefaultExpanded : true ,
1012+ } ;
1013+ const { key } = manyChildFilters [ 0 ] ;
1014+ const { rerender } = renderWithMantine (
1015+ < NestedFilterGroup
1016+ { ...props }
1017+ selectedValues = { {
1018+ [ key ] : { included : new Set ( [ 'val' ] ) , excluded : new Set ( ) } ,
1019+ } }
1020+ /> ,
1021+ ) ;
1022+ const panel = ( ) =>
1023+ within ( screen . getByTestId ( `nested-filter-group-${ key } ` ) ) . getByTestId (
1024+ 'filter-group-panel' ,
1025+ ) ;
1026+ expect ( panel ( ) ) . toHaveAttribute ( 'aria-hidden' , 'false' ) ;
1027+
1028+ rerender (
1029+ < TestProviders >
1030+ < NestedFilterGroup { ...props } />
1031+ </ TestProviders > ,
1032+ ) ;
1033+
1034+ expect ( panel ( ) ) . toHaveAttribute ( 'aria-hidden' , 'false' ) ;
1035+ } ) ;
1036+
9361037 it ( 'should show an empty state when no keys match' , async ( ) => {
9371038 renderWithMantine (
9381039 < NestedFilterGroup
0 commit comments