Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboboxControl: Add more unit tests #65255

Merged
merged 7 commits into from
Sep 18, 2024
40 changes: 40 additions & 0 deletions packages/components/src/combobox-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,46 @@ describe.each( [
expect( input ).toHaveValue( targetOption.label );
} );

it( 'calls onFilterValueChange whenever the textbox changes', async () => {
const user = userEvent.setup();
const onFilterValueChangeSpy = jest.fn();
render(
<Component
options={ timezones }
label={ defaultLabelText }
onFilterValueChange={ onFilterValueChangeSpy }
/>
);

const input = getInput( defaultLabelText );

await user.type( input, 'a' );
expect( onFilterValueChangeSpy ).toHaveBeenCalledWith( 'a' );
} );

it( 'clears the textbox value if there is no selected value on blur', async () => {
const user = userEvent.setup();
const onFilterValueChangeSpy = jest.fn();
render(
<Component
options={ timezones }
label={ defaultLabelText }
onFilterValueChange={ onFilterValueChangeSpy }
/>
);
const input = getInput( defaultLabelText );

await user.type( input, 'a' );
expect( input ).toHaveValue( 'a' );

// Blur and focus the input.
await user.tab();
await user.click( input );

expect( input ).toHaveValue( '' );
expect( onFilterValueChangeSpy ).toHaveBeenLastCalledWith( '' );
} );

it( 'should select the correct option from a search', async () => {
const user = await userEvent.setup();
const targetOption = timezones[ 13 ];
Expand Down
Loading