diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js index 8b459e3ea6a91a..ec80b7054c6db4 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pattern/index.js @@ -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 ) ); @@ -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 ( { '/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' ); + } ); } );