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

[History]: Fix redo after update/publish with transient edits #37840

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
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
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 -->"
` );
} );
} );
23 changes: 13 additions & 10 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 Expand Up @@ -164,15 +168,14 @@ describe( 'Template Revert', () => {
expect( contentBefore ).toBe( contentAfter );
} );

it.skip( 'should show the original content after revert, clicking undo then redo in the header toolbar', async () => {
it( 'should show the original content after revert, clicking undo then redo in the header toolbar', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other changes in this file are not relevant to the PR, but refactored a bit (correct function signatures, etc..).

const contentBefore = await getEditedPostContent();

await addDummyText();
await save();
await revertTemplate();
await save();
await undoRevertInHeaderToolbar();
// there's a bug which probably also exists where the redo button stays disabled.
await clickRedoInHeaderToolbar();

const contentAfter = await getEditedPostContent();
Expand Down
13 changes: 7 additions & 6 deletions test/emptytheme/block-templates/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->

<!-- wp:query {"queryId":1,"query":{"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","sticky":""}} -->
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->

<!-- wp:post-excerpt /-->
<!-- /wp:post-template -->
<!-- /wp:query -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt /-->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->