Skip to content

Commit c737c13

Browse files
committed
Update test by using ByRole queries.
1 parent a0ce5cd commit c737c13

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

packages/block-editor/src/components/link-control/test/index.js

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ describe( 'Basic rendering', () => {
373373
/>
374374
);
375375

376-
const linkPreview = screen.getByLabelText( 'Manage link' );
376+
const linkPreview = screen.getByRole( 'group', {
377+
name: 'Manage link',
378+
} );
377379

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

835837
render( <LinkControlConsumer /> );
836838

837-
let linkPreview = screen.getByLabelText( 'Manage link' );
839+
let linkPreview = screen.getByRole( 'group', {
840+
name: 'Manage link',
841+
} );
838842

839843
expect( linkPreview ).toBeInTheDocument();
840844

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

871-
linkPreview = screen.getByLabelText( 'Manage link' );
875+
linkPreview = screen.getByRole( 'group', {
876+
name: 'Manage link',
877+
} );
872878

873879
expect( linkPreview ).toBeInTheDocument();
874880

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

10771083
// Click the "Edit/Change" button and check initial suggestions are not
10781084
// shown.
1079-
const currentLinkUI = screen.getByLabelText( 'Manage link' );
1085+
const currentLinkUI = screen.getByRole( 'group', {
1086+
name: 'Manage link',
1087+
} );
10801088
const currentLinkBtn = within( currentLinkUI ).getByRole( 'button', {
10811089
name: 'Edit link',
10821090
} );
@@ -1230,7 +1238,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
12301238

12311239
// Check for loading indicator.
12321240
const loadingIndicator = screen.getByText( 'Creating…' );
1233-
const currentLinkLabel = screen.queryByLabelText( 'Manage link' );
1241+
const currentLinkLabel = screen.queryByRole( 'group', {
1242+
name: 'Manage link',
1243+
} );
12341244

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

1244-
const currentLink = await screen.findByLabelText( 'Manage link' );
1254+
const currentLink = await screen.findByRole( 'group', {
1255+
name: 'Manage link',
1256+
} );
12451257

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

12901302
await user.click( createButton );
12911303

1292-
const currentLink = screen.getByLabelText( 'Manage link' );
1304+
const currentLink = screen.getByRole( 'group', {
1305+
name: 'Manage link',
1306+
} );
12931307

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

13501364
expect(
1351-
await screen.findByLabelText( 'Manage link' )
1365+
await screen.findByRole( 'group', {
1366+
name: 'Manage link',
1367+
} )
13521368
).toHaveTextContent( entityNameText );
13531369
} );
13541370

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

15281544
render( <LinkControlConsumer /> );
15291545

1530-
const currentLink = screen.getByLabelText( 'Manage link' );
1546+
const currentLink = screen.getByRole( 'group', {
1547+
name: 'Manage link',
1548+
} );
15311549
const currentLinkAnchor = screen.getByRole( 'link', {
15321550
name: `${ selectedLink.title } (opens in a new tab)`,
15331551
} );
@@ -1557,7 +1575,9 @@ describe( 'Selecting links', () => {
15571575
render( <LinkControlConsumer /> );
15581576

15591577
// Required in order to select the button below.
1560-
let currentLinkUI = screen.getByLabelText( 'Manage link' );
1578+
let currentLinkUI = screen.getByRole( 'group', {
1579+
name: 'Manage link',
1580+
} );
15611581
const currentLinkBtn = within( currentLinkUI ).getByRole( 'button', {
15621582
name: 'Edit link',
15631583
} );
@@ -1568,7 +1588,9 @@ describe( 'Selecting links', () => {
15681588
const searchInput = screen.getByRole( 'combobox', {
15691589
name: 'Search or type URL',
15701590
} );
1571-
currentLinkUI = screen.queryByLabelText( 'Manage link' );
1591+
currentLinkUI = screen.queryByRole( 'group', {
1592+
name: 'Manage link',
1593+
} );
15721594

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

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

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

2127-
const linkPreview = screen.getByLabelText( 'Manage link' );
2151+
const linkPreview = screen.getByRole( 'group', {
2152+
name: 'Manage link',
2153+
} );
21282154

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

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

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

2148-
const linkPreview = screen.getByLabelText( 'Manage link' );
2174+
const linkPreview = screen.getByRole( 'group', {
2175+
name: 'Manage link',
2176+
} );
21492177

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

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

2165-
const linkPreview = screen.getByLabelText( 'Manage link' );
2193+
const linkPreview = screen.getByRole( 'group', {
2194+
name: 'Manage link',
2195+
} );
21662196

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

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

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

2197-
const linkPreview = screen.getByLabelText( 'Manage link' );
2227+
const linkPreview = screen.getByRole( 'group', {
2228+
name: 'Manage link',
2229+
} );
21982230

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

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

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

2221-
const linkPreview = screen.getByLabelText( 'Manage link' );
2253+
const linkPreview = screen.getByRole( 'group', {
2254+
name: 'Manage link',
2255+
} );
22222256

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

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

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

2256-
const linkPreview = screen.getByLabelText( 'Manage link' );
2290+
const linkPreview = screen.getByRole( 'group', {
2291+
name: 'Manage link',
2292+
} );
22572293

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

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

2281-
const linkPreview = screen.getByLabelText( 'Manage link' );
2317+
const linkPreview = screen.getByRole( 'group', {
2318+
name: 'Manage link',
2319+
} );
22822320

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

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

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

2300-
const linkPreview = screen.getByLabelText( 'Manage link' );
2338+
const linkPreview = screen.getByRole( 'group', {
2339+
name: 'Manage link',
2340+
} );
23012341

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

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

2313-
const linkPreview = screen.getByLabelText( 'Manage link' );
2353+
const linkPreview = screen.getByRole( 'group', {
2354+
name: 'Manage link',
2355+
} );
23142356

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

0 commit comments

Comments
 (0)