Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Dec 15, 2023
1 parent 6e650da commit 136f647
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/components/src/form-token-field/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,40 @@ describe( 'FormTokenField', () => {
] );
} );

it( 'should not render suggestions after the input is blurred', async () => {
const user = userEvent.setup();

const onFocusSpy = jest.fn();

const suggestions = [ 'Green', 'Emerald', 'Seaweed' ];

render(
<>
<FormTokenFieldWithState
onFocus={ onFocusSpy }
suggestions={ suggestions }
/>
</>
);

const input = screen.getByRole( 'combobox' );

await user.type( input, 'ee' );

expectVisibleSuggestionsToBe( screen.getByRole( 'listbox' ), [
'Green',
'Seaweed',
] );

// Select the first suggestion ("Green")
await user.keyboard( '[ArrowDown][Enter]' );

// Click the body, blurring the input.
await user.click( document.body );

expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();
} );

it( 'should not render suggestions if the text input is not matching any of the suggestions', async () => {
const user = userEvent.setup();

Expand Down

0 comments on commit 136f647

Please sign in to comment.