diff --git a/packages/e2e-tests/specs/widgets/editing-widgets.test.js b/packages/e2e-tests/specs/widgets/editing-widgets.test.js index 9eab5544c04097..b5d7e480d9d8de 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,62 @@ 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": "
+ ", + } + ` ); + } ); } ); /** diff --git a/packages/edit-widgets/src/store/actions.js b/packages/edit-widgets/src/store/actions.js index c3ae54eb619aeb..179723a85488e2 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 );