mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: show search filtered total (#36083)
This commit is contained in:
@@ -17,7 +17,13 @@
|
||||
* under the License.
|
||||
*/
|
||||
import '@testing-library/jest-dom';
|
||||
import { render, screen } from '@superset-ui/core/spec';
|
||||
import {
|
||||
render,
|
||||
screen,
|
||||
fireEvent,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@superset-ui/core/spec';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import TableChart, { sanitizeHeaderId } from '../src/TableChart';
|
||||
import transformProps from '../src/transformProps';
|
||||
@@ -1085,6 +1091,52 @@ describe('plugin-chart-table', () => {
|
||||
'rgba(172, 225, 196, 1)',
|
||||
);
|
||||
});
|
||||
|
||||
it('recalculates totals when user filters data', async () => {
|
||||
const formDataWithTotals = {
|
||||
...testData.basic.formData,
|
||||
show_totals: true,
|
||||
include_search: true,
|
||||
server_pagination: false,
|
||||
metrics: ['sum__num'],
|
||||
};
|
||||
|
||||
const data = testData.basic.queriesData[0].data;
|
||||
const totalBeforeFilter = data.reduce(
|
||||
(sum, row) => sum + Number(row.sum__num || 0),
|
||||
0,
|
||||
);
|
||||
const totalAfterFilter =
|
||||
data.find(item => item.name === 'Michael')?.sum__num || 0;
|
||||
|
||||
const props = transformProps({
|
||||
...testData.basic,
|
||||
formData: formDataWithTotals,
|
||||
});
|
||||
props.totals = { sum__num: totalBeforeFilter };
|
||||
props.includeSearch = true;
|
||||
render(
|
||||
<ProviderWrapper>
|
||||
<TableChart {...props} sticky={false} />
|
||||
</ProviderWrapper>,
|
||||
);
|
||||
|
||||
const table = screen.getByRole('table');
|
||||
const totalCellBefore = within(table).getByText(
|
||||
String(totalBeforeFilter),
|
||||
);
|
||||
expect(totalCellBefore).toBeInTheDocument();
|
||||
|
||||
const searchInput = screen.getByRole('textbox');
|
||||
fireEvent.change(searchInput, { target: { value: 'Michael' } });
|
||||
|
||||
await waitFor(() => {
|
||||
const totalCellAfter = within(table).getByText(
|
||||
String(totalAfterFilter),
|
||||
);
|
||||
expect(totalCellAfter).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user