Skip to content

Commit

Permalink
add tests for suggestion visibility after selection
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 committed Dec 15, 2023
1 parent 136f647 commit 333952b
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 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,69 @@ describe( 'FormTokenField', () => {
] );
} );

it( 'should render suggestions after a selection is made when the `__experimentalExpandOnFocus` prop is set to `true`', async () => {
const user = userEvent.setup();

const onFocusSpy = jest.fn();

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

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

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]' );

expect( screen.getByRole( 'listbox' ) ).toBeVisible();
} );

it( 'should not render suggestions after a selection is made when the `__experimentalExpandOnFocus` prop is set to `false` or not defined', 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]' );

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

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

Expand Down

0 comments on commit 333952b

Please sign in to comment.