From 9e58916d935cf15c3fbe1949dd81f7acec2514c3 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) --- .../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 b247950aba..37a3920436 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; @@ -384,6 +388,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(