From d8c1f9745a222588b5d0ecf19ec3f44a10f42db1 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 7 Aug 2018 13:48:51 +0200 Subject: [PATCH] chore: Introduce new e2e helper for clicking block appender --- test/e2e/specs/adding-blocks.test.js | 3 ++- test/e2e/specs/adding-inline-tokens.test.js | 9 +++++++-- test/e2e/specs/change-detection.test.js | 5 +++-- test/e2e/specs/formatting-controls.test.js | 9 +++++++-- test/e2e/specs/hooks-api.test.js | 9 ++++++--- test/e2e/specs/managing-links.test.js | 9 ++++++--- test/e2e/specs/multi-block-selection.test.js | 9 +++++++-- test/e2e/specs/nux.test.js | 3 ++- test/e2e/specs/undo.test.js | 5 +++-- test/e2e/specs/writing-flow.test.js | 11 ++++++----- test/e2e/support/utils.js | 7 +++++++ 11 files changed, 56 insertions(+), 23 deletions(-) diff --git a/test/e2e/specs/adding-blocks.test.js b/test/e2e/specs/adding-blocks.test.js index 2cfd3aa37e6f5..02a1ac3348785 100644 --- a/test/e2e/specs/adding-blocks.test.js +++ b/test/e2e/specs/adding-blocks.test.js @@ -2,6 +2,7 @@ * Internal dependencies */ import { + clickBlockAppender, newPost, insertBlock, getEditedPostContent, @@ -28,7 +29,7 @@ describe( 'adding blocks', () => { expect( await page.$( '[data-type="core/paragraph"]' ) ).toBeNull(); // Using the placeholder - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'Paragraph block' ); // Using the slash command diff --git a/test/e2e/specs/adding-inline-tokens.test.js b/test/e2e/specs/adding-inline-tokens.test.js index 4f7c61ee26ba1..0e2e54e62fb0d 100644 --- a/test/e2e/specs/adding-inline-tokens.test.js +++ b/test/e2e/specs/adding-inline-tokens.test.js @@ -9,7 +9,12 @@ import uuid from 'uuid/v4'; /** * Internal dependencies */ -import { newPost, getEditedPostContent, insertBlock } from '../support/utils'; +import { + clickBlockAppender, + getEditedPostContent, + insertBlock, + newPost, +} from '../support/utils'; describe( 'adding inline tokens', () => { beforeAll( async () => { @@ -18,7 +23,7 @@ describe( 'adding inline tokens', () => { it( 'Should insert inline image', async () => { // Create a paragraph. - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'a ' ); await insertBlock( 'Inline Image', 'Inline Elements' ); diff --git a/test/e2e/specs/change-detection.test.js b/test/e2e/specs/change-detection.test.js index e7313ca6621d8..44096b72638ca 100644 --- a/test/e2e/specs/change-detection.test.js +++ b/test/e2e/specs/change-detection.test.js @@ -2,6 +2,7 @@ * Internal dependencies */ import { + clickBlockAppender, newPost, pressWithModifier, ensureSidebarOpened, @@ -137,7 +138,7 @@ describe( 'Change detection', () => { } ); it( 'Should prompt if content added without save', async () => { - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await assertIsDirty( true ); } ); @@ -261,7 +262,7 @@ describe( 'Change detection', () => { // Keyboard shortcut Ctrl+S save. await pressWithModifier( 'Mod', 'S' ); - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); // Allow save to complete. Disabling interception flushes pending. await Promise.all( [ diff --git a/test/e2e/specs/formatting-controls.test.js b/test/e2e/specs/formatting-controls.test.js index 7886416c6a969..e38d3315fe57c 100644 --- a/test/e2e/specs/formatting-controls.test.js +++ b/test/e2e/specs/formatting-controls.test.js @@ -1,7 +1,12 @@ /** * Internal dependencies */ -import { newPost, pressWithModifier, getEditedPostContent } from '../support/utils'; +import { + clickBlockAppender, + getEditedPostContent, + newPost, + pressWithModifier, +} from '../support/utils'; describe( 'Formatting Controls', () => { beforeEach( async () => { @@ -10,7 +15,7 @@ describe( 'Formatting Controls', () => { it( 'Should apply the formatting controls', async () => { // Creating a paragraph block with some content - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'Paragraph to be made "bold"' ); // Selecting some text diff --git a/test/e2e/specs/hooks-api.test.js b/test/e2e/specs/hooks-api.test.js index 3f2e8e8df8418..3af80549b511d 100644 --- a/test/e2e/specs/hooks-api.test.js +++ b/test/e2e/specs/hooks-api.test.js @@ -1,7 +1,10 @@ /** * Internal dependencies */ -import { newPost } from '../support/utils'; +import { + clickBlockAppender, + newPost, +} from '../support/utils'; import { activatePlugin, deactivatePlugin } from '../support/plugins'; describe( 'Using Hooks API', () => { @@ -18,13 +21,13 @@ describe( 'Using Hooks API', () => { } ); it( 'Should contain a reset block button on the sidebar', async () => { - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'First paragraph' ); expect( await page.$( '.edit-post-sidebar .e2e-reset-block-button' ) ).not.toBeNull(); } ); it( 'Pressing reset block button resets the block', async () => { - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'First paragraph' ); const paragraphContent = await page.$eval( 'div[data-type="core/paragraph"] p', ( element ) => element.textContent ); expect( paragraphContent ).toEqual( 'First paragraph' ); diff --git a/test/e2e/specs/managing-links.test.js b/test/e2e/specs/managing-links.test.js index 6a3f1dddccc37..0854b5f9e3d78 100644 --- a/test/e2e/specs/managing-links.test.js +++ b/test/e2e/specs/managing-links.test.js @@ -1,7 +1,10 @@ /** * Internal dependencies */ -import { newPost } from '../support/utils'; +import { + clickBlockAppender, + newPost, +} from '../support/utils'; describe( 'Managing links', () => { beforeEach( async () => { @@ -24,7 +27,7 @@ describe( 'Managing links', () => { it( 'Pressing Left and Esc in Link Dialog in "Fixed to Toolbar" mode', async () => { await setFixedToolbar( true ); - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'Text' ); await page.click( 'button[aria-label="Link"]' ); @@ -42,7 +45,7 @@ describe( 'Managing links', () => { it( 'Pressing Left and Esc in Link Dialog in "Docked Toolbar" mode', async () => { await setFixedToolbar( false ); - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'Text' ); // we need to trigger isTyping = false diff --git a/test/e2e/specs/multi-block-selection.test.js b/test/e2e/specs/multi-block-selection.test.js index 40a30f72b8725..5e8607fd8b295 100644 --- a/test/e2e/specs/multi-block-selection.test.js +++ b/test/e2e/specs/multi-block-selection.test.js @@ -1,7 +1,12 @@ /** * Internal dependencies */ -import { newPost, pressWithModifier, insertBlock } from '../support/utils'; +import { + clickBlockAppender, + insertBlock, + newPost, + pressWithModifier, +} from '../support/utils'; describe( 'Multi-block selection', () => { beforeAll( async () => { @@ -15,7 +20,7 @@ describe( 'Multi-block selection', () => { const multiSelectedCssClass = 'is-multi-selected'; // Creating test blocks - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'First Paragraph' ); await insertBlock( 'Image' ); await insertBlock( 'Quote' ); diff --git a/test/e2e/specs/nux.test.js b/test/e2e/specs/nux.test.js index 3665333d472f4..6fa00755e839b 100644 --- a/test/e2e/specs/nux.test.js +++ b/test/e2e/specs/nux.test.js @@ -2,6 +2,7 @@ * Internal dependencies */ import { + clickBlockAppender, clickOnMoreMenuItem, newPost, } from '../support/utils'; @@ -161,7 +162,7 @@ describe( 'New User Experience (NUX)', () => { // Let's type something so there's content in this post. await page.click( '.editor-post-title__input' ); await page.keyboard.type( 'Post title' ); - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'Post content goes here.' ); // Save the post as a draft. await page.click( '.editor-post-save-draft' ); diff --git a/test/e2e/specs/undo.test.js b/test/e2e/specs/undo.test.js index 36a166288f38c..66e4dc941718c 100644 --- a/test/e2e/specs/undo.test.js +++ b/test/e2e/specs/undo.test.js @@ -2,9 +2,10 @@ * Internal dependencies */ import { + clickBlockAppender, + getEditedPostContent, newPost, pressWithModifier, - getEditedPostContent, } from '../support/utils'; describe( 'undo', () => { @@ -14,7 +15,7 @@ describe( 'undo', () => { it( 'Should undo to expected level intervals', async () => { await page.waitForSelector( '.editor-default-block-appender__content' ); - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'This' ); await page.keyboard.press( 'Enter' ); diff --git a/test/e2e/specs/writing-flow.test.js b/test/e2e/specs/writing-flow.test.js index 7817d76a7d2db..ca67310a986ed 100644 --- a/test/e2e/specs/writing-flow.test.js +++ b/test/e2e/specs/writing-flow.test.js @@ -2,10 +2,11 @@ * Internal dependencies */ import { - newPost, + clickBlockAppender, getEditedPostContent, - pressWithModifier, + newPost, pressTimes, + pressWithModifier, } from '../support/utils'; describe( 'adding blocks', () => { @@ -17,7 +18,7 @@ describe( 'adding blocks', () => { let activeElementText; // Add demo content - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'First paragraph' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( '/columns' ); @@ -73,7 +74,7 @@ describe( 'adding blocks', () => { it( 'should navigate around inline boundaries', async () => { // Add demo content - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await page.keyboard.type( 'First' ); await page.keyboard.press( 'Enter' ); await page.keyboard.type( 'Second' ); @@ -143,7 +144,7 @@ describe( 'adding blocks', () => { it( 'should clean TinyMCE content', async () => { // Ensure no zero-width space character. Notably, this can occur when // save occurs while at an inline boundary edge. - await page.click( '.editor-default-block-appender__content' ); + await clickBlockAppender(); await pressWithModifier( 'mod', 'b' ); expect( await getEditedPostContent() ).toMatchSnapshot(); diff --git a/test/e2e/support/utils.js b/test/e2e/support/utils.js index b19bf5f43fc59..6e8a646d67c5d 100644 --- a/test/e2e/support/utils.js +++ b/test/e2e/support/utils.js @@ -165,6 +165,13 @@ export async function ensureSidebarOpened() { } } +/** + * Clicks the default block appender. + */ +export async function clickBlockAppender() { + await page.click( '.editor-default-block-appender__content' ); +} + /** * Search for block in the global inserter *