Skip to content

Commit

Permalink
Merge pull request #3070 from ONSdigital/EAR-2192-additional-content-…
Browse files Browse the repository at this point in the history
…on-collector-quest

EAR 2192 additional content on list collector page
  • Loading branch information
shelleytruong authored Oct 9, 2023
2 parents b238642 + c353a05 commit 37c7bcd
Show file tree
Hide file tree
Showing 20 changed files with 636 additions and 33 deletions.
221 changes: 221 additions & 0 deletions eq-author-api/migrations/addAdditionalContentsToAddItemPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
const addAdditionalContentsToAddItemPage = require("./addAdditonalContentsToAddItemPage");

describe("addAdditionalContentsToAddItemPage", () => {
let questionnaire;

beforeEach(() => {
questionnaire = {
sections: [
{
id: "section-1",
folders: [
{
id: "folder-1",
listId: "list-1",
pages: [
{
id: "qualifier-page-1",
pageType: "ListCollectorQualifierPage",
answers: [
{
id: "answer-1",
type: "Radio",
options: [
{
id: "qualifier-option-positive-1",
description: "Qualifier positive description",
},
{
id: "qualifier-option-negative-1",
description: "Qualifier negative description",
},
],
},
],
},
{
id: "add-item-page-1",
pageType: "ListCollectorAddItemPage",
pageDescription: `Add item description`,
},
{
id: "confirmation-page-1",
pageType: "ListCollectorConfirmationPage",
pageDescription: `Confirmation description`,
answers: [
{
id: "answer-2",
type: "Radio",
options: [
{
id: "confirmation-option-positive-1",
description: "Confirmation positive description",
},
{
id: "confirmation-option-negative-1",
description: "Confirmation negative description",
},
],
},
],
},
],
},
],
},
],
};
});

describe("Additional Contents", () => {
it("should add additional content fields to the add item list collector page", () => {
const updatedQuestionnaire =
addAdditionalContentsToAddItemPage(questionnaire);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].descriptionEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].descriptionEnabled
).toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].guidanceEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].guidanceEnabled
).toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].definitionEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].definitionEnabled
).toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1]
.additionalInfoEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1]
.additionalInfoEnabled
).toBe(false);
});

it("should not change additional content fields to the add item list collector page if additional content fields are defined", () => {
questionnaire.sections[0].folders[0].pages[1].descriptionEnabled = true;
questionnaire.sections[0].folders[0].pages[1].guidanceEnabled = true;
questionnaire.sections[0].folders[0].pages[1].additionalInfoEnabled = true;
const updatedQuestionnaire =
addAdditionalContentsToAddItemPage(questionnaire);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].descriptionEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].descriptionEnabled
).toBe(true);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].guidanceEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].guidanceEnabled
).toBe(true);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].definitionEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].definitionEnabled
).toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1]
.additionalInfoEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1]
.additionalInfoEnabled
).toBe(true);
});

it("should not add additional content fields to non add item list collector pages", () => {
const updatedQuestionnaire =
addAdditionalContentsToAddItemPage(questionnaire);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0].descriptionEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0].descriptionEnabled
).not.toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0].guidanceEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0].guidanceEnabled
).not.toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0].definitionEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0].definitionEnabled
).not.toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0]
.additionalInfoEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[0]
.additionalInfoEnabled
).not.toBe(false);

expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].descriptionEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].descriptionEnabled
).toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].guidanceEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].guidanceEnabled
).toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].definitionEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1].definitionEnabled
).toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1]
.additionalInfoEnabled
).not.toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[1]
.additionalInfoEnabled
).toBe(false);

