Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: Add Undo test for explicit persistence undo regression #15049

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );
} );
} );