@@ -1042,7 +1042,21 @@ describe('Table.tsx', () => {
1042
1042
expect ( emitMock ) . toHaveBeenCalledTimes ( 1 )
1043
1043
} )
1044
1044
1045
- it ( 'Filter counts - manual select, deselect' , ( ) => {
1045
+ it ( 'Filter counts - manual select' , ( ) => {
1046
+ const { container, getAllByRole, getByLabelText, queryByTestId } = render ( < XTable model = { tableProps } /> )
1047
+
1048
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
1049
+ fireEvent . click ( container . querySelector ( filterSelectorName ) ! )
1050
+ //select 2 options
1051
+ fireEvent . click ( getByLabelText ( '1' ) )
1052
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( 1 + headerRow )
1053
+ expect ( queryByTestId ( 'filter-count' ) ) . toHaveTextContent ( '1' )
1054
+ fireEvent . click ( getByLabelText ( '2' ) )
1055
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( 2 + headerRow )
1056
+ expect ( queryByTestId ( 'filter-count' ) ) . toHaveTextContent ( '2' )
1057
+ } )
1058
+
1059
+ it ( 'Filter counts - manual deselect' , ( ) => {
1046
1060
const { container, getAllByRole, getByLabelText, queryByTestId } = render ( < XTable model = { tableProps } /> )
1047
1061
1048
1062
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
@@ -1064,7 +1078,18 @@ describe('Table.tsx', () => {
1064
1078
expect ( queryByTestId ( 'filter-count' ) ) . toBeNull
1065
1079
} )
1066
1080
1067
- it ( 'Filter counts - select all, deselect all' , ( ) => {
1081
+ it ( 'Filter counts - select all' , ( ) => {
1082
+ const { container, getAllByRole, queryByTestId, getByText } = render ( < XTable model = { tableProps } /> )
1083
+
1084
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
1085
+ fireEvent . click ( container . querySelector ( filterSelectorName ) ! )
1086
+
1087
+ fireEvent . click ( getByText ( 'Select All' ) )
1088
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
1089
+ expect ( queryByTestId ( 'filter-count' ) ) . toHaveTextContent ( tableProps . rows ! . length . toString ( ) )
1090
+ } )
1091
+
1092
+ it ( 'Filter counts - deselect all' , ( ) => {
1068
1093
const { container, getAllByRole, queryByTestId, getByText } = render ( < XTable model = { tableProps } /> )
1069
1094
1070
1095
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
@@ -1077,7 +1102,7 @@ describe('Table.tsx', () => {
1077
1102
fireEvent . click ( getByText ( 'Deselect All' ) )
1078
1103
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
1079
1104
expect ( queryByTestId ( 'filter-count' ) ) . toBeNull
1080
- } )
1105
+ } )
1081
1106
1082
1107
it ( 'Filter counts - more than 9 selections' , ( ) => {
1083
1108
@@ -1110,6 +1135,25 @@ describe('Table.tsx', () => {
1110
1135
expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
1111
1136
expect ( queryByTestId ( 'filter-count' ) ) . toBeNull
1112
1137
} )
1138
+
1139
+ it ( 'Filter counts - clear selection with reset' , ( ) => {
1140
+ const { container, getAllByRole, getByLabelText, queryByTestId, getByText } = render ( < XTable model = { { ...tableProps , resettable : true } } /> )
1141
+
1142
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
1143
+ fireEvent . click ( container . querySelector ( filterSelectorName ) ! )
1144
+ //select 2 options
1145
+ fireEvent . click ( getByLabelText ( '1' ) )
1146
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( 1 + headerRow )
1147
+ expect ( queryByTestId ( 'filter-count' ) ) . toHaveTextContent ( '1' )
1148
+ fireEvent . click ( getByLabelText ( '2' ) )
1149
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( 2 + headerRow )
1150
+ expect ( queryByTestId ( 'filter-count' ) ) . toHaveTextContent ( '2' )
1151
+
1152
+ //hit reset to clear the 2 options
1153
+ fireEvent . click ( getByText ( 'Reset table' ) )
1154
+ expect ( getAllByRole ( 'row' ) ) . toHaveLength ( tableProps . rows ! . length + headerRow )
1155
+ expect ( queryByTestId ( 'filter-count' ) ) . toBeNull
1156
+ } )
1113
1157
} )
1114
1158
1115
1159
0 commit comments