Skip to content

Commit

Permalink
Site Editor: Fix focus mode navigation (#67458)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: carolinan <[email protected]>
  • Loading branch information
4 people authored and michalczaplinski committed Dec 5, 2024
1 parent 5742e9d commit c3529ad
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function useNavigateToEntityRecord() {
const onNavigateToEntityRecord = useCallback(
( params ) => {
history.navigate(
`/${ params.postType }/${ params.id }?canvas=edit&focusMode=true`
`/${ params.postType }/${ params.postId }?canvas=edit&focusMode=true`
);
},
[ history ]
Expand Down
1 change: 1 addition & 0 deletions packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export function useHistory() {
return useMemo(
() => ( {
navigate,
back: history.back,
} ),
[ navigate ]
);
Expand Down
50 changes: 50 additions & 0 deletions test/e2e/specs/site-editor/template-part-focus-mode.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Template Part Focus mode', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyfour' );
} );

test.afterEach( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'Should navigate to template part and back.', async ( {
admin,
page,
editor,
} ) => {
await admin.visitAdminPage( 'site-editor.php?canvas=edit' );
await editor.setPreferences( 'core/edit-site', {
welcomeGuide: false,
} );

// Check that we're editing the template
await expect( page.locator( 'h1' ) ).toContainText( 'Blog Home' );
await expect( page.locator( 'h1' ) ).toContainText( 'Template' );

// Click Template Part
await editor.canvas
.getByRole( 'document', {
name: 'Header',
} )
.click();

// Navigate to Focus mode
await editor.clickBlockToolbarButton( 'Edit' );

// Check if focus mode is active
await expect( page.locator( 'h1' ) ).toContainText( 'Header' );
await expect( page.locator( 'h1' ) ).toContainText( 'Template Part' );

// Go back
await page.getByRole( 'button', { name: 'Back' } ).click();

// Check that we're editing the template
await expect( page.locator( 'h1' ) ).toContainText( 'Blog Home' );
await expect( page.locator( 'h1' ) ).toContainText( 'Template' );
} );
} );

0 comments on commit c3529ad

Please sign in to comment.