Skip to content

Commit

Permalink
Update test by using ByRole queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Oct 24, 2024
1 parent adb94ad commit ee7667a
Showing 1 changed file with 63 additions and 21 deletions.
84 changes: 63 additions & 21 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ describe( 'Basic rendering', () => {
/>
);

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

const isPreviewError = linkPreview.classList.contains( 'is-error' );
expect( isPreviewError ).toBe( true );
Expand Down Expand Up @@ -834,7 +836,9 @@ describe( 'Manual link entry', () => {

render( <LinkControlConsumer /> );

let linkPreview = screen.getByLabelText( 'Manage link' );
let linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

expect( linkPreview ).toBeInTheDocument();

Expand Down Expand Up @@ -868,7 +872,9 @@ describe( 'Manual link entry', () => {
// Cancel the editing process.
await user.click( cancelButton );

linkPreview = screen.getByLabelText( 'Manage link' );
linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

expect( linkPreview ).toBeInTheDocument();

Expand Down Expand Up @@ -1076,7 +1082,9 @@ describe( 'Default search suggestions', () => {

// Click the "Edit/Change" button and check initial suggestions are not
// shown.
const currentLinkUI = screen.getByLabelText( 'Manage link' );
const currentLinkUI = screen.getByRole( 'group', {
name: 'Manage link',
} );
const currentLinkBtn = within( currentLinkUI ).getByRole( 'button', {
name: 'Edit link',
} );
Expand Down Expand Up @@ -1230,7 +1238,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {

// Check for loading indicator.
const loadingIndicator = screen.getByText( 'Creating…' );
const currentLinkLabel = screen.queryByLabelText( 'Manage link' );
const currentLinkLabel = screen.queryByRole( 'group', {
name: 'Manage link',
} );

expect( currentLinkLabel ).not.toBeInTheDocument();
expect( loadingIndicator ).toBeVisible();
Expand All @@ -1241,7 +1251,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
// Resolve the `createSuggestion` promise.
resolver();

const currentLink = await screen.findByLabelText( 'Manage link' );
const currentLink = await screen.findByRole( 'group', {
name: 'Manage link',
} );

expect( currentLink ).toHaveTextContent( entityNameText );
expect( currentLink ).toHaveTextContent( '/?p=123' );
Expand Down Expand Up @@ -1289,7 +1301,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {

await user.click( createButton );

const currentLink = screen.getByLabelText( 'Manage link' );
const currentLink = screen.getByRole( 'group', {
name: 'Manage link',
} );

expect( currentLink ).toHaveTextContent( 'Some new page to create' );
expect( currentLink ).toHaveTextContent( '/?p=123' );
Expand Down Expand Up @@ -1348,7 +1362,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
triggerEnter( searchInput );

expect(
await screen.findByLabelText( 'Manage link' )
await screen.findByRole( 'group', {
name: 'Manage link',
} )
).toHaveTextContent( entityNameText );
} );

Expand Down Expand Up @@ -1527,7 +1543,9 @@ describe( 'Selecting links', () => {

render( <LinkControlConsumer /> );

const currentLink = screen.getByLabelText( 'Manage link' );
const currentLink = screen.getByRole( 'group', {
name: 'Manage link',
} );
const currentLinkAnchor = screen.getByRole( 'link', {
name: `${ selectedLink.title } (opens in a new tab)`,
} );
Expand Down Expand Up @@ -1557,7 +1575,9 @@ describe( 'Selecting links', () => {
render( <LinkControlConsumer /> );

// Required in order to select the button below.
let currentLinkUI = screen.getByLabelText( 'Manage link' );
let currentLinkUI = screen.getByRole( 'group', {
name: 'Manage link',
} );
const currentLinkBtn = within( currentLinkUI ).getByRole( 'button', {
name: 'Edit link',
} );
Expand All @@ -1568,7 +1588,9 @@ describe( 'Selecting links', () => {
const searchInput = screen.getByRole( 'combobox', {
name: 'Search or type URL',
} );
currentLinkUI = screen.queryByLabelText( 'Manage link' );
currentLinkUI = screen.queryByRole( 'group', {
name: 'Manage link',
} );

// We should be back to showing the search input.
expect( searchInput ).toBeVisible();
Expand Down Expand Up @@ -1731,7 +1753,9 @@ describe( 'Selecting links', () => {
triggerEnter( searchInput );

// Check that the suggestion selected via is now shown as selected.
const currentLink = screen.getByLabelText( 'Manage link' );
const currentLink = screen.getByRole( 'group', {
name: 'Manage link',
} );
const currentLinkAnchor = screen.getByRole( 'link', {
name: `${ selectedLink.title } (opens in a new tab)`,
} );
Expand Down Expand Up @@ -2124,7 +2148,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

const isRichLinkPreview = linkPreview.classList.contains( 'is-rich' );

Expand All @@ -2145,7 +2171,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

await waitFor( () => expect( linkPreview ).toHaveClass( 'is-rich' ) );
} );
Expand All @@ -2162,7 +2190,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

await waitFor( () => expect( linkPreview ).toHaveClass( 'is-rich' ) );

Expand Down Expand Up @@ -2194,7 +2224,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

await waitFor( () => expect( linkPreview ).toHaveClass( 'is-rich' ) );

Expand All @@ -2218,7 +2250,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

await waitFor( () => expect( linkPreview ).toHaveClass( 'is-rich' ) );

Expand Down Expand Up @@ -2253,7 +2287,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

await waitFor( () =>
expect( linkPreview ).toHaveClass( 'is-rich' )
Expand All @@ -2278,7 +2314,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

expect( linkPreview ).toHaveClass( 'is-fetching' );

Expand All @@ -2297,7 +2335,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

expect( linkPreview ).toHaveClass( 'is-fetching' );
expect( linkPreview ).not.toHaveClass( 'is-rich' );
Expand All @@ -2310,7 +2350,9 @@ describe( 'Rich link previews', () => {

render( <LinkControl value={ selectedLink } hasRichPreviews /> );

const linkPreview = screen.getByLabelText( 'Manage link' );
const linkPreview = screen.getByRole( 'group', {
name: 'Manage link',
} );

expect( linkPreview ).toHaveClass( 'is-fetching' );

Expand Down

0 comments on commit ee7667a

Please sign in to comment.