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

fix(helpers): prefix route path with slash #382

Merged
merged 2 commits into from
Feb 13, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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