Skip to content
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

Fix: Pattern details page backpath #61174

Merged
merged 2 commits into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -23,7 +23,7 @@ export default function SidebarNavigationScreenPattern() {
const history = useHistory();
const location = useLocation();
const {
params: { postType, postId },
params: { postType, postId, categoryId, categoryType },
} = location;
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );

Expand All @@ -48,10 +48,14 @@ export default function SidebarNavigationScreenPattern() {
* Depending on whether the theme supports block-template-parts, we go back to Patterns or Template screens.
* This is temporary. We aim to consolidate to /patterns.
*/
const backPath =
isTemplatePartsMode && postType === 'wp_template_part'
? { path: '/wp_template_part/all' }
: { path: '/patterns' };
const backPath = {
categoryId,
categoryType,
path:
isTemplatePartsMode && postType === 'wp_template_part'
? '/wp_template_part/all'
: '/patterns',
};

return (
<SidebarNavigationScreen
Expand Down
26 changes: 26 additions & 0 deletions test/e2e/specs/site-editor/site-editor-url-navigation.spec.js
Expand Up @@ -66,4 +66,30 @@ test.describe( 'Site editor url navigation', () => {
'/wp-admin/site-editor.php?postId=emptytheme%2F%2Fdemo&postType=wp_template_part&canvas=edit'
);
} );

test( 'The Patterns page should keep the previously selected template part category', async ( {
admin,
page,
} ) => {
await admin.visitSiteEditor();
const navigation = page.getByRole( 'region', {
name: 'Navigation',
} );
await navigation.getByRole( 'button', { name: 'Patterns' } ).click();
await navigation.getByRole( 'button', { name: 'General' } ).click();
await page
.getByRole( 'region', {
name: 'Patterns content',
} )
.getByLabel( 'header', { exact: true } )
.click();
await expect(
page.getByRole( 'region', { name: 'Editor content' } )
).toBeVisible();
await page.getByRole( 'button', { name: 'Open navigation' } ).click();
await navigation.getByRole( 'button', { name: 'Back' } ).click();
await expect(
navigation.getByRole( 'button', { name: 'General' } )
).toHaveAttribute( 'aria-current', 'true' );
} );
} );