Skip to content

Commit

Permalink
Fix: Intermittent end 2 end test on the buttons block
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jan 13, 2020
1 parent 06782e1 commit 55ed619
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
12 changes: 11 additions & 1 deletion packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class URLInput extends Component {
onKeyDown( event ) {
const { showSuggestions, selectedSuggestion, suggestions, loading } = this.state;

const setCurrentInputAsLink = () => {
const { value } = this.props;
this.selectLink( { url: value, title: value } );
};
// If the suggestions are not shown or loading, we shouldn't handle the arrow keys
// We shouldn't preventDefault to allow block arrow keys navigation
if (
Expand Down Expand Up @@ -179,6 +183,10 @@ class URLInput extends Component {
}
break;
}
case ENTER: {
// If pressing enter before suggestions are loaded use the current input as the link.
setCurrentInputAsLink();
}
}

return;
Expand Down Expand Up @@ -215,8 +223,10 @@ class URLInput extends Component {
}
case ENTER: {
if ( this.state.selectedSuggestion !== null ) {
event.stopPropagation();
this.selectLink( suggestion );
} else {
// If pressing enter and no suggestion is selected use the current input as the link.
setCurrentInputAsLink();
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`Buttons can jump to the link editor using the keyboard shortcut 1`] = `
"<!-- wp:buttons -->
<div class=\\"wp-block-buttons\\"><!-- wp:button -->
<div class=\\"wp-block-button\\"><a class=\\"wp-block-button__link\\">WordPress</a></div>
<div class=\\"wp-block-button\\"><a class=\\"wp-block-button__link\\" href=\\"https://www.wordpress.org/\\" title=\\"https://www.wordpress.org/\\">WordPress</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->"
`;
Expand Down
3 changes: 1 addition & 2 deletions packages/e2e-tests/specs/editor/blocks/buttons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ describe( 'Buttons', () => {
await insertBlock( 'Buttons' );
await page.keyboard.type( 'WordPress' );
await pressKeyWithModifier( 'primary', 'k' );
await page.keyboard.type( 'https://wwww.wordpress.org/' );
await page.keyboard.type( 'https://www.wordpress.org/' );
await page.keyboard.press( 'Enter' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
8 changes: 1 addition & 7 deletions packages/e2e-tests/specs/editor/blocks/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function updateActiveNavigationLink( { url, label } ) {
await page.type( 'input[placeholder="Search or type url"]', url );
// Wait for the autocomplete suggestion item to appear.
await page.waitForXPath( `//span[@class="block-editor-link-control__search-item-title"]/mark[text()="${ url }"]` );
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.press( 'Enter' );
}

Expand Down Expand Up @@ -134,12 +135,5 @@ describe( 'Navigation', () => {

// Expect a Navigation Block with two Navigation Links in the snapshot.
expect( await getEditedPostContent() ).toMatchSnapshot();

// TODO - this is needed currently because when adding a link using the suggestion list,
// a submit button is used. The form that the submit button is in is unmounted when submission
// occurs, resulting in a warning 'Form submission canceled because the form is not connected'
// in Chrome.
// Ideally, the suggestions wouldn't be implemented using submit buttons.
expect( console ).toHaveWarned();
} );
} );

0 comments on commit 55ed619

Please sign in to comment.