Skip to content

Commit

Permalink
ComboboxControl: Add more unit tests (#65255)
Browse files Browse the repository at this point in the history
* Combobox Control: Do not clear values when focusing the textbox

* Call onFilterValueChange on blur if no value is selected

* Clear inputValue on the background to avoid suggestion flickering

* Revert "Clear inputValue on the background to avoid suggestion flickering"

This reverts commit 43158d2.

* Revert "Call onFilterValueChange on blur if no value is selected"

This reverts commit 2a62872.

* Revert "Combobox Control: Do not clear values when focusing the textbox"

This reverts commit 0423a7e.

* Tweak tests

---------

Co-authored-by: Lena Morita <[email protected]>
Co-authored-by: zaguiini <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
5 people authored Sep 18, 2024
1 parent 48079e9 commit b6ba559
Showing 1 changed file with 40 additions and 0 deletions.
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

0 comments on commit b6ba559

Please sign in to comment.