Skip to content

Commit

Permalink
Merge pull request #81 from ONSdigital/ear-1673-add-submission-config…
Browse files Browse the repository at this point in the history
…-in-publisher

EAR-1673 Add submission configuration in publisher
  • Loading branch information
farres1 authored Mar 1, 2022
2 parents 3fc357b + 16e4569 commit fdfa955
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/eq_schema/schema/Questionnaire/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
DEFAULT_METADATA,
DEFAULT_METADATA_NAMES,
DEFAULT_METADATA_NAMES
} = require("../../../constants/metadata");

const { contentMap } = require("../../../constants/legalBases");
Expand All @@ -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 {
Expand Down Expand Up @@ -57,20 +58,21 @@ class Questionnaire {
this.theme = getTheme(questionnaireJson.themeSettings.previewTheme);

this.navigation = {
visible: questionnaireJson.navigation,
visible: questionnaireJson.navigation
};
this.metadata = this.buildMetadata(questionnaireJson.metadata);

this.post_submission = this.buildPostSubmission(
questionnaireJson.submission,
ctx
);
}

this.submission = this.buildSubmission(questionnaireJson.submission);
}
createContext(questionnaireJson) {
return {
routingGotos: [],
questionnaireJson,
questionnaireJson
};
}

Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions src/eq_schema/schema/Submission/index.js
Original file line number Diff line number Diff line change
@@ -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;
47 changes: 47 additions & 0 deletions src/eq_schema/schema/Submission/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const Submission = require(".");

describe("Submission with guidance", () => {
let submission;
beforeEach(() => {
submission = {
id: "07b92a18-180c-4c35-9e94-aa6df9cdee6b",
furtherContent:
'<p>Your response will help inform decision-makers how best to support the UK population and economy at this challenging time.</p><p><a href="https://www.ons.gov.uk/surveys" target="_blank" rel="noopener noreferrer">Learn more about how we use this data</a></p>',
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:
'<p>Your response will help inform decision-makers how best to support the UK population and economy at this challenging time.</p><p><a href="https://www.ons.gov.uk/surveys" target="_blank" rel="noopener noreferrer">Learn more about how we use this data</a></p>',
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();
});
});

0 comments on commit fdfa955

Please sign in to comment.