From f0ec47312a93db10db3b0eaeca4dfd952abf8e90 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Wed, 1 Nov 2023 13:54:23 -0700 Subject: [PATCH] Add missing test for `onSearchChange` that demonstrates bug --- src/components/combo_box/combo_box.test.tsx | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/components/combo_box/combo_box.test.tsx b/src/components/combo_box/combo_box.test.tsx index 4dcdcc9274d..6ba4af27414 100644 --- a/src/components/combo_box/combo_box.test.tsx +++ b/src/components/combo_box/combo_box.test.tsx @@ -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( + + ); + 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 () => { @@ -587,7 +603,6 @@ describe('EuiComboBox', () => { }); describe('sortMatchesBy', () => { - const onSearchChange = jest.fn(); const sortMatchesByOptions = [ { label: 'Something is Disabled' }, ...options, @@ -595,11 +610,7 @@ describe('EuiComboBox', () => { test('"none"', () => { const { getByTestSubject, getAllByRole } = render( - + ); fireEvent.change(getByTestSubject('comboBoxSearchInput'), { target: { value: 'di' }, @@ -615,7 +626,6 @@ describe('EuiComboBox', () => { const { getByTestSubject, getAllByRole } = render( );