Skip to content

Commit

Permalink
Add e2e tests to cover onSplit behaviour for headings (WordPress#10326)
Browse files Browse the repository at this point in the history
This ensures that if a user types a heading, then moves the caret to the beginning of the line and presses ENTER, that a paragraph block is created above. Also ensures that when a user presses ENTER at the end of a heading, a paragraph block is created below.
  • Loading branch information
andrewserong committed Feb 13, 2019
1 parent be995ca commit 69fc7cc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`splitting and merging blocks should create a paragraph block above when pressing enter at start of heading 1`] = `
"<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:heading -->
<h2>Abc</h2>
<!-- /wp:heading -->"
`;

exports[`splitting and merging blocks should create a paragraph block below when pressing enter at end of heading 1`] = `
"<!-- wp:heading -->
<h2>Abc</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->"
`;

exports[`splitting and merging blocks should delete an empty first line 1`] = `
"<!-- wp:paragraph -->
<p>First</p>
Expand Down
20 changes: 20 additions & 0 deletions packages/e2e-tests/specs/splitting-merging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,24 @@ describe( 'splitting and merging blocks', () => {

expect( isInDefaultBlock ).toBe( true );
} );

it( 'should create a paragraph block above when pressing enter at start of heading', async () => {
await insertBlock( 'Heading' );
await page.keyboard.type( 'Abc' );
await pressKeyTimes( 'ArrowLeft', 3 );
await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'ArrowUp' );

const activeElementClassList = await page.evaluate( () => document.activeElement.classList );
expect( Object.values( activeElementClassList ) ).toContain( 'wp-block-paragraph' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should create a paragraph block below when pressing enter at end of heading', async () => {
await insertBlock( 'Heading' );
await page.keyboard.type( 'Abc' );
await page.keyboard.press( 'Enter' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );

0 comments on commit 69fc7cc

Please sign in to comment.