diff --git a/src/eq_schema/schema/Questionnaire/index.js b/src/eq_schema/schema/Questionnaire/index.js index a7e5578a..089c3877 100644 --- a/src/eq_schema/schema/Questionnaire/index.js +++ b/src/eq_schema/schema/Questionnaire/index.js @@ -1,6 +1,6 @@ const { DEFAULT_METADATA, - DEFAULT_METADATA_NAMES, + DEFAULT_METADATA_NAMES } = require("../../../constants/metadata"); const { contentMap } = require("../../../constants/legalBases"); @@ -13,12 +13,13 @@ const { Introduction } = require("../../block-types"); const Section = require("../Section"); const PostSubmission = require("../PostSubmission"); +const Submission = require("../Submission"); const QuestionnaireFlow = require("../QuestionnaireFlow"); const getPreviewTheme = ({ previewTheme, themes }) => - themes && themes.find((theme) => theme && theme.shortName === previewTheme); + themes && themes.find(theme => theme && theme.shortName === previewTheme); -const getTheme = (previewTheme) => { +const getTheme = previewTheme => { if (validThemes.includes(previewTheme)) { return previewTheme; } else { @@ -57,7 +58,7 @@ class Questionnaire { this.theme = getTheme(questionnaireJson.themeSettings.previewTheme); this.navigation = { - visible: questionnaireJson.navigation, + visible: questionnaireJson.navigation }; this.metadata = this.buildMetadata(questionnaireJson.metadata); @@ -65,12 +66,13 @@ class Questionnaire { questionnaireJson.submission, ctx ); - } + this.submission = this.buildSubmission(questionnaireJson.submission); + } createContext(questionnaireJson) { return { routingGotos: [], - questionnaireJson, + questionnaireJson }; } @@ -92,18 +94,18 @@ class Questionnaire { { id: `group${introduction.id}`, title: "Introduction", - blocks: [new Introduction(introduction, ctx)], - }, - ], + blocks: [new Introduction(introduction, ctx)] + } + ] }, - ...this.sections, + ...this.sections ]; this.sections = newSections; } buildSections(sections, ctx) { - return sections.map((section) => new Section(section, ctx)); + return sections.map(section => new Section(section, ctx)); } buildMetadata(metadata) { @@ -112,12 +114,16 @@ class Questionnaire { .map(({ key, type }) => ({ name: key, type: type === "Date" ? "date" : "string", - optional: type === "Text_Optional" || undefined, + optional: type === "Text_Optional" || undefined })); return [...DEFAULT_METADATA, ...userMetadata]; } + buildSubmission(postSubmission) { + return new Submission(postSubmission); + } + buildPostSubmission(postSubmission, ctx) { return new PostSubmission(postSubmission, ctx); } diff --git a/src/eq_schema/schema/Submission/index.js b/src/eq_schema/schema/Submission/index.js new file mode 100644 index 00000000..d768d0a9 --- /dev/null +++ b/src/eq_schema/schema/Submission/index.js @@ -0,0 +1,13 @@ +class Submission { + constructor(postSubmission) { + this.button = "Submit"; + if (postSubmission.viewPrintAnswers) { + this.guidance = + "You will have the opportunity to view, save or print a copy of your answers after submitting this survey."; + } + this.title = "Submit your questionnaire"; + this.warning = "You cannot view your answers after submission"; + } +} + +module.exports = Submission; diff --git a/src/eq_schema/schema/Submission/index.test.js b/src/eq_schema/schema/Submission/index.test.js new file mode 100644 index 00000000..b68de29d --- /dev/null +++ b/src/eq_schema/schema/Submission/index.test.js @@ -0,0 +1,47 @@ +const Submission = require("."); + +describe("Submission with guidance", () => { + let submission; + beforeEach(() => { + submission = { + id: "07b92a18-180c-4c35-9e94-aa6df9cdee6b", + furtherContent: + '

Your response will help inform decision-makers how best to support the UK population and economy at this challenging time.

Learn more about how we use this data

', + viewPrintAnswers: true, + emailConfirmation: true, + feedback: true + }; + }); + + it("should set the correct data", () => { + const renderSubmission = new Submission(submission); + + expect(renderSubmission.button).toBeTruthy(); + expect(renderSubmission.guidance).toBeTruthy(); + expect(renderSubmission.title).toBeTruthy(); + expect(renderSubmission.warning).toBeTruthy(); + }); +}); + +describe("Submission without guidance", () => { + let submissionWithout; + beforeEach(() => { + submissionWithout = { + id: "07b92a18-180c-4c35-9e94-aa6df9cdee6b", + furtherContent: + '

Your response will help inform decision-makers how best to support the UK population and economy at this challenging time.

Learn more about how we use this data

', + viewPrintAnswers: false, + emailConfirmation: true, + feedback: true + }; + }); + + it("should set the correct data", () => { + const renderSubmission = new Submission(submissionWithout); + + expect(renderSubmission.button).toBeTruthy(); + expect(renderSubmission.guidance).toBeFalsy(); + expect(renderSubmission.title).toBeTruthy(); + expect(renderSubmission.warning).toBeTruthy(); + }); +});