Skip to content

Commit

Permalink
Add e2e test for undoing widget deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Jun 11, 2021
1 parent 9f74b0c commit d9744d5
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/e2e-tests/specs/widgets/editing-widgets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
showBlockToolbar,
visitAdminPage,
deleteAllWidgets,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';

/**
Expand Down Expand Up @@ -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": "<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
<p>First Paragraph</p>
</div></div>
<div class=\\"widget widget_block widget_text\\"><div class=\\"widget-content\\">
<p>Second Paragraph</p>
</div></div>",
"wp_inactive_widgets": "",
}
` );
} );
} );

/**
Expand Down

0 comments on commit d9744d5

Please sign in to comment.