Skip to content

Commit 2593614

Browse files
committed
Update test by using ByRole queries.
1 parent 7ac9990 commit 2593614

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
@@ -365,7 +365,9 @@ describe( 'Basic rendering', () => {
365365
/>
366366
);
367367

368-
const linkPreview = screen.getByLabelText( 'Manage link' );
368+
const linkPreview = screen.getByRole( 'group', {
369+
name: 'Manage link',
370+
} );
369371

370372
const isPreviewError = linkPreview.classList.contains( 'is-error' );
371373
expect( isPreviewError ).toBe( true );
@@ -816,7 +818,9 @@ describe( 'Manual link entry', () => {
816818

817819
render( <LinkControlConsumer /> );
818820

819-
let linkPreview = screen.getByLabelText( 'Manage link' );
821+
let linkPreview = screen.getByRole( 'group', {
822+
name: 'Manage link',
823+
} );
820824

821825
expect( linkPreview ).toBeInTheDocument();
822826

@@ -850,7 +854,9 @@ describe( 'Manual link entry', () => {
850854
// Cancel the editing process.
851855
await user.click( cancelButton );
852856

853-
linkPreview = screen.getByLabelText( 'Manage link' );
857+
linkPreview = screen.getByRole( 'group', {
858+
name: 'Manage link',
859+
} );
854860

855861
expect( linkPreview ).toBeInTheDocument();
856862

@@ -1058,7 +1064,9 @@ describe( 'Default search suggestions', () => {
10581064

10591065
// Click the "Edit/Change" button and check initial suggestions are not
10601066
// shown.
1061-
const currentLinkUI = screen.getByLabelText( 'Manage link' );
1067+
const currentLinkUI = screen.getByRole( 'group', {
1068+
name: 'Manage link',
1069+
} );
10621070
const currentLinkBtn = within( currentLinkUI ).getByRole( 'button', {
10631071
name: 'Edit link',
10641072
} );
@@ -1206,7 +1214,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
12061214

12071215
// Check for loading indicator.
12081216
const loadingIndicator = screen.getByText( 'Creating…' );
1209-
const currentLinkLabel = screen.queryByLabelText( 'Manage link' );
1217+
const currentLinkLabel = screen.queryByRole( 'group', {
1218+
name: 'Manage link',
1219+
} );
12101220

12111221
expect( currentLinkLabel ).not.toBeInTheDocument();
12121222
expect( loadingIndicator ).toBeVisible();
@@ -1217,7 +1227,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
12171227
// Resolve the `createSuggestion` promise.
12181228
resolver();
12191229

1220-
const currentLink = await screen.findByLabelText( 'Manage link' );
1230+
const currentLink = await screen.findByRole( 'group', {
1231+
name: 'Manage link',
1232+
} );
12211233

12221234
expect( currentLink ).toHaveTextContent( entityNameText );
12231235
expect( currentLink ).toHaveTextContent( '/?p=123' );
@@ -1263,7 +1275,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
12631275

12641276
await user.click( createButton );
12651277

1266-
const currentLink = screen.getByLabelText( 'Manage link' );
1278+
const currentLink = screen.getByRole( 'group', {
1279+
name: 'Manage link',
1280+
} );
12671281

12681282
expect( currentLink ).toHaveTextContent( 'Some new page to create' );
12691283
expect( currentLink ).toHaveTextContent( '/?p=123' );
@@ -1320,7 +1334,9 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
13201334
triggerEnter( searchInput );
13211335

13221336
expect(
1323-
await screen.findByLabelText( 'Manage link' )
1337+
await screen.findByRole( 'group', {
1338+
name: 'Manage link',
1339+
} )
13241340
).toHaveTextContent( entityNameText );
13251341
} );
13261342

@@ -1493,7 +1509,9 @@ describe( 'Selecting links', () => {
14931509

14941510
render( <LinkControlConsumer /> );
14951511

1496-
const currentLink = screen.getByLabelText( 'Manage link' );
1512+
const currentLink = screen.getByRole( 'group', {
1513+
name: 'Manage link',
1514+
} );
14971515
const currentLinkAnchor = screen.getByRole( 'link', {
14981516
name: `${ selectedLink.title } (opens in a new tab)`,
14991517
} );
@@ -1523,7 +1541,9 @@ describe( 'Selecting links', () => {
15231541
render( <LinkControlConsumer /> );
15241542

15251543
// Required in order to select the button below.
1526-
let currentLinkUI = screen.getByLabelText( 'Manage link' );
1544+
let currentLinkUI = screen.getByRole( 'group', {
1545+
name: 'Manage link',
1546+
} );
15271547
const currentLinkBtn = within( currentLinkUI ).getByRole( 'button', {
15281548
name: 'Edit link',
15291549
} );
@@ -1532,7 +1552,9 @@ describe( 'Selecting links', () => {
15321552
await user.click( currentLinkBtn );
15331553

15341554
const searchInput = screen.getByRole( 'combobox', { name: 'Link' } );
1535-
currentLinkUI = screen.queryByLabelText( 'Manage link' );
1555+
currentLinkUI = screen.queryByRole( 'group', {
1556+
name: 'Manage link',
1557+
} );
15361558

15371559
// We should be back to showing the search input.
15381560
expect( searchInput ).toBeVisible();
@@ -1695,7 +1717,9 @@ describe( 'Selecting links', () => {
16951717
triggerEnter( searchInput );
16961718

16971719
// Check that the suggestion selected via is now shown as selected.
1698-
const currentLink = screen.getByLabelText( 'Manage link' );
1720+
const currentLink = screen.getByRole( 'group', {
1721+
name: 'Manage link',
1722+
} );
16991723
const currentLinkAnchor = screen.getByRole( 'link', {
17001724
name: `${ selectedLink.title } (opens in a new tab)`,
17011725
} );
@@ -2086,7 +2110,9 @@ describe( 'Rich link previews', () => {
20862110

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

2089-
const linkPreview = screen.getByLabelText( 'Manage link' );
2113+
const linkPreview = screen.getByRole( 'group', {
2114+
name: 'Manage link',
2115+
} );
20902116

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

@@ -2107,7 +2133,9 @@ describe( 'Rich link previews', () => {
21072133

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

2110-
const linkPreview = screen.getByLabelText( 'Manage link' );
2136+
const linkPreview = screen.getByRole( 'group', {
2137+
name: 'Manage link',
2138+
} );
21112139

21122140
await waitFor( () => expect( linkPreview ).toHaveClass( 'is-rich' ) );
21132141
} );
@@ -2124,7 +2152,9 @@ describe( 'Rich link previews', () => {
21242152

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

2127-
const linkPreview = screen.getByLabelText( 'Manage link' );
2155+
const linkPreview = screen.getByRole( 'group', {
2156+
name: 'Manage link',
2157+
} );
21282158

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

@@ -2156,7 +2186,9 @@ describe( 'Rich link previews', () => {
21562186

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

2159-
const linkPreview = screen.getByLabelText( 'Manage link' );
2189+
const linkPreview = screen.getByRole( 'group', {
2190+
name: 'Manage link',
2191+
} );
21602192

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

@@ -2180,7 +2212,9 @@ describe( 'Rich link previews', () => {
21802212

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

2183-
const linkPreview = screen.getByLabelText( 'Manage link' );
2215+
const linkPreview = screen.getByRole( 'group', {
2216+
name: 'Manage link',
2217+
} );
21842218

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

@@ -2215,7 +2249,9 @@ describe( 'Rich link previews', () => {
22152249

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

2218-
const linkPreview = screen.getByLabelText( 'Manage link' );
2252+
const linkPreview = screen.getByRole( 'group', {
2253+
name: 'Manage link',
2254+
} );
22192255

22202256
await waitFor( () =>
22212257
expect( linkPreview ).toHaveClass( 'is-rich' )
@@ -2240,7 +2276,9 @@ describe( 'Rich link previews', () => {
22402276

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

2243-
const linkPreview = screen.getByLabelText( 'Manage link' );
2279+
const linkPreview = screen.getByRole( 'group', {
2280+
name: 'Manage link',
2281+
} );
22442282

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

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

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

2262-
const linkPreview = screen.getByLabelText( 'Manage link' );
2300+
const linkPreview = screen.getByRole( 'group', {
2301+
name: 'Manage link',
2302+
} );
22632303

22642304
expect( linkPreview ).toHaveClass( 'is-fetching' );
22652305
expect( linkPreview ).not.toHaveClass( 'is-rich' );
@@ -2272,7 +2312,9 @@ describe( 'Rich link previews', () => {
22722312

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

2275-
const linkPreview = screen.getByLabelText( 'Manage link' );
2315+
const linkPreview = screen.getByRole( 'group', {
2316+
name: 'Manage link',
2317+
} );
22762318

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

0 commit comments

Comments
 (0)