Skip to content

Commit

Permalink
chore: Introduce new e2e helper for clicking block appender
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Aug 8, 2018
1 parent 0e7977c commit d8c1f97
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 23 deletions.
3 changes: 2 additions & 1 deletion test/e2e/specs/adding-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Internal dependencies
*/
import {
clickBlockAppender,
newPost,
insertBlock,
getEditedPostContent,
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions test/e2e/specs/adding-inline-tokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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' );
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/specs/change-detection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Internal dependencies
*/
import {
clickBlockAppender,
newPost,
pressWithModifier,
ensureSidebarOpened,
Expand Down Expand Up @@ -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 );
} );
Expand Down Expand Up @@ -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( [
Expand Down
9 changes: 7 additions & 2 deletions test/e2e/specs/formatting-controls.test.js
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/specs/hooks-api.test.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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' );
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/specs/managing-links.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* Internal dependencies
*/
import { newPost } from '../support/utils';
import {
clickBlockAppender,
newPost,
} from '../support/utils';

describe( 'Managing links', () => {
beforeEach( async () => {
Expand All @@ -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"]' );

Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions test/e2e/specs/multi-block-selection.test.js
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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' );
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/specs/nux.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Internal dependencies
*/
import {
clickBlockAppender,
clickOnMoreMenuItem,
newPost,
} from '../support/utils';
Expand Down Expand Up @@ -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' );
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/specs/undo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Internal dependencies
*/
import {
clickBlockAppender,
getEditedPostContent,
newPost,
pressWithModifier,
getEditedPostContent,
} from '../support/utils';

describe( 'undo', () => {
Expand All @@ -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' );
Expand Down
11 changes: 6 additions & 5 deletions test/e2e/specs/writing-flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* Internal dependencies
*/
import {
newPost,
clickBlockAppender,
getEditedPostContent,
pressWithModifier,
newPost,
pressTimes,
pressWithModifier,
} from '../support/utils';

describe( 'adding blocks', () => {
Expand All @@ -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' );
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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();

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit d8c1f97

Please sign in to comment.