Skip to content

Commit

Permalink
fix: Fires onChange when clearing all values of single select (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Nov 3, 2023
1 parent ff8bc3c commit 8061d5c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
28 changes: 28 additions & 0 deletions superset-frontend/src/components/Select/AsyncSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,34 @@ test('does not fire onChange when searching but no selection', async () => {
expect(onChange).toHaveBeenCalledTimes(1);
});

test('fires onChange when clearing the selection in single mode', async () => {
const onChange = jest.fn();
render(
<AsyncSelect
{...defaultProps}
onChange={onChange}
mode="single"
value={OPTIONS[0]}
/>,
);
clearAll();
expect(onChange).toHaveBeenCalledTimes(1);
});

test('fires onChange when clearing the selection in multiple mode', async () => {
const onChange = jest.fn();
render(
<AsyncSelect
{...defaultProps}
onChange={onChange}
mode="multiple"
value={OPTIONS[0]}
/>,
);
clearAll();
expect(onChange).toHaveBeenCalledTimes(1);
});

test('does not duplicate options when using numeric values', async () => {
render(
<AsyncSelect
Expand Down
28 changes: 28 additions & 0 deletions superset-frontend/src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,34 @@ test('does not fire onChange when searching but no selection', async () => {
expect(onChange).toHaveBeenCalledTimes(1);
});

test('fires onChange when clearing the selection in single mode', async () => {
const onChange = jest.fn();
render(
<Select
{...defaultProps}
onChange={onChange}
mode="single"
value={OPTIONS[0]}
/>,
);
clearAll();
expect(onChange).toHaveBeenCalledTimes(1);
});

test('fires onChange when clearing the selection in multiple mode', async () => {
const onChange = jest.fn();
render(
<Select
{...defaultProps}
onChange={onChange}
mode="multiple"
value={OPTIONS[0]}
/>,
);
clearAll();
expect(onChange).toHaveBeenCalledTimes(1);
});

test('does not duplicate options when using numeric values', async () => {
render(
<Select
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ const Select = forwardRef(
: option.value,
),
);
fireOnChange();
}
fireOnChange();
};

const handleOnDeselect: SelectProps['onDeselect'] = (value, option) => {
Expand Down

0 comments on commit 8061d5c

Please sign in to comment.