Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix(helpers): prefix route path with slash (#382)
Browse files Browse the repository at this point in the history
* fix(helpers): prefix route path with slash

* fix(helpers): do not prefix technical urls
  • Loading branch information
mkucmus authored Feb 13, 2020
1 parent 8d15ea4 commit 43602eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions packages/helpers/__tests__/navigation/getNavigationRoutes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { getNavigationRoutes } from "@shopware-pwa/helpers";
describe("Shopware helpers - navigation", () => {
describe("getNavigationRoutes", () => {
it("should return technical url without prefixing by slash if it exists already", () => {
const SWNavigationResponse = [
{
name: "Cloting",
route: {
path: "/navigation/7d4c679c61d5aa387c80a6a45d75c117"
},
children: null
}
];

const result = getNavigationRoutes(SWNavigationResponse as any);

expect(result).toStrictEqual([
{ routeLabel: "Cloting", routePath: "/navigation/7d4c679c61d5aa387c80a6a45d75c117", children: null }
]);
});
it("should return an array with one object with no children included", () => {
const SWNavigationResponse = [
{
Expand All @@ -15,7 +32,7 @@ describe("Shopware helpers - navigation", () => {
const result = getNavigationRoutes(SWNavigationResponse as any);

expect(result).toStrictEqual([
{ routeLabel: "Cloting", routePath: "clothing/", children: null }
{ routeLabel: "Cloting", routePath: "/clothing/", children: null }
]);
});

Expand All @@ -42,12 +59,12 @@ describe("Shopware helpers - navigation", () => {
expect(result).toStrictEqual([
{
routeLabel: "Cloting",
routePath: "clothing/",
routePath: "/clothing/",
children: [
{
children: undefined,
routeLabel: "Outdoor",
routePath: "clothing/outdoor/"
routePath: "/clothing/outdoor/"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/helpers/src/navigation/getNavigationRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getNavigationRoutes(
route: { path: string; resourceType: string };
}) => ({
routeLabel: element.name,
routePath: element.route.path,
routePath: element.route.path.charAt(0) !== '/' ? `/${element.route.path}` : element.route.path,
children: element.children && getNavigationRoutes(element.children)
})
);
Expand Down

1 comment on commit 43602eb

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for website ready!

Built with commit 9fe59c5

https://shopware-pwa-jxls7xlob.now.sh

Please sign in to comment.