Skip to content

Commit

Permalink
Fix: Pattern details page backpath (#61174)
Browse files Browse the repository at this point in the history
* Fix: Pattern details page backpath

* Add e2e test

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
  • Loading branch information
3 people committed Apr 30, 2024
1 parent 694447d commit 7fd46f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
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' );
} );
} );

0 comments on commit 7fd46f2

Please sign in to comment.