rebenitez1802 commented on code in PR #37017:
URL: https://github.com/apache/superset/pull/37017#discussion_r2687399057
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.test.tsx:
##########
@@ -602,6 +602,84 @@ describe('SelectFilterPlugin', () => {
expect(options[2]).toHaveTextContent('alpha');
});
+ test('Select boolean FALSE value in single-select mode', async () => {
+ const setDataMaskMock = jest.fn();
+ const testProps = {
+ ...selectMultipleProps,
+ formData: {
+ ...selectMultipleProps.formData,
+ multiSelect: false,
+ groupby: ['is_active'],
+ },
+ queriesData: [
+ {
+ ...selectMultipleProps.queriesData[0],
+ colnames: ['is_active'],
+ data: [{ is_active: true }, { is_active: false }],
+ applied_filters: [{ column: 'is_active' }],
+ },
+ ],
+ filterState: { value: undefined },
+ };
+
+ render(
+ // @ts-ignore
+ <SelectFilterPlugin
+ // @ts-ignore
+ {...transformProps(testProps)}
+ setDataMask={setDataMaskMock}
+ showOverflow={false}
+ />,
+ {
+ useRedux: true,
+ initialState: {
+ nativeFilters: {
+ filters: {
+ 'test-filter': {
+ name: 'Test Filter',
+ },
+ },
+ },
+ dataMask: {
+ 'test-filter': {
+ extraFormData: {},
+ filterState: {
+ value: undefined,
+ },
+ },
+ },
+ },
+ },
+ );
+
+ const filterSelect = screen.getByRole('combobox');
+ await userEvent.click(filterSelect);
+
+ const falseOption = await screen.findByRole('option', { name: /false/i });
+ expect(falseOption).toBeInTheDocument();
+ await userEvent.click(falseOption);
+
+ const selectedElements = await screen.findAllByTitle('FALSE');
+ expect(selectedElements.length).toBeGreaterThan(0);
+
+ expect(setDataMaskMock).toHaveBeenCalledWith(
+ expect.objectContaining({
+ extraFormData: {
+ filters: [
+ {
+ col: 'is_active',
+ op: 'IN',
+ val: [false],
+ },
+ ],
+ },
+ filterState: expect.objectContaining({
+ value: [false],
+ }),
+ }),
+ );
+ });
+
Review Comment:
Consider adding a few more test cases to make this bulletproof
- Selecting TRUE value (to ensure it still works)
- Toggling between TRUE and FALSE
- Boolean filter with null values
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]