diff --git a/src/eq_schema/block-types/Introduction/index.js b/src/eq_schema/block-types/Introduction/index.js index a283a77d..ffb8b972 100644 --- a/src/eq_schema/block-types/Introduction/index.js +++ b/src/eq_schema/block-types/Introduction/index.js @@ -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, @@ -35,7 +36,7 @@ class Introduction { this.primary_content = [ { id: "primary", - title: this.buildTitle(title, ctx), + title: buildIntroductionTitle(), contents: buildContactDetails( contactDetailsPhoneNumber, contactDetailsEmailAddress, diff --git a/src/eq_schema/block-types/Introduction/index.test.js b/src/eq_schema/block-types/Introduction/index.test.js index 1a37be7a..e739da38 100644 --- a/src/eq_schema/block-types/Introduction/index.test.js +++ b/src/eq_schema/block-types/Introduction/index.test.js @@ -11,15 +11,16 @@ describe("Introduction", () => { placeholder, value: { identifier: placeholder, - source - } - } - ] + source, + }, + }, + ], }); beforeEach(() => { apiData = { id: "1", - title: "
You are completing this for ru_name (trad_as)
", + title: + 'You are completing this for ru_name (trad_as)
', description: `Information you need ${piping}
`, @@ -29,13 +30,13 @@ describe("Introduction", () => { { id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36", title: "Hello
", - description: `World ${piping}
` + description: `World ${piping}
`, }, { id: "1e7e5ecd-6f4c-4219-9893-6efdeea36ad0", title: "Collapsible
", - description: "Description
" - } + description: "Description
", + }, ], tertiaryTitle: `How we use your data ${piping}
`, tertiaryDescription: `Hello
", - description: "World
" + description: "World
", }, { id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36", title: "Hello
", - description: "" + description: "", }, { id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36", title: "", - description: "Description
" - } + description: "Description
", + }, ]; const introduction = new Introduction(apiData, context); expect(introduction.preview_content.questions).toMatchObject([ { contents: [{ description: "World" }], - question: "Hello" - } + question: "Hello", + }, ]); }); @@ -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"), + ], + }, + ], + }, ]); }); }); diff --git a/src/utils/builders/index.js b/src/utils/builders/index.js index 347bc305..9539ad30 100644 --- a/src/utils/builders/index.js +++ b/src/utils/builders/index.js @@ -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, }; diff --git a/src/utils/convertPipes/PlaceholderObjectBuilder.js b/src/utils/convertPipes/PlaceholderObjectBuilder.js index 15a4c3f8..0772f48d 100644 --- a/src/utils/convertPipes/PlaceholderObjectBuilder.js +++ b/src/utils/convertPipes/PlaceholderObjectBuilder.js @@ -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] - } + }; } } @@ -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 = {