-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark applying block templates not persistent (#45843)
* mark applying templates as a not persistent change * Add a test * Update e2e test - Move block code to test plugin file - Move from block locking test file to a new inner blocks template file - Update test logic to test post is not dirty on a fresh load - Rename post type templates file to distinguish from inner blocks templates file * Fix tests - Avoid saving inner blocks of the test block, as otherwise template sync won't run - Wait for template resolution before saving, as the test seems flakey otherwise * make more explicit assetions Co-authored-by: Ben Dwyer <ben@scruffian.com> Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
- Loading branch information
1 parent
9aff35e
commit e87b3fe
Showing
5 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
test/e2e/specs/editor/various/inner-blocks-templates.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Inner blocks templates', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await requestUtils.activatePlugin( | ||
'gutenberg-test-inner-blocks-templates' | ||
); | ||
} ); | ||
|
||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deactivatePlugin( | ||
'gutenberg-test-inner-blocks-templates' | ||
); | ||
} ); | ||
|
||
test( 'applying block templates asynchronously does not create a persistent change in the editor', async ( { | ||
editor, | ||
page, | ||
} ) => { | ||
await editor.insertBlock( { | ||
name: 'test/test-inner-blocks-async-template', | ||
} ); | ||
|
||
const blockWithTemplateContent = page.locator( | ||
'role=document[name="Block: Test Inner Blocks Async Template"i] >> text=OneTwo' | ||
); | ||
|
||
// The block template content appears asynchronously, so wait for it. | ||
await expect( blockWithTemplateContent ).toBeVisible(); | ||
|
||
// Publish the post, then reload. | ||
await editor.publishPost(); | ||
await page.reload(); | ||
|
||
// Wait for the block that was inserted to appear with its templated content. | ||
await expect( blockWithTemplateContent ).toBeVisible(); | ||
|
||
// The template resolution shouldn't cause the post to be dirty. | ||
const editorTopBar = page.locator( | ||
'role=region[name="Editor top bar"i]' | ||
); | ||
const undoButton = editorTopBar.locator( 'role=button[name="Undo"i]' ); | ||
const updateButton = editorTopBar.locator( | ||
'role=button[name="Update"i]' | ||
); | ||
await expect( undoButton ).toHaveAttribute( 'aria-disabled', 'true' ); | ||
await expect( updateButton ).toHaveAttribute( 'aria-disabled', 'true' ); | ||
} ); | ||
} ); |