Skip to content

Commit

Permalink
Re-use option objects when it makes sense instead of hardcoded strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jun 21, 2024
1 parent a073327 commit c5b6a4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe.each( [
screen.getByRole( 'combobox', {
expanded: false,
} )
).toHaveTextContent( 'violets' );
).toHaveTextContent( legacyProps.options[ 0 ].name );

// Necessary to wait for onChange to potentially fire
await sleep();
Expand All @@ -156,7 +156,7 @@ describe.each( [
screen.getByRole( 'combobox', {
expanded: false,
} )
).toHaveTextContent( 'amber' );
).toHaveTextContent( legacyProps.options[ 3 ].name );

// Necessary to wait for onChange to potentially fire
await sleep();
Expand Down Expand Up @@ -502,7 +502,9 @@ describe.each( [
await press.ArrowDown();
await press.Enter();

expect( currentSelectedItem ).toHaveTextContent( 'crimson clover' );
expect( currentSelectedItem ).toHaveTextContent(
legacyProps.options[ 1 ].name
);
} );

it( 'Should be able to type characters to select matching options', async () => {
Expand Down Expand Up @@ -536,7 +538,9 @@ describe.each( [
await sleep();
await press.Tab();
expect( currentSelectedItem ).toHaveFocus();
expect( currentSelectedItem ).toHaveTextContent( 'violets' );
expect( currentSelectedItem ).toHaveTextContent(
legacyProps.options[ 0 ].name
);

// Ideally we would test a multi-character typeahead, but anything more than a single character is flaky
await type( 'a' );
Expand Down
8 changes: 5 additions & 3 deletions packages/components/src/custom-select-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe.each( [
screen.getByRole( 'button', {
expanded: false,
} )
).toHaveTextContent( 'violets' );
).toHaveTextContent( props.options[ 0 ].name );

expect( mockOnChange ).not.toHaveBeenCalled();
} );
Expand All @@ -142,7 +142,7 @@ describe.each( [
screen.getByRole( 'button', {
expanded: false,
} )
).toHaveTextContent( 'amber' );
).toHaveTextContent( props.options[ 3 ].name );

expect( mockOnChange ).not.toHaveBeenCalled();
} );
Expand Down Expand Up @@ -489,7 +489,9 @@ describe.each( [
await user.keyboard( '{arrowdown}' );
await user.keyboard( '{enter}' );

expect( currentSelectedItem ).toHaveTextContent( 'crimson clover' );
expect( currentSelectedItem ).toHaveTextContent(
props.options[ 1 ].name
);
} );

it( 'Should be able to type characters to select matching options', async () => {
Expand Down

0 comments on commit c5b6a4c

Please sign in to comment.