Skip to content

Commit

Permalink
Fix link control tests by querying explicitly for the spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 7, 2023
1 parent 968add1 commit 5761d79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ describe( 'Basic rendering', () => {
await user.type( searchInput, 'Hello' );

// Wait for the spinner SVG icon to be rendered.
expect( await screen.findByRole( 'presentation' ) ).toBeVisible();
expect(
await screen.findByTestId( 'components-spinner' )
).toBeVisible();
// Check the suggestions list is not rendered yet.
expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();

Expand All @@ -190,7 +192,9 @@ describe( 'Basic rendering', () => {
// Check the suggestions list is rendered.
expect( resultsList ).toBeVisible();
// Check the spinner SVG icon is not rendered any longer.
expect( screen.queryByRole( 'presentation' ) ).not.toBeInTheDocument();
expect(
screen.queryByTestId( 'components-spinner' )
).not.toBeInTheDocument();

const searchResultElements =
within( resultsList ).getAllByRole( 'option' );
Expand Down Expand Up @@ -455,14 +459,18 @@ describe( 'Searching for a link', () => {
// Simulate searching for a term.
await user.type( searchInput, searchTerm );

expect( await screen.findByRole( 'presentation' ) ).toBeVisible();
expect(
await screen.findByTestId( 'components-spinner' )
).toBeVisible();
expect( screen.queryByRole( 'listbox' ) ).not.toBeInTheDocument();

// make the search suggestions fetch return a response
resolver( fauxEntitySuggestions );

expect( await screen.findByRole( 'listbox' ) ).toBeVisible();
expect( screen.queryByRole( 'presentation' ) ).not.toBeInTheDocument();
expect(
screen.queryByTestId( 'components-spinner' )
).not.toBeInTheDocument();
} );

it.each( [ 'With spaces', 'Uppercase', 'lowercase' ] )(
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/spinner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function UnforwardedSpinner(
focusable="false"
{ ...props }
ref={ forwardedRef }
data-testid="components-spinner"
>
{ /* Gray circular background */ }
<SpinnerTrack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ exports[`PostPublishPanel should render the spinner if the post is being saved 1
>
<svg
class="components-spinner emotion-0 emotion-1"
data-testid="components-spinner"
focusable="false"
height="16"
role="presentation"
Expand Down

0 comments on commit 5761d79

Please sign in to comment.