From 9e524aad1b112704cc8224dabf8fd194f6c88bae Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Wed, 23 Mar 2022 09:31:38 -0400 Subject: [PATCH] fix: regression on Select component when handling null values (#19326) (cherry picked from commit 9e58916d935cf15c3fbe1949dd81f7acec2514c3) --- .../src/components/Select/Select.test.tsx | 28 +++++++++++++++++++ .../src/components/Select/utils.ts | 12 ++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/components/Select/Select.test.tsx b/superset-frontend/src/components/Select/Select.test.tsx index 4701af236ceba..1092ec754dac3 100644 --- a/superset-frontend/src/components/Select/Select.test.tsx +++ b/superset-frontend/src/components/Select/Select.test.tsx @@ -50,6 +50,10 @@ const OPTIONS = [ { label: 'Cher', value: 22, gender: 'Female' }, { label: 'Her', value: 23, gender: 'Male' }, ].sort((option1, option2) => option1.label.localeCompare(option2.label)); +const NULL_OPTION = { label: '', value: null } as unknown as { + label: string; + value: number; +}; const loadOptions = async (search: string, page: number, pageSize: number) => { const totalCount = OPTIONS.length; @@ -373,6 +377,30 @@ test('does not add a new option if allowNewOptions is false', async () => { expect(await screen.findByText(NO_DATA)).toBeInTheDocument(); }); +test('adds the null option when selected in single mode', async () => { + render(, + ); + await open(); + userEvent.click(await findSelectOption(OPTIONS[0].label)); + userEvent.click(await findSelectOption(NULL_OPTION.label)); + const values = await findAllSelectValues(); + expect(values[0]).toHaveTextContent(OPTIONS[0].label); + expect(values[1]).toHaveTextContent(NULL_OPTION.label); +}); + test('static - renders the select with default props', () => { render(