Skip to content

Commit

Permalink
[History]: Fix redo after update/publish with transient edits (#37840)
Browse files Browse the repository at this point in the history
* [History]: Fix redo after update/publish with transient edits

* test
  • Loading branch information
ntsekouras authored and Mamaduka committed Feb 16, 2022
1 parent 61232e9 commit ae70ab8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
9 changes: 9 additions & 0 deletions packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,16 @@ export function undo( state = UNDO_INITIAL_STATE, action ) {
// to continue as if we were creating an explicit undo level. This
// will result in an extra undo level being appended with the flattened
// undo values.
// We also have to take into account if the `lastEditAction` had opted out
// of being tracked in undo history, like the action that persists the latest
// content right before saving. In that case we have to update the `lastEditAction`
// to avoid returning early before applying the existing flattened undos.
isCreateUndoLevel = true;
if ( ! lastEditAction.meta.undo ) {
lastEditAction.meta.undo = {
edits: {},
};
}
action = lastEditAction;
} else {
return nextState;
Expand Down
21 changes: 21 additions & 0 deletions packages/e2e-tests/specs/editor/various/undo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,25 @@ describe( 'undo', () => {
// Expect "1".
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should be able to undo and redo when transient changes have been made and we update/publish', async () => {
// Typing consecutive characters in a `Paragraph` block updates the same
// block attribute as in the previous action and results in transient edits
// and skipping `undo` history steps.
const text = 'tonis';
await clickBlockAppender();
await page.keyboard.type( text );
await publishPost();
await pressKeyWithModifier( 'primary', 'z' );
expect( await getEditedPostContent() ).toBe( '' );
await page.waitForSelector(
'.editor-history__redo[aria-disabled="false"]'
);
await page.click( '.editor-history__redo[aria-disabled="false"]' );
expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
"<!-- wp:paragraph -->
<p>tonis</p>
<!-- /wp:paragraph -->"
` );
} );
} );
20 changes: 12 additions & 8 deletions packages/e2e-tests/specs/site-editor/template-revert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,31 @@ const {
disableWelcomeGuide,
} = siteEditor;

const assertSaveButtonIsDisabled = () =>
const assertSaveButtonIsDisabled = async () =>
page.waitForSelector(
'.edit-site-save-button__button[aria-disabled="true"]'
);

const assertSaveButtonIsEnabled = () =>
const assertSaveButtonIsEnabled = async () =>
page.waitForSelector(
'.edit-site-save-button__button[aria-disabled="false"]'
);

const waitForNotice = () => page.waitForSelector( '.components-snackbar' );

const clickButtonInNotice = async () => {
const selector = '.components-snackbar button';
await page.waitForSelector( selector );
await page.click( selector );
};

const clickUndoInHeaderToolbar = () =>
const clickUndoInHeaderToolbar = async () =>
page.click( '.edit-site-header__toolbar button[aria-label="Undo"]' );

const clickRedoInHeaderToolbar = () =>
page.click( '.edit-site-header__toolbar button[aria-label="Redo"]' );
const clickRedoInHeaderToolbar = async () => {
await page.waitForSelector(
'.edit-site-header__toolbar button[aria-label="Redo"][aria-disabled="false"]'
);
return page.click( '.edit-site-header__toolbar button[aria-label="Redo"]' );
};

const undoRevertInHeaderToolbar = async () => {
await clickUndoInHeaderToolbar();
Expand Down Expand Up @@ -72,7 +74,9 @@ const save = async () => {
const revertTemplate = async () => {
await page.click( '.edit-site-document-actions__get-info' );
await page.click( '.edit-site-template-details__revert-button' );
await waitForNotice();
await page.waitForXPath(
'//*[contains(@class, "components-snackbar") and contains(text(), "Template reverted")]'
);
await assertSaveButtonIsEnabled();
};

Expand Down

0 comments on commit ae70ab8

Please sign in to comment.