Skip to content

Commit

Permalink
Fix Custom Views locator hook (#3280)
Browse files Browse the repository at this point in the history
* fix(application-component): fix custom views locator hook

* fix(visual-testing-app): fix custom views vrts

* chore: changeset added
  • Loading branch information
CarlosCortizasCT authored Oct 19, 2023
1 parent 3e11bae commit 0c49364
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-flies-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/application-components': patch
---

Fix url matching in `useCustomViewLocator` hook.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const mockConfig = {
'locator-a': '/route/locator-a',
'locator-b': '/route/locator-b',
'locator-c': '/route/locator-c',
'locator-nested': '/route/locator-a/nested',
};

const createMockHistory = (location: string) =>
Expand All @@ -21,10 +22,11 @@ const render = (location: string) =>

describe('useCustomViewLocatorSelector', () => {
it.each`
location | expectedLocator
${'/route/locator-a'} | ${'locator-a'}
${'/route/locator-b'} | ${'locator-b'}
${'/route/locator-c'} | ${'locator-c'}
location | expectedLocator
${'/route/locator-a'} | ${'locator-a'}
${'/route/locator-b'} | ${'locator-b'}
${'/route/locator-c'} | ${'locator-c'}
${'/route/locator-a/nested'} | ${'locator-nested'}
`(
'should return the view locator code based on the current location',
({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const useCustomViewLocatorSelector = (
return matchPath(location.pathname, {
// strip the search, otherwise the path won't match
path: pathWithoutSearch(locator),
exact: false,
exact: true,
strict: false,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export const Component = () => (
<Spec label="TabularDetailPage - with Custom Views selector" size="xl">
<TabularDetailPageContainer
customViewLocatorCodes={{
[CUSTOM_VIEW_LOCATORS.productDetails]: routePath,
[CUSTOM_VIEW_LOCATORS.productDetails]: '/tabular-detail-page/tab-one',
}}
>
<Content />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const Component = () => (
<Spec label="TabularMainPage - with Custom Views selector" size="xl">
<TabularMainPageContainer
customViewLocatorCodes={{
[CUSTOM_VIEW_LOCATORS.productDetails]: routePath,
[CUSTOM_VIEW_LOCATORS.productDetails]: '/tabular-main-page/tab-one',
}}
>
<Content />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ export const Component = () => (
spec: (
<ModalPageWithPortalParentSelector
customViewLocatorCodes={{
[CUSTOM_VIEW_LOCATORS.productDetails]: routePath,
[CUSTOM_VIEW_LOCATORS.productDetails]:
'/tabular-modal-page/tabular-modal-page-default-with-custom-views-selector/tab-one',
}}
>
<Content />
Expand Down

1 comment on commit 0c49364

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-r8v2wp07z-commercetools.vercel.app

Built with commit 0c49364.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.