diff --git a/packages/e2e-tests/specs/widgets/editing-widgets.test.js b/packages/e2e-tests/specs/widgets/editing-widgets.test.js index 4c0088d4ea4f2..9eab5544c0409 100644 --- a/packages/e2e-tests/specs/widgets/editing-widgets.test.js +++ b/packages/e2e-tests/specs/widgets/editing-widgets.test.js @@ -130,6 +130,16 @@ describe( 'Widgets screen', () => { } it( 'Should insert content using the global inserter', async () => { + const updateButton = await find( { + role: 'button', + name: 'Update', + } ); + + // Update button should start out disabled. + expect( + await updateButton.evaluate( ( button ) => button.disabled ) + ).toBe( true ); + const widgetAreas = await findAll( { role: 'group', name: 'Block: Widget Area', @@ -146,6 +156,11 @@ describe( 'Widgets screen', () => { await addParagraphBlock.click(); + // Adding content should enable the Update button. + expect( + await updateButton.evaluate( ( button ) => button.disabled ) + ).toBe( false ); + let addedParagraphBlockInFirstWidgetArea = await find( { name: /^Empty block/, @@ -215,6 +230,12 @@ describe( 'Widgets screen', () => { // await page.keyboard.type( 'Third Paragraph' ); await saveWidgets(); + + // The Update button should be disabled again after saving. + expect( + await updateButton.evaluate( ( button ) => button.disabled ) + ).toBe( true ); + const serializedWidgetAreas = await getSerializedWidgetAreas(); expect( serializedWidgetAreas ).toMatchInlineSnapshot( ` Object { diff --git a/packages/edit-widgets/src/store/actions.js b/packages/edit-widgets/src/store/actions.js index 555cd2d31d8ba..b09d7b92b9521 100644 --- a/packages/edit-widgets/src/store/actions.js +++ b/packages/edit-widgets/src/store/actions.js @@ -204,12 +204,9 @@ export function* saveWidgetArea( widgetAreaId ) { const widget = preservedRecords[ i ]; const { block, position } = batchMeta[ i ]; - yield dispatch( - 'core/block-editor', - 'updateBlockAttributes', - block.clientId, - { __internalWidgetId: widget.id } - ); + // Set __internalWidgetId on the block. This will be persisted to the + // store when we dispatch receiveEntityRecords( post ) below. + post.blocks[ position ].attributes.__internalWidgetId = widget.id; const error = yield select( 'core',