Skip to content

Commit

Permalink
Merge pull request #72 from ONSdigital/EAR-1646-intro-title-trad_as
Browse files Browse the repository at this point in the history
Ear 1646 intro title trad as
  • Loading branch information
farres1 authored Feb 10, 2022
2 parents c2ec378 + 15b6e5f commit 7e7c84b
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 87 deletions.
5 changes: 3 additions & 2 deletions src/eq_schema/block-types/Introduction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ const reverseContent = (ctx) =>
flow(wrapContents("content"), reversePipeContent(ctx));

const buildContactDetails = require("../../builders/contactDetails");
const { buildIntroductionTitle } = require("../../../utils/builders");

class Introduction {
constructor(
{
title,
contactDetailsPhoneNumber,
contactDetailsEmailAddress,
contactDetailsEmailSubject,
Expand All @@ -35,7 +36,7 @@ class Introduction {
this.primary_content = [
{
id: "primary",
title: this.buildTitle(title, ctx),
title: buildIntroductionTitle(),
contents: buildContactDetails(
contactDetailsPhoneNumber,
contactDetailsEmailAddress,
Expand Down
113 changes: 63 additions & 50 deletions src/eq_schema/block-types/Introduction/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ describe("Introduction", () => {
placeholder,
value: {
identifier: placeholder,
source
}
}
]
source,
},
},
],
});
beforeEach(() => {
apiData = {
id: "1",
title: "<p>You are completing this for <span data-piped=\"metadata\" data-id=\"ru_name\">ru_name</span> (<span data-piped=\"metadata\" data-id=\"trad_as\">trad_as</span>)</p>",
title:
'<p>You are completing this for <span data-piped="metadata" data-id="ru_name">ru_name</span> (<span data-piped="metadata" data-id="trad_as">trad_as</span>)</p>',
description: `<ul><li>Data should relate to all sites in England, Scotland, Wales and Northern Ireland unless otherwise stated. </li><li>You can provide info estimates if actual figures aren’t available.</li><li>We will treat your data securely and confidentially.</li><li>${piping}</li></ul>`,
legalBasis: "NOTICE_2",
secondaryTitle: `<p>Information you need ${piping}</p>`,
Expand All @@ -29,13 +30,13 @@ describe("Introduction", () => {
{
id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36",
title: "<p>Hello</p>",
description: `<p>World ${piping}</p>`
description: `<p>World ${piping}</p>`,
},
{
id: "1e7e5ecd-6f4c-4219-9893-6efdeea36ad0",
title: "<p>Collapsible</p>",
description: "<p>Description</p>"
}
description: "<p>Description</p>",
},
],
tertiaryTitle: `<p>How we use your data ${piping}</p>`,
tertiaryDescription: `<ul><li>You cannot appeal your selection. Your business was selected to give us a comprehensive view of the UK economy.</li><li>The information you provide contributes to Gross Domestic Product (GDP).</li><li>${piping}</li></ul>`,
Expand All @@ -47,8 +48,7 @@ describe("Introduction", () => {
context = {
questionnaireJson: {
metadata: [
{ id: "1",
key: "some_metadata" },
{ id: "1", key: "some_metadata" },
{
id: "ru_name",
key: "ru_name",
Expand Down Expand Up @@ -78,20 +78,33 @@ describe("Introduction", () => {
{
id: "primary",
title: {
text: "You are completing this for {ru_name} ({trad_as})",
text: "You are completing this for {trad_as} ({ru_name})",
placeholders: [
{
placeholder: "ru_name",
value: {
source: "metadata",
identifier: "ru_name",
},
placeholder: "trad_as",
transforms: [
{
transform: "first_non_empty_item",
arguments: {
items: [
{
source: "metadata",
identifier: "trad_as",
},
{
source: "metadata",
identifier: "ru_name",
},
],
},
},
],
},
{
placeholder: "trad_as",
placeholder: "ru_name",
value: {
source: "metadata",
identifier: "trad_as",
identifier: "ru_name",
},
},
],
Expand Down Expand Up @@ -155,8 +168,8 @@ describe("Introduction", () => {
contents: [
{
description:
"You can select the dates of the period you are reporting for, if the given dates are not appropriate."
}
"You can select the dates of the period you are reporting for, if the given dates are not appropriate.",
},
],
id: "preview",
questions: expect.any(Array),
Expand All @@ -167,11 +180,11 @@ describe("Introduction", () => {
placeholder: "some_metadata",
value: {
identifier: "some_metadata",
source: "metadata"
}
}
]
}
source: "metadata",
},
},
],
},
});
});

Expand All @@ -188,19 +201,19 @@ describe("Introduction", () => {
placeholder: "some_metadata",
value: {
identifier: "some_metadata",
source: "metadata"
}
}
]
}
}
source: "metadata",
},
},
],
},
},
],
question: "Hello"
question: "Hello",
},
{
contents: [{ description: "Description" }],
question: "Collapsible"
}
question: "Collapsible",
},
]);
});

