Skip to content

Commit

Permalink
Fix test and tidy code
Browse files Browse the repository at this point in the history
  • Loading branch information
farres1 committed Jul 13, 2022
1 parent e8743a1 commit db36ae6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ const { flatMap, get, findIndex, isNil } = require("lodash");
const { getPageById } = require("../../../../utils/functions/pageGetters");

const getAbsoluteDestination = (destination, ctx) => {
const page = getPageById(ctx, destination.pageId);
if (destination.pageId && page.pageType !== "ListCollectorPage") {
return { block: `block${destination.pageId}` };
}
if (destination.pageId && page.pageType === "ListCollectorPage") {
return { block: `block-driving${destination.pageId}` };
if (destination.pageId) {
const page = getPageById(ctx, destination.pageId);
if (page.pageType === "ListCollectorPage") {
return { block: `block-driving${destination.pageId}` };
} else {
return { block: `block${destination.pageId}` };
}
}

// Get first folder in the section when routing to sections
Expand All @@ -27,6 +28,7 @@ const getNextPageDestination = (pageId, ctx) => {
sectionId: section.id,
folderId: folder.id,
folderEnabled: folder.enabled,
pageType: page.pageType,
}))
)
);
Expand All @@ -48,7 +50,11 @@ const getNextPageDestination = (pageId, ctx) => {
} else if (currentPage.sectionId !== nextPage.sectionId) {
return { group: `group${nextPage.sectionId}` };
} else {
return { block: `block${nextPage.id}` };
if (nextPage.pageType === "ListCollectorPage") {
return { block: `block-driving${nextPage.id}` };
} else {
return { block: `block${nextPage.id}` };
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ const {

describe("Translation of a routing destination", () => {
it("should translate an absolute destination to another Page", () => {
const ctx = {
questionnaireJson: {
sections: [{ folders: [{ pages: [{ id: "2" }] }] }],
},
};
const authorDestination = {
pageId: "2",
};
expect(translateRoutingDestination(authorDestination)).toMatchObject({
expect(
translateRoutingDestination(
authorDestination,
authorDestination.pageId,
ctx
)
).toMatchObject({
block: "block2",
});
});
Expand Down

0 comments on commit db36ae6

Please sign in to comment.