From 9f74b0c9e239688e9751df27a91d6a62a13aaa24 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Thu, 10 Jun 2021 15:39:10 +1000 Subject: [PATCH 1/3] Don't add undo levels when saving widgets. --- packages/edit-widgets/src/store/actions.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/edit-widgets/src/store/actions.js b/packages/edit-widgets/src/store/actions.js index b09d7b92b9521..624ece78c05ef 100644 --- a/packages/edit-widgets/src/store/actions.js +++ b/packages/edit-widgets/src/store/actions.js @@ -152,7 +152,8 @@ export function* saveWidgetArea( widgetAreaId ) { { ...widget, sidebar: widgetAreaId, - } + }, + { undoIgnore: true } ); const hasEdits = yield select( @@ -242,7 +243,8 @@ export function* saveWidgetArea( widgetAreaId ) { widgetAreaId, { widgets: sidebarWidgetsIds, - } + }, + { undoIgnore: true } ); yield* trySaveWidgetArea( widgetAreaId ); From d9744d5643490a6b22c44760ce72b34cf0dfb94e Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 11 Jun 2021 12:24:27 +1000 Subject: [PATCH 2/3] Add e2e test for undoing widget deletion. --- .../specs/widgets/editing-widgets.test.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/packages/e2e-tests/specs/widgets/editing-widgets.test.js b/packages/e2e-tests/specs/widgets/editing-widgets.test.js index 9eab5544c0409..d51acbbf2331e 100644 --- a/packages/e2e-tests/specs/widgets/editing-widgets.test.js +++ b/packages/e2e-tests/specs/widgets/editing-widgets.test.js @@ -9,6 +9,7 @@ import { showBlockToolbar, visitAdminPage, deleteAllWidgets, + pressKeyWithModifier, } from '@wordpress/e2e-test-utils'; /** @@ -694,6 +695,63 @@ describe( 'Widgets screen', () => { } ` ); } ); + + it( 'Allows widget deletion to be undone', async () => { + const [ firstWidgetArea ] = await findAll( { + role: 'group', + name: 'Block: Widget Area', + } ); + + let addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' ); + await addParagraphBlock.click(); + + let addedParagraphBlockInFirstWidgetArea = await find( + { + name: /^Empty block/, + selector: '[data-block][data-type="core/paragraph"]', + }, + { + root: firstWidgetArea, + } + ); + await addedParagraphBlockInFirstWidgetArea.focus(); + await page.keyboard.type( 'First Paragraph' ); + + addParagraphBlock = await getBlockInGlobalInserter( 'Paragraph' ); + await addParagraphBlock.click(); + + addedParagraphBlockInFirstWidgetArea = await firstWidgetArea.$( + '[data-block][data-type="core/paragraph"][aria-label^="Empty block"]' + ); + await addedParagraphBlockInFirstWidgetArea.focus(); + await page.keyboard.type( 'Second Paragraph' ); + + await saveWidgets(); + + // Delete the last block and save again. + await pressKeyWithModifier( 'access', 'z' ); + await saveWidgets(); + + // Undo block deletion and save again + await pressKeyWithModifier( 'primary', 'z' ); + await saveWidgets(); + + // Reload the page to make sure changes were actually saved. + await page.reload(); + + const serializedWidgetAreas = await getSerializedWidgetAreas(); + expect( serializedWidgetAreas ).toMatchInlineSnapshot( ` + Object { + "sidebar-1": "
+

First Paragraph

+
+
+

Second Paragraph

+
", + "wp_inactive_widgets": "", + } + ` ); + } ); } ); /** From 5ceeec06fbca46dbc73fe39cbe614ef0803059bc Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 11 Jun 2021 15:10:17 +1000 Subject: [PATCH 3/3] Update failing snapshot --- packages/e2e-tests/specs/widgets/editing-widgets.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/e2e-tests/specs/widgets/editing-widgets.test.js b/packages/e2e-tests/specs/widgets/editing-widgets.test.js index d51acbbf2331e..b5d7e480d9d8d 100644 --- a/packages/e2e-tests/specs/widgets/editing-widgets.test.js +++ b/packages/e2e-tests/specs/widgets/editing-widgets.test.js @@ -748,7 +748,6 @@ describe( 'Widgets screen', () => {

Second Paragraph

", - "wp_inactive_widgets": "", } ` ); } );