Skip to content

Commit 62f2353

Browse files
Link Control test migration: Should contain a label when it should open in a new tab (#51001)
* fixed utils * update snapshots, commented waitForURLFieldAutoFocus * remove appender function * removed snapshots * migrated test * removed old test * removed old snapshots * use proper locator instead of a class * use locators instead of tabbing around, remove appender util function * simplified test * removed snapshots and updated locator of save button * add comment
1 parent 069d541 commit 62f2353

File tree

3 files changed

+64
-89
lines changed

3 files changed

+64
-89
lines changed

packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap

-12
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,3 @@ exports[`Links can be removed 1`] = `
4747
<p>This is Gutenberg</p>
4848
<!-- /wp:paragraph -->"
4949
`;
50-
51-
exports[`Links should contain a label when it should open in a new tab 1`] = `
52-
"<!-- wp:paragraph -->
53-
<p>This is <a href="http://w.org" target="_blank" rel="noreferrer noopener">WordPress</a></p>
54-
<!-- /wp:paragraph -->"
55-
`;
56-
57-
exports[`Links should contain a label when it should open in a new tab 2`] = `
58-
"<!-- wp:paragraph -->
59-
<p>This is <a href="http://wordpress.org" target="_blank" rel="noreferrer noopener">WordPress</a></p>
60-
<!-- /wp:paragraph -->"
61-
`;

packages/e2e-tests/specs/editor/various/links.test.js

-77
Original file line numberDiff line numberDiff line change
@@ -478,83 +478,6 @@ describe( 'Links', () => {
478478
);
479479
} );
480480

481-
it( 'should contain a label when it should open in a new tab', async () => {
482-
await clickBlockAppender();
483-
await page.keyboard.type( 'This is WordPress' );
484-
// Select "WordPress".
485-
await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' );
486-
await pressKeyWithModifier( 'primary', 'k' );
487-
await waitForURLFieldAutoFocus();
488-
await page.keyboard.type( 'w.org' );
489-
490-
// Link settings open
491-
await page.keyboard.press( 'Tab' );
492-
await page.keyboard.press( 'Space' );
493-
494-
// Navigate to and toggle the "Open in new tab" checkbox.
495-
await page.keyboard.press( 'Tab' );
496-
await page.keyboard.press( 'Space' );
497-
498-
// Confirm that focus was not prematurely returned to the paragraph on
499-
// a changing value of the setting.
500-
await page.waitForSelector(
501-
':focus.components-checkbox-control__input'
502-
);
503-
504-
// Submit link. Expect that "Open in new tab" would have been applied
505-
// immediately.
506-
await page.keyboard.press( 'Tab' );
507-
await page.keyboard.press( 'Enter' );
508-
509-
// Wait for Gutenberg to finish the job.
510-
await page.waitForXPath(
511-
'//a[contains(@href,"w.org") and @target="_blank"]'
512-
);
513-
514-
expect( await getEditedPostContent() ).toMatchSnapshot();
515-
516-
// Regression Test: This verifies that the UI is updated according to
517-
// the expected changed values, where previously the value could have
518-
// fallen out of sync with how the UI is displayed (specifically for
519-
// collapsed selections).
520-
//
521-
// See: https://github.com/WordPress/gutenberg/pull/15573
522-
523-
// Move caret back into the link.
524-
await page.keyboard.press( 'ArrowLeft' );
525-
await page.keyboard.press( 'ArrowLeft' );
526-
527-
// Edit link.
528-
await pressKeyWithModifier( 'primary', 'k' );
529-
await waitForURLFieldAutoFocus();
530-
await pressKeyWithModifier( 'primary', 'a' );
531-
await page.keyboard.type( 'wordpress.org' );
532-
533-
// Update the link.
534-
await page.keyboard.press( 'Enter' );
535-
536-
// Navigate back to the popover.
537-
await page.keyboard.press( 'ArrowLeft' );
538-
await page.keyboard.press( 'ArrowLeft' );
539-
540-
// Navigate back to inputs to verify appears as changed.
541-
await pressKeyWithModifier( 'primary', 'k' );
542-
await waitForURLFieldAutoFocus();
543-
544-
// Navigate to the "Open in new tab" checkbox.
545-
await page.keyboard.press( 'Tab' );
546-
await page.keyboard.press( 'Tab' );
547-
// Uncheck the checkbox.
548-
await page.keyboard.press( 'Space' );
549-
550-
// Wait for Gutenberg to finish the job.
551-
await page.waitForXPath(
552-
'//a[contains(@href,"wordpress.org") and not(@target)]'
553-
);
554-
555-
expect( await getEditedPostContent() ).toMatchSnapshot();
556-
} );
557-
558481
describe( 'Editing link text', () => {
559482
it( 'should not display text input when initially creating the link', async () => {
560483
// Create a block with some text.

test/e2e/specs/editor/blocks/links.spec.js

+64
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,68 @@ test.describe( 'Links', () => {
6666
},
6767
] );
6868
} );
69+
70+
test( 'can update the url of an existing link', async ( {
71+
page,
72+
editor,
73+
pageUtils,
74+
} ) => {
75+
// Create a block with some text.
76+
await editor.insertBlock( {
77+
name: 'core/paragraph',
78+
} );
79+
await page.keyboard.type( 'This is WordPress' );
80+
// Select "WordPress".
81+
await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' );
82+
await pageUtils.pressKeys( 'primary+k' );
83+
await page.keyboard.type( 'w.org' );
84+
85+
await page
86+
//TODO: change to a better selector when https://github.com/WordPress/gutenberg/issues/51060 is resolved.
87+
.locator( '.block-editor-link-control' )
88+
.getByRole( 'button', { name: 'Save' } )
89+
.click();
90+
91+
await expect.poll( editor.getBlocks ).toMatchObject( [
92+
{
93+
name: 'core/paragraph',
94+
attributes: {
95+
content: 'This is <a href="http://w.org">WordPress</a>',
96+
},
97+
},
98+
] );
99+
100+
// Move caret back into the link.
101+
await page.keyboard.press( 'ArrowLeft' );
102+
await page.keyboard.press( 'ArrowLeft' );
103+
104+
// Edit link.
105+
await pageUtils.pressKeys( 'primary+k' );
106+
await pageUtils.pressKeys( 'primary+a' );
107+
await page.keyboard.type( 'wordpress.org' );
108+
109+
// Update the link.
110+
await page.keyboard.press( 'Enter' );
111+
112+
// Navigate back to the popover.
113+
await page.keyboard.press( 'ArrowLeft' );
114+
await page.keyboard.press( 'ArrowLeft' );
115+
116+
// Navigate back to inputs to verify appears as changed.
117+
await pageUtils.pressKeys( 'primary+k' );
118+
const urlInputValue = await page
119+
.getByPlaceholder( 'Search or type url' )
120+
.inputValue();
121+
expect( urlInputValue ).toContain( 'wordpress.org' );
122+
123+
await expect.poll( editor.getBlocks ).toMatchObject( [
124+
{
125+
name: 'core/paragraph',
126+
attributes: {
127+
content:
128+
'This is <a href="http://wordpress.org">WordPress</a>',
129+
},
130+
},
131+
] );
132+
} );
69133
} );

0 commit comments

Comments
 (0)