Skip to content

Commit

Permalink
Migrate CircularOptionPicker tests from user-event to ariakit/test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jan 12, 2024
1 parent f6e2ba8 commit c7b359e
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions packages/components/src/circular-option-picker/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { press } from '@ariakit/test';

/**
* Internal dependencies
Expand Down Expand Up @@ -71,28 +71,24 @@ describe( 'CircularOptionPicker', () => {

describe( 'when `loop` is not set', () => {
it( 'should loop', async () => {
const user = userEvent.setup();

render(
<CircularOptionPicker
{ ...DEFAULT_PROPS }
options={ MULTIPLE_OPTIONS }
/>
);

await user.tab();
await press.Tab();
expect( getOption( 'Option One' ) ).toHaveFocus();
await user.keyboard( '[ArrowRight]' );
await press.ArrowRight();
expect( getOption( 'Option Two' ) ).toHaveFocus();
await user.keyboard( '[ArrowRight]' );
await press.ArrowRight();
expect( getOption( 'Option One' ) ).toHaveFocus();
} );
} );

describe( 'when `loop` is true', () => {
it( 'should loop', async () => {
const user = userEvent.setup();

render(
<CircularOptionPicker
{ ...DEFAULT_PROPS }
Expand All @@ -101,19 +97,17 @@ describe( 'CircularOptionPicker', () => {
/>
);

await user.tab();
await press.Tab();
expect( getOption( 'Option One' ) ).toHaveFocus();
await user.keyboard( '[ArrowRight]' );
await press.ArrowRight();
expect( getOption( 'Option Two' ) ).toHaveFocus();
await user.keyboard( '[ArrowRight]' );
await press.ArrowRight();
expect( getOption( 'Option One' ) ).toHaveFocus();
} );
} );

describe( 'when `loop` is false', () => {
it( 'should not loop', async () => {
const user = userEvent.setup();

render(
<CircularOptionPicker
{ ...DEFAULT_PROPS }
Expand All @@ -122,11 +116,11 @@ describe( 'CircularOptionPicker', () => {
/>
);

await user.tab();
await press.Tab();
expect( getOption( 'Option One' ) ).toHaveFocus();
await user.keyboard( '[ArrowRight]' );
await press.ArrowRight();
expect( getOption( 'Option Two' ) ).toHaveFocus();
await user.keyboard( '[ArrowRight]' );
await press.ArrowRight();
expect( getOption( 'Option Two' ) ).toHaveFocus();
} );
} );
Expand Down

0 comments on commit c7b359e

Please sign in to comment.