Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add a test
  • Loading branch information
scruffian committed Nov 24, 2022
commit 87efa23dc7ff9a29e63704c38dedba3766860841
70 changes: 70 additions & 0 deletions test/e2e/specs/editor/various/block-locking.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,75 @@ test.describe( 'Block Locking', () => {
<p>Some paragraph</p>
<!-- /wp:paragraph -->` );
} );

test( 'Applying block templates does not create a persistent change in the editor', async ( { editor, page, pageUtils } ) => {
// Create a new block template for the test.
// Should this live in a different file?
await page.evaluate( () => {
const el = window.wp.element.createElement;
const useState = window.wp.element.useState;
const InnerBlocks = window.wp.blockEditor.InnerBlocks;
const TEMPLATE_TWO_PARAGRAPHS = [
[
'core/paragraph',
{
fontSize: 'large',
content: 'One',
},
],
[
'core/paragraph',
{
fontSize: 'large',
content: 'Two',
},
],
];

window.wp.blocks.registerBlockType( 'test/test-inner-blocks-async-template', {
title: 'Test Inner Blocks no locking',
icon: 'cart',
category: 'text',

edit() {

const [ template, setTemplate ] = useState([]);

setInterval( () => {
setTemplate( TEMPLATE_TWO_PARAGRAPHS );
}, 1000 );

return el( InnerBlocks, {
template: template,
} );
},

save() {
return el( InnerBlocks.Content );
},
} );

} );
await editor.insertBlock( { name: 'test/test-inner-blocks-async-template' } );

await expect( await editor.getEditedPostContent() )
.toBe( `<!-- wp:test/test-inner-blocks-async-template /-->` );

const undoButton = await page.locator( '.editor-history__undo' );

// Check is that the undo button is enabled.
// Unfortunately the button does not have a disabled attribute.
await expect( undoButton ).toHaveAttribute( 'aria-disabled', 'false' );

// Undo the change.
await pageUtils.pressKeyWithModifier( 'primary', 'z' );

await expect( await editor.getEditedPostContent() )
.toBe( `` );

// There should be no more undo history.
// Unfortunately the button does not have a disabled attribute.
await expect( undoButton ).toHaveAttribute( 'aria-disabled', 'true' );
} );
} );
} );