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: ``, legalBasis: "NOTICE_2", secondaryTitle: `

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: ``, @@ -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", @@ -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", }, }, ], @@ -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), @@ -167,11 +180,11 @@ describe("Introduction", () => { placeholder: "some_metadata", value: { identifier: "some_metadata", - source: "metadata" - } - } - ] - } + source: "metadata", + }, + }, + ], + }, }); }); @@ -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", + }, ]); }); @@ -209,25 +222,25 @@ describe("Introduction", () => { { id: "d45bf1dd-f286-40ca-b6a2-fe0014574c36", title: "

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 = {