Skip to content

Commit

Permalink
Add unit tests to V1 and V2 legacy wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jun 27, 2024
1 parent 6634310 commit 5321e8e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,28 @@ describe.each( [
expect( currentSelectedItem ).toHaveTextContent( 'amber' );
} );

it( 'Can change selection with a focused input and closed dropdown while pressing arrow keys', async () => {
render( <Component { ...legacyProps } /> );

const currentSelectedItem = screen.getByRole( 'combobox', {
expanded: false,
} );

await press.Tab();
expect( currentSelectedItem ).toHaveFocus();
expect( currentSelectedItem ).toHaveTextContent(
legacyProps.options[ 0 ].name
);

await press.ArrowDown();
await press.ArrowDown();
expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();

expect( currentSelectedItem ).toHaveTextContent(
legacyProps.options[ 2 ].name
);
} );

it( 'Should have correct aria-selected value for selections', async () => {
render( <Component { ...legacyProps } /> );

Expand Down
24 changes: 24 additions & 0 deletions packages/components/src/custom-select-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,30 @@ describe.each( [
expect( currentSelectedItem ).toHaveTextContent( 'aquamarine' );
} );

it( 'Can change selection with a focused input and closed dropdown while pressing arrow keys', async () => {
const user = userEvent.setup();

render( <Component { ...props } /> );

const currentSelectedItem = screen.getByRole( 'button', {
expanded: false,
} );

await user.tab();
expect( currentSelectedItem ).toHaveFocus();
expect( currentSelectedItem ).toHaveTextContent(
props.options[ 0 ].name
);

await user.keyboard( '{arrowdown}' );
await user.keyboard( '{arrowdown}' );
expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();

expect( currentSelectedItem ).toHaveTextContent(
props.options[ 2 ].name
);
} );

it( 'Should have correct aria-selected value for selections', async () => {
const user = userEvent.setup();

Expand Down

0 comments on commit 5321e8e

Please sign in to comment.