Expand All @@ -209,25 +222,25 @@ describe("Introduction", () => {
{
id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36",
title: "<p>Hello</p>",
description: "<p>World</p>"
description: "<p>World</p>",
},
{
id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36",
title: "<p>Hello</p>",
description: ""
description: "",
},
{
id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36",
title: "",
description: "<p>Description</p>"
}
description: "<p>Description</p>",
},
];
const introduction = new Introduction(apiData, context);
expect(introduction.preview_content.questions).toMatchObject([
{
contents: [{ description: "World" }],
question: "Hello"
}
question: "Hello",
},
]);
});

Expand All @@ -245,21 +258,21 @@ describe("Introduction", () => {
placeholder: "some_metadata",
value: {
identifier: "some_metadata",
source: "metadata"
}
}
]
}
source: "metadata",
},
},
],
},
},
{
list: [
"You cannot appeal your selection. Your business was selected to give us a comprehensive view of the UK economy.",
"The information you provide contributes to Gross Domestic Product (GDP).",
createPipedFormat("some_metadata", "metadata")
]
}
]
}
createPipedFormat("some_metadata", "metadata"),
],
},
],
},
]);
});
});
36 changes: 36 additions & 0 deletions src/utils/builders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@ const buildContents = (title, ctx) => {
return processPipe(ctx)(title);
};

const buildIntroductionTitle = () => {
return {
text: "You are completing this for {trad_as} ({ru_name})",
placeholders: [
{
placeholder: "trad_as",
transforms: [
{
transform: "first_non_empty_item",
arguments: {
items: [
{
source: "metadata",
identifier: "trad_as",
},
{
source: "metadata",
identifier: "ru_name",
},
],
},
},
],
},
{
placeholder: "ru_name",
value: {
source: "metadata",
identifier: "ru_name",
},
},
],
};
};

module.exports = {
buildContents,
buildIntroductionTitle,
};
70 changes: 35 additions & 35 deletions src/utils/convertPipes/PlaceholderObjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,31 @@ const placeholderObjectBuilder = (
fallback,
AnswerType
) => {

let valueSource;
let argumentList;
let placeHolder;

if (["metadata","answers"].includes(source)) {
if (["metadata", "answers"].includes(source)) {
valueSource = {
source,
identifier
}
};
identifier,
};
}

if ([AnswerType]in(TRANSFORM_MAP)) {
if (["Date","DateRange"].includes(AnswerType)) {
argumentList={
"date_format" : DATE_FORMAT_MAP[dateFormat ? dateFormat : "dd/mm/yyyy" ]
}
if ([AnswerType] in TRANSFORM_MAP) {
if (["Date", "DateRange"].includes(AnswerType)) {
argumentList = {
date_format: DATE_FORMAT_MAP[dateFormat ? dateFormat : "dd/mm/yyyy"],
};
}
if (["Number","Currency"].includes(AnswerType)) {
argumentList={
}
if (["Number", "Currency"].includes(AnswerType)) {
argumentList = {};
}
if (["Unit"].includes(AnswerType)) {
argumentList={
argumentList = {
// leaving here until unit added to runner
// "unit": unitConversion[unitType]
}
};
}
}

Expand All @@ -69,42 +67,44 @@ const placeholderObjectBuilder = (
{
transform: "first_non_empty_item",
arguments: {
items: [
valueSource,
fallback
]
}
items: [valueSource, fallback],
},
},
]
}
if ([AnswerType]in(TRANSFORM_MAP)) {
placeHolder.transforms.push(
{
transform: TRANSFORM_MAP[AnswerType].format,
arguments: { [TRANSFORM_MAP[AnswerType].transformKey] : { source: "previous_transform" }, ...argumentList }
}
)
],
};
if ([AnswerType] in TRANSFORM_MAP) {
placeHolder.transforms.push({
transform: TRANSFORM_MAP[AnswerType].format,
arguments: {
[TRANSFORM_MAP[AnswerType].transformKey]: {
source: "previous_transform",
},
...argumentList,
},
});
}
return placeHolder
return placeHolder;
}

if ([AnswerType]in(TRANSFORM_MAP)) {
if ([AnswerType] in TRANSFORM_MAP) {
return {
placeholder: removeDash(identifier),
transforms: [
{
transform: TRANSFORM_MAP[AnswerType].format,
arguments: { [TRANSFORM_MAP[AnswerType].transformKey]: valueSource, ...argumentList }
arguments: {
[TRANSFORM_MAP[AnswerType].transformKey]: valueSource,
...argumentList,
},
},
]
}
],
};
}

return {
placeholder: removeDash(identifier),
value: valueSource,
};

};

module.exports = {
Expand Down

0 comments on commit 7e7c84b

Please sign in to comment.