-
Notifications
You must be signed in to change notification settings - Fork 67
fix: when show template is enabled, insert in post content area instead #3737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,3 +216,101 @@ test.describe( 'Design Library', () => { | |
| await expect( backgroundToggle ).toHaveJSProperty( 'checked', ! wasChecked ) | ||
| } ) | ||
| } ) | ||
|
|
||
| const activateBlockTheme = async requestUtils => { | ||
| const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ) | ||
| const active = themes.find( theme => theme.status === 'active' ) | ||
| if ( active?.is_block_theme ) { | ||
| return active.stylesheet | ||
| } | ||
|
|
||
| for ( const slug of [ 'twentytwentyfive', 'twentytwentyfour' ] ) { | ||
| try { | ||
| await requestUtils.activateTheme( slug ) | ||
| return slug | ||
| } catch { | ||
| // Try the next bundled block theme. | ||
| } | ||
| } | ||
|
|
||
| throw new Error( 'Show Template e2e needs a block theme (Twenty Twenty-Five or Twenty Twenty-Four).' ) | ||
| } | ||
|
|
||
| /** | ||
| * Show Template puts the editor in `template-locked` mode. The canvas root is | ||
| * then the locked page template, so `insertBlocks()` without a | ||
| * `core/post-content` root cannot place the Design Library block and the | ||
| * toolbar button never finds a button to open the modal. | ||
| */ | ||
| const enableShowTemplate = async ( page: Page ) => { | ||
| await page.waitForFunction( | ||
| () => window?.wp?.data?.select?.( 'core/editor' )?.getRenderingMode | ||
| ) | ||
|
|
||
| const alreadyLocked = await page.evaluate( () => | ||
| window.wp.data.select( 'core/editor' ).getRenderingMode() === 'template-locked' | ||
| ) | ||
|
|
||
| if ( ! alreadyLocked ) { | ||
| await page.evaluate( () => { | ||
| window.wp.data.dispatch( 'core/editor' ).setRenderingMode( 'template-locked' ) | ||
| } ) | ||
| } | ||
|
|
||
| await expect.poll( async () => { | ||
| return page.evaluate( () => window.wp.data.select( 'core/editor' ).getRenderingMode() ) | ||
| } ).toBe( 'template-locked' ) | ||
|
|
||
| // The lock is only real once the template's post content area is in the tree. | ||
| await expect.poll( async () => { | ||
| return page.evaluate( () => | ||
| window.wp.data.select( 'core/block-editor' ).getBlocksByName( 'core/post-content' )?.length || 0 | ||
| ) | ||
| } ).toBeGreaterThan( 0 ) | ||
| } | ||
|
|
||
| test.describe( 'Design Library with Show Template', () => { | ||
| let pid = null | ||
| let originalTheme = null | ||
|
|
||
| test.beforeEach( async ( { | ||
| admin, editor, page, requestUtils, | ||
| } ) => { | ||
| const themes = await requestUtils.rest( { path: '/wp/v2/themes' } ) | ||
| originalTheme = themes.find( theme => theme.status === 'active' )?.stylesheet | ||
| await activateBlockTheme( requestUtils ) | ||
|
|
||
| await admin.createNewPost( { | ||
| postType: 'page', | ||
| title: 'Design Library Show Template', | ||
| } ) | ||
| await editor.saveDraft() | ||
| const postQuery = new URL( editor.page.url() ).search | ||
| pid = new URLSearchParams( postQuery ).get( 'post' ) | ||
|
|
||
| await enableShowTemplate( page ) | ||
| } ) | ||
|
|
||
| test.afterEach( async ( { requestUtils } ) => { | ||
| if ( pid ) { | ||
| try { | ||
| await requestUtils.deletePost( pid, 'pages' ) | ||
| } catch { | ||
| // Best-effort cleanup. | ||
| } | ||
| } | ||
| if ( originalTheme ) { | ||
| try { | ||
| await requestUtils.activateTheme( originalTheme ) | ||
| } catch { | ||
| // Best-effort restore so later specs keep the original theme. | ||
| } | ||
| } | ||
| } ) | ||
|
|
||
| test( 'opens when Show Template is enabled on a page', async ( { | ||
| page, | ||
| } ) => { | ||
| await openDesignLibrary( page ) | ||
| } ) | ||
| } ) | ||
|
Comment on lines
+272
to
+316
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert selected Design Library content is inside
🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Do not hide theme restoration failures.
If
activateTheme( originalTheme )rejects,afterEachcompletes while the changed theme remains active. The Playwright configuration uses one worker and oneWP_BASE_URL, and no later fixture or global setup resets the theme. Later specs can therefore run against the wrong WordPress theme and fail.Proposed fix
if ( originalTheme ) { - try { - await requestUtils.activateTheme( originalTheme ) - } catch { - // Best-effort restore so later specs keep the original theme. - } + await requestUtils.activateTheme( originalTheme ) }🤖 Prompt for AI Agents