Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Dec 5, 2018
1 parent a8ab4e6 commit 1dcd440
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/e2e/specs/__snapshots__/rich-text.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ exports[`RichText should handle change in tag name gracefully 1`] = `
<!-- /wp:heading -->"
`;

exports[`RichText should only mutate text data on input 1`] = `
"<!-- wp:paragraph -->
<p>1<strong>2</strong>34</p>
<!-- /wp:paragraph -->"
`;

exports[`RichText should transform backtick to code 1`] = `
"<!-- wp:paragraph -->
<p>A <code>backtick</code></p>
Expand Down
53 changes: 53 additions & 0 deletions test/e2e/specs/rich-text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,57 @@ describe( 'RichText', () => {

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

it( 'should only mutate text data on input', async () => {
await clickBlockAppender();
await page.keyboard.type( '1' );
await pressWithModifier( 'primary', 'b' );
await page.keyboard.type( '2' );
await pressWithModifier( 'primary', 'b' );
await page.keyboard.type( '3' );

await page.evaluate( () => {
let called;
const { body } = document;
const config = {
attributes: true,
childList: true,
characterData: true,
subtree: true,
};

const mutationObserver = new MutationObserver( ( records ) => {
if ( called ) {
throw new Error( 'Typing should only mutate once.' );
}

if ( records.length > 1 ) {
throw new Error( 'Typing should only mutate once.' );
}

records.forEach( ( record ) => {
if ( record.type !== 'characterData' ) {
throw new Error(
`Typing mutated more than character data: ${ record.type }`
);
}
} );

called = true;
} );

mutationObserver.observe( body, config );

document.addEventListener( 'selectionchange', () => {
// One selection change event is fine.
document.addEventListener( 'selectionchange', () => {
throw new Error( 'Typing should only emit one selection change event.' );
}, { once: true } );
}, { once: true } );
} );

await page.keyboard.type( '4' );

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

0 comments on commit 1dcd440

Please sign in to comment.