Skip to content

Commit

Permalink
Testing: Add Undo test for explicit persistence undo regression
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Apr 14, 2019
1 parent 299313c commit b99908f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/e2e-tests/specs/undo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
getEditedPostContent,
createNewPost,
pressKeyWithModifier,
selectBlockByClientId,
getAllBlocks,
saveDraft,
} from '@wordpress/e2e-test-utils';

describe( 'undo', () => {
Expand Down Expand Up @@ -63,4 +66,36 @@ describe( 'undo', () => {
// After undoing every action, there should be no more undo history.
expect( await page.$( '.editor-history__undo[aria-disabled="true"]' ) ).not.toBeNull();
} );

it( 'should undo for explicit persistence editing post', async () => {
// Regression test: An issue had occurred where the creation of an
// explicit undo level would interfere with blocks values being synced
// correctly to the block editor.
//
// See: https://github.com/WordPress/gutenberg/issues/14950

// Issue is demonstrated from an edited post: create, save, and reload.
await clickBlockAppender();
await page.keyboard.type( 'original' );
await saveDraft();
await page.reload();

// Issue is demonstrated by forcing state merges (multiple inputs) on
// an existing text after a fresh reload.
await selectBlockByClientId( ( await getAllBlocks() )[ 0 ].clientId );
await page.keyboard.type( 'modified' );

// The issue is demonstrated after the one second delay to trigger the
// creation of an explicit undo persistence level.
await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) );

await pressKeyWithModifier( 'primary', 'z' );

// Assert against the _visible_ content. Since editor state with the
// regression present was accurate, it would produce the correct
// content. The issue had manifested in the form of what was shown to
// the user since the blocks state failed to sync to block editor.
const visibleContent = await page.evaluate( () => document.activeElement.textContent );
expect( visibleContent ).toBe( 'original' );
} );
} );

0 comments on commit b99908f

Please sign in to comment.