Skip to content

Commit

Permalink
Add clickBlockToolbarButton end to end test util (#14254)
Browse files Browse the repository at this point in the history
This PR adds an end 2 end test util that allows clicking in a block toolbar button and refactors existing code to use it.

## How has this been tested?
We only need to verify that the end 2 end tests pass.
  • Loading branch information
jorgefilipecosta authored and youknowriad committed Mar 20, 2019
1 parent 03a74ba commit 3c5ed0e
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 91 deletions.
100 changes: 55 additions & 45 deletions packages/e2e-test-utils/README.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions packages/e2e-test-utils/src/click-block-toolbar-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Clicks a block toolbar button.
*
* @param {string} buttonAriaLabel The aria label of the button to click.
*/
export async function clickBlockToolbarButton( buttonAriaLabel ) {
const BLOCK_TOOLBAR_SELECTOR = '.editor-block-toolbar';
const BUTTON_SELECTOR = `${ BLOCK_TOOLBAR_SELECTOR } button[aria-label="${ buttonAriaLabel }"]`;
if ( await page.$( BLOCK_TOOLBAR_SELECTOR ) === null ) {
// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
}
await page.waitForSelector( BUTTON_SELECTOR );
await page.click( BUTTON_SELECTOR );
}
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { activatePlugin } from './activate-plugin';
export { arePrePublishChecksEnabled } from './are-pre-publish-checks-enabled';
export { clearLocalStorage } from './clear-local-storage';
export { clickBlockAppender } from './click-block-appender';
export { clickBlockToolbarButton } from './click-block-toolbar-button';
export { clickButton } from './click-button';
export { clickOnCloseModalButton } from './click-on-close-modal-button';
export { clickOnMoreMenuItem } from './click-on-more-menu-item';
Expand Down
20 changes: 4 additions & 16 deletions packages/e2e-tests/specs/blocks/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import {
clickBlockAppender,
clickBlockToolbarButton,
getEditedPostContent,
createNewPost,
pressKeyTimes,
Expand Down Expand Up @@ -124,11 +125,7 @@ describe( 'List', () => {
await insertBlock( 'List' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
// Pointer device is needed. Shift+Tab won't focus the toolbar.
// To do: fix so Shift+Tab works.
// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
await page.click( 'button[aria-label="Indent list item"]' );
await clickBlockToolbarButton( 'Indent list item' );
await page.keyboard.type( 'two' );
await transformBlockTo( 'Paragraph' );

Expand Down Expand Up @@ -198,11 +195,7 @@ describe( 'List', () => {
await insertBlock( 'List' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
// Pointer device is needed. Shift+Tab won't focus the toolbar.
// To do: fix so Shift+Tab works.
// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
await page.click( 'button[aria-label="Indent list item"]' );
await clickBlockToolbarButton( 'Indent list item' );
await page.keyboard.type( 'two' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'three' );
Expand Down Expand Up @@ -233,12 +226,7 @@ describe( 'List', () => {
await pressKeyWithModifier( 'primary', 'm' );
await page.keyboard.type( '1' );

// Pointer device is needed. Shift+Tab won't focus the toolbar.
// To do: fix so Shift+Tab works.
// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );

await page.click( 'button[aria-label="Convert to ordered list"]' );
await clickBlockToolbarButton( 'Convert to ordered list' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
Expand Down
6 changes: 2 additions & 4 deletions packages/e2e-tests/specs/invalid-block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
createNewPost,
clickBlockAppender,
clickBlockToolbarButton,
} from '@wordpress/e2e-test-utils';

describe( 'invalid blocks', () => {
Expand All @@ -16,10 +17,7 @@ describe( 'invalid blocks', () => {
await clickBlockAppender();
await page.keyboard.type( 'hello' );

// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
// Click the 'more options'
await page.click( 'button[aria-label="More options"]' );
await clickBlockToolbarButton( 'More options' );

// Change to HTML mode and close the options
const changeModeButton = await page.waitForXPath( '//button[text()="Edit as HTML"]' );
Expand Down
6 changes: 2 additions & 4 deletions packages/e2e-tests/specs/links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import {
clickBlockAppender,
clickBlockToolbarButton,
getEditedPostContent,
createNewPost,
pressKeyWithModifier,
Expand Down Expand Up @@ -219,10 +220,7 @@ describe( 'Links', () => {
await clickBlockAppender();
await page.keyboard.type( 'Text' );

// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
await page.waitForSelector( 'button[aria-label="Link"]' );
await page.click( 'button[aria-label="Link"]' );
await clickBlockToolbarButton( 'Link' );

// Typing "left" should not close the dialog
await page.keyboard.press( 'ArrowLeft' );
Expand Down
9 changes: 3 additions & 6 deletions packages/e2e-tests/specs/plugins/format-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
activatePlugin,
clickBlockAppender,
clickBlockToolbarButton,
createNewPost,
deactivatePlugin,
getEditedPostContent,
Expand All @@ -26,19 +27,15 @@ describe( 'Using Format API', () => {
it( 'Format toolbar is present in a paragraph block', async () => {
await clickBlockAppender();
await page.keyboard.type( 'First paragraph' );
// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
expect( await page.$( '[aria-label="Custom Link"]' ) ).not.toBeNull();
await clickBlockToolbarButton( 'Custom Link' );
} );

it( 'Clicking the control wraps the selected text properly with HTML code', async () => {
await clickBlockAppender();
await page.keyboard.type( 'First paragraph' );
await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' );
await pressKeyWithModifier( 'primary', 'A' );
// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
await page.click( '[aria-label="Custom Link"]' );
await clickBlockToolbarButton( 'Custom Link' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
13 changes: 3 additions & 10 deletions packages/e2e-tests/specs/reusable-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
insertBlock,
createNewPost,
clickBlockToolbarButton,
pressKeyWithModifier,
searchForBlock,
getEditedPostContent,
Expand Down Expand Up @@ -34,12 +35,8 @@ describe( 'Reusable Blocks', () => {
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Hello there!' );

// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
await clickBlockToolbarButton( 'More options' );

// Convert block to a reusable block
await page.waitForSelector( 'button[aria-label="More options"]' );
await page.click( 'button[aria-label="More options"]' );
const convertButton = await page.waitForXPath( '//button[text()="Add to Reusable Blocks"]' );
await convertButton.click();

Expand Down Expand Up @@ -80,12 +77,8 @@ describe( 'Reusable Blocks', () => {
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Hello there!' );

// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
await clickBlockToolbarButton( 'More options' );

// Convert block to a reusable block
await page.waitForSelector( 'button[aria-label="More options"]' );
await page.click( 'button[aria-label="More options"]' );
const convertButton = await page.waitForXPath( '//button[text()="Add to Reusable Blocks"]' );
await convertButton.click();

Expand Down
13 changes: 7 additions & 6 deletions packages/e2e-tests/specs/style-variation.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* WordPress dependencies
*/
import { createNewPost, insertBlock, getEditedPostContent } from '@wordpress/e2e-test-utils';
import {
createNewPost,
clickBlockToolbarButton,
insertBlock,
getEditedPostContent,
} from '@wordpress/e2e-test-utils';

describe( 'adding blocks', () => {
beforeAll( async () => {
Expand All @@ -13,12 +18,8 @@ describe( 'adding blocks', () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'Quote content' );

// Press escape to show the block toolbar
await page.keyboard.press( 'Escape' );
await clickBlockToolbarButton( 'Change block type' );

// Use a different style variation
await page.waitForSelector( 'button[aria-label="Change block type"]' );
await page.click( 'button[aria-label="Change block type"]' );
const styleVariations = await page.$$( '.editor-block-styles__item' );
await styleVariations[ 1 ].click();

Expand Down

0 comments on commit 3c5ed0e

Please sign in to comment.