expect(
updatedQuestionnaire.sections[0].folders[0].pages[2].descriptionEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[2].descriptionEnabled
).not.toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[2].guidanceEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[2].guidanceEnabled
).not.toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[2].definitionEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[2].definitionEnabled
).not.toBe(false);
expect(
updatedQuestionnaire.sections[0].folders[0].pages[2]
.additionalInfoEnabled
).toBeUndefined();
expect(
updatedQuestionnaire.sections[0].folders[0].pages[2]
.additionalInfoEnabled
).not.toBe(false);
});
});
});
26 changes: 26 additions & 0 deletions eq-author-api/migrations/addAdditonalContentsToAddItemPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = (questionnaire) => {
questionnaire.sections.forEach((section) => {
section.folders.forEach((folder) => {
if (folder.listId !== undefined) {
folder.pages.forEach((page) => {
if (page.pageType === "ListCollectorAddItemPage") {
if (page.descriptionEnabled === undefined) {
page.descriptionEnabled = false;
}
if (page.guidanceEnabled === undefined) {
page.guidanceEnabled = false;
}
if (page.definitionEnabled === undefined) {
page.definitionEnabled = false;
}
if (page.additionalInfoEnabled === undefined) {
page.additionalInfoEnabled = false;
}
}
});
}
});
});

return questionnaire;
};
4 changes: 4 additions & 0 deletions eq-author-api/migrations/convertListCollectorPageToFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const generateListCollectorFolder = (page) => {
title: page.addItemTitle,
pageDescription: page.addItemPageDescription,
position: 1,
descriptionEnabled: page.descriptionEnabled,
guidanceEnabled: page.guidanceEnabled,
definitionEnabled: page.definitionEnabled,
additionalInfoEnabled: page.additionalGuidanceEnabled,
}),
createListCollectorConfirmationPage({
title: page.anotherTitle,
Expand Down
1 change: 1 addition & 0 deletions eq-author-api/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const migrations = [
require("./convertListCollectorPageToFolder"),
require("./addValidationToListCollectorAnswers"),
require("./addFieldsToListCollectorFolderContents"),
require("./addAdditonalContentsToAddItemPage"),
];

const currentVersion = migrations.length;
Expand Down
10 changes: 10 additions & 0 deletions eq-author-api/schema/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ type ListCollectorAddItemPage implements Page {
folder: Folder!
section: Section!
position: Int!
description: String
descriptionEnabled: Boolean!
guidance: String
guidanceEnabled: Boolean!
definitionLabel: String
definitionContent: String
definitionEnabled: Boolean!
additionalInfoLabel: String
additionalInfoContent: String
additionalInfoEnabled: Boolean!
comments: [Comment]
validationErrorInfo: ValidationErrorInfo
}
Expand Down
4 changes: 4 additions & 0 deletions eq-author-api/src/businessLogic/createListCollectorPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const createListCollectorAddItemPage = (input = { position: 1 }) => ({
pageType: "ListCollectorAddItemPage",
title: "",
pageDescription: "",
descriptionEnabled: false,
guidanceEnabled: false,
definitionEnabled: false,
additionalInfoEnabled: false,
alias: null,
...omit(input, "folderId"),
});
Expand Down
20 changes: 20 additions & 0 deletions eq-author-api/tests/utils/contextBuilder/page/queryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,30 @@ const getPageQuery = `
}
}
... on ListCollectorAddItemPage {
description
descriptionEnabled
guidance
guidanceEnabled
definitionLabel
definitionContent
definitionEnabled
additionalInfoLabel
additionalInfoContent
additionalInfoEnabled
comments {
id
commentText
}
validationErrorInfo {
id
errors {
id
type
field
errorCode
}
totalCount
}
}
... on ListCollectorConfirmationPage {
comments {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ fragment Pages on Page {
}
}
... on ListCollectorAddItemPage {
id
description
descriptionEnabled
guidance
guidanceEnabled
definitionLabel
definitionContent
definitionEnabled
additionalInfoLabel
additionalInfoContent
additionalInfoEnabled
comments {
...Comment
}
Expand Down Expand Up @@ -274,6 +285,16 @@ fragment ListCollectorAddItemPages on ListCollectorAddItemPage {
position
displayName
pageType
description
descriptionEnabled
guidance
guidanceEnabled
definitionLabel
definitionContent
definitionEnabled
additionalInfoLabel
additionalInfoContent
additionalInfoEnabled
validationErrorInfo {
id
errors {
Expand Down
Loading

0 comments on commit 37c7bcd

Please sign in to comment.