Skip to content

Commit

Permalink
Merge pull request #103 from ONSdigital/EAR-1699-fix-list-collector-r…
Browse files Browse the repository at this point in the history
…outing

EAR 1699 Fix list collector routing to repeating question
  • Loading branch information
farres1 authored Jul 13, 2022
2 parents e07d14a + db36ae6 commit cf3a9dc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const { flatMap, get, findIndex, isNil } = require("lodash");
const { getPageById } = require("../../../../utils/functions/pageGetters");

const getAbsoluteDestination = (destination, ctx) => {
if (destination.pageId) {
return { block: `block${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 @@ -22,6 +28,7 @@ const getNextPageDestination = (pageId, ctx) => {
sectionId: section.id,
folderId: folder.id,
folderEnabled: folder.enabled,
pageType: page.pageType,
}))
)
);
Expand All @@ -43,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 All @@ -56,7 +67,6 @@ const getLogicalDestination = (pageId, { logical }, ctx) => {
return getNextPageDestination(pageId, ctx);
}


throw new Error(`${logical} is not a valid destination type`);
};

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
16 changes: 16 additions & 0 deletions src/utils/functions/pageGetters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const getPageById = (ctx, pageId) => {
let result;
ctx.questionnaireJson.sections.forEach((section) => {
section.folders.forEach((folder) => {
folder.pages.forEach((page) => {
if (page.id === pageId) {
result = page;
}
});
});
});

return result;
};

module.exports = { getPageById };

0 comments on commit cf3a9dc

Please sign in to comment.