Skip to content

Commit

Permalink
Add missing test for onSearchChange that demonstrates bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Nov 1, 2023
1 parent 92efeb4 commit f0ec473
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/components/combo_box/combo_box.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ describe('EuiComboBox', () => {

expect(getByRole('combobox')).toBe(inputRefCallback.mock.calls[0][0]);
});

test('onSearchChange', () => {
const onSearchChange = jest.fn();
const { getByTestSubject, queryAllByRole } = render(
<EuiComboBox options={options} onSearchChange={onSearchChange} />
);
const input = getByTestSubject('comboBoxSearchInput');

fireEvent.change(input, { target: { value: 'no results' } });
expect(onSearchChange).toHaveBeenCalledWith('no results', false);
expect(queryAllByRole('option')).toHaveLength(0);

fireEvent.change(input, { target: { value: 'titan' } });
expect(onSearchChange).toHaveBeenCalledWith('titan', true);
expect(queryAllByRole('option')).toHaveLength(2);
});
});

it('does not show multiple checkmarks with duplicate labels', async () => {
Expand Down Expand Up @@ -587,19 +603,14 @@ describe('EuiComboBox', () => {
});

describe('sortMatchesBy', () => {
const onSearchChange = jest.fn();
const sortMatchesByOptions = [
{ label: 'Something is Disabled' },
...options,
];

test('"none"', () => {
const { getByTestSubject, getAllByRole } = render(
<EuiComboBox
options={sortMatchesByOptions}
onSearchChange={onSearchChange}
sortMatchesBy="none"
/>
<EuiComboBox options={sortMatchesByOptions} sortMatchesBy="none" />
);
fireEvent.change(getByTestSubject('comboBoxSearchInput'), {
target: { value: 'di' },
Expand All @@ -615,7 +626,6 @@ describe('EuiComboBox', () => {
const { getByTestSubject, getAllByRole } = render(
<EuiComboBox
options={sortMatchesByOptions}
onSearchChange={onSearchChange}
sortMatchesBy="startsWith"
/>
);
Expand Down

0 comments on commit f0ec473

Please sign in to comment.