Skip to content

Commit 1227e1e

Browse files
FS-4870: adding prefixes and suffix along with the value in the last page (summary) (#85)
1 parent c711aa2 commit 1227e1e

File tree

4 files changed

+334
-5
lines changed

4 files changed

+334
-5
lines changed

runner/src/server/plugins/engine/models/ViewModelBase.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,11 @@ function Item(
445445
title: component.title,
446446
dataType: component.dataType,
447447
immutable: component.options.disableChangingFromSummary,
448+
prefix: component.options && component.options.prefix ? component.options.prefix: "",
449+
suffix: component.options && component.options.suffix ? component.options.suffix: "",
448450
};
449451

450-
if (
451-
component.type === "FileUploadField" &&
452-
model.showFilenamesOnSummaryPage
453-
) {
452+
if (component.type === "FileUploadField" && model.showFilenamesOnSummaryPage && sectionState.originalFilenames) {
454453
//@ts-ignore
455454
item.filename = sectionState.originalFilenames[component.name]?.originalFilename;
456455
}

runner/src/server/views/partials/summary-row.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{{itemValue}}<br>
1111
{% endfor %}
1212
{% elif item.type == 'NumberField' or item.type == 'WebsiteField' and 'http' not in item.value|lower %}
13-
{{item.prefix}}{{item.value}}
13+
{{item.prefix}} {{item.value}} {{item.suffix}}
1414
{% elif item.type == 'ClientSideFileUploadField' %}
1515
{% if item.value.files|length == 0 %}
1616
{{ notSuppliedText }}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import * as Code from "@hapi/code";
2+
import * as Lab from "@hapi/lab";
3+
import * as path from "path";
4+
import * as sinon from "sinon";
5+
//@ts-ignore
6+
import {AdapterFormModel} from "src/server/plugins/engine/models";
7+
//@ts-ignore
8+
import createServer from "src/server";
9+
//@ts-ignore
10+
import {StartPageController} from "src/server/plugins/engine/page-controllers";
11+
//@ts-ignore
12+
import {TranslationLoaderService} from "src/server/services/TranslationLoaderService";
13+
import {PluginUtil} from "../../../../../../src/server/plugins/engine/util/PluginUtil";
14+
15+
import form from "../../../prefix-postfix-for-fields.test.json";
16+
17+
const {expect} = Code;
18+
const lab = Lab.script();
19+
exports.lab = lab;
20+
const {suite, test, before, after, beforeEach, afterEach} = lab;
21+
22+
suite("SummaryPageController", () => {
23+
let server;
24+
let sandbox;
25+
26+
const mockI18n = (key) => {
27+
const translationService: TranslationLoaderService = new TranslationLoaderService();
28+
const translations = translationService.getTranslations();
29+
return translations.en[key] || key;
30+
};
31+
32+
before(async () => {
33+
server = await createServer({
34+
formFileName: "prefix-postfix-for-fields.test.json",
35+
formFilePath: path.join(__dirname, "../../../"),
36+
enforceCsrf: false,
37+
});
38+
server.i18n = {
39+
__: mockI18n
40+
};
41+
});
42+
43+
after(async () => {
44+
await server.stop();
45+
});
46+
47+
beforeEach(() => {
48+
sandbox = sinon.createSandbox();
49+
});
50+
51+
afterEach(() => {
52+
sandbox.restore();
53+
});
54+
55+
test("shouldAddingPreFixesForTheSummaryIfThereAreAnyPrefixes", async () => {
56+
const pages = [...form.pages];
57+
const firstPage = pages.shift();
58+
const formDef = {...form, pages: [firstPage, ...pages]};
59+
let formModel = new AdapterFormModel(formDef, {});
60+
const page = formModel.pages.find(
61+
(page) => PluginUtil.normalisePath(page.path) === PluginUtil.normalisePath("summary")
62+
);
63+
64+
const mockState = {
65+
progress: ["/xwFi2C2S-Y/management-case-oqAeVI", "/xwFi2C2S-Y/management-case-kYpnwk"],
66+
FabDefault: {
67+
TzOokX: [{
68+
GpLJDu: "Natalie Watkins",
69+
RRzTlc: 148
70+
}, {
71+
GpLJDu: "sdf",
72+
RRzTlc: 4
73+
}],
74+
iyTJRX: 45,
75+
IdoZHN: 4343
76+
},
77+
webhookData: {
78+
metadata: {},
79+
name: "Apply for funding to save an asset in your community",
80+
questions: [{
81+
category: "FabDefault",
82+
question: "Management case",
83+
fields: [{
84+
key: "TzOokX",
85+
title: "Sources of income",
86+
type: "multiInput",
87+
answer: [{
88+
GpLJDu: "Natalie Watkins",
89+
RRzTlc: 148
90+
}, {
91+
GpLJDu: "sdf",
92+
RRzTlc: 4
93+
}]
94+
}, {
95+
key: "iyTJRX",
96+
title: "How many years old ",
97+
type: "text",
98+
answer: "45"
99+
}, {
100+
key: "IdoZHN",
101+
title: "Amount your salary ?",
102+
type: "text",
103+
answer: "4343"
104+
}]
105+
}]
106+
}
107+
};
108+
// Mock adapterCacheService with the methods you need
109+
const mockAdapterCacheService: any = {
110+
getState: sinon.stub().resolves(mockState),
111+
};
112+
// Mock request with state
113+
const request = {
114+
services: sinon.stub().returns({
115+
adapterCacheService: mockAdapterCacheService,
116+
}),
117+
query: {
118+
lang: "en"
119+
},
120+
yar: {
121+
get: sinon.stub().returns("en"),
122+
flash: sinon.stub().returns("en")
123+
},
124+
logger: {
125+
info: sinon.stub().returns("logger")
126+
},
127+
i18n: {
128+
__: sinon.stub().returns("english text"),
129+
getLocale: sinon.stub().returns("en")
130+
},
131+
auth: {
132+
isAuthenticated: false
133+
}
134+
};
135+
136+
// Mock Hapi response toolkit
137+
const h = {
138+
response: sinon.stub().returns({
139+
code: sinon.stub()
140+
}),
141+
redirect: sinon.stub(),
142+
view: sinon.stub().callsFake(async (_templateName, contextData) => {
143+
// Call server.render with the same arguments
144+
expect(contextData.details).exist();
145+
expect(contextData.details[0]).exist();
146+
expect(contextData.details[0].items).exist();
147+
expect(contextData.details[0].items[0].value[0]).to.contains("Natalie Watkins : £148");
148+
expect(contextData.details[0].items[0].value[1]).to.contains("sdf : £4");
149+
expect(contextData.details[0].items[1].value).to.contains("45");
150+
expect(contextData.details[0].items[1].suffix).to.contains("years");
151+
expect(contextData.details[0].items[2].prefix).to.contains("£");
152+
expect(contextData.details[0].items[2].value).to.contains("4343");
153+
}),
154+
};
155+
await page.makeGetRouteHandler()(request, h);
156+
});
157+
});
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
{
2+
"metadata": {},
3+
"startPage": "/management-case-oqAeVI",
4+
"pages": [
5+
{
6+
"path": "/management-case-kYpnwk",
7+
"controller": "RepeatingFieldPageController",
8+
"options": {
9+
"summaryDisplayMode": {
10+
"samePage": true,
11+
"separatePage": false,
12+
"hideRowTitles": false
13+
},
14+
"customText": {
15+
"samePageTitle": "Your income sources",
16+
"samePageTableItemName": ""
17+
}
18+
},
19+
"title": "Management case",
20+
"components": [
21+
{
22+
"name": "FHZRAe",
23+
"options": {},
24+
"type": "Html",
25+
"content": "<h2 class=\"govuk-heading-m\">Income to run the asset</h2>",
26+
"schema": {}
27+
},
28+
{
29+
"name": "fzAoYw",
30+
"options": {},
31+
"type": "Details",
32+
"content": "<p>We're looking to understand your full financial forecasts for running the asset once you take ownership.</p>\n\n<p> This includes your sources of income and regular costs, as well as a summary of your expected cash flow for the next few years.</p>\n<p>We also need to make sure you're confident you will spend any money awarded by this fund within 12 months.</p>\n\n<p>You can use your business plan to provide information that supports your answers.</p>",
33+
"title": "Help with project costs",
34+
"schema": {}
35+
},
36+
{
37+
"name": "adkAXU",
38+
"options": {},
39+
"type": "Para",
40+
"content": "<h2 class=\"govuk-heading-s\">Income sources</h2>\n<p class=\"govuk-caption-m\">This is how you expect the asset to make money in future. These should be measured against your running costs.</p>\n<p class=\"govuk-caption-m\">You can use your business plan to provide information that supports your answers.</p>",
41+
"schema": {}
42+
},
43+
{
44+
"name": "TzOokX",
45+
"options": {
46+
"prefix": "£",
47+
"columnTitles": [
48+
"Source",
49+
"Amount",
50+
"Action"
51+
],
52+
"required": true
53+
},
54+
"type": "MultiInputField",
55+
"title": "Sources of income",
56+
"hint": "The MultiInputField needed",
57+
"schema": {},
58+
"children": [
59+
{
60+
"name": "GpLJDu",
61+
"options": {},
62+
"type": "TextField",
63+
"title": "Source"
64+
},
65+
{
66+
"name": "RRzTlc",
67+
"options": {
68+
"prefix": "£",
69+
"classes": "govuk-!-width-one-half"
70+
},
71+
"type": "NumberField",
72+
"title": "Amount in pounds",
73+
"hint": "",
74+
"schema": {}
75+
}
76+
]
77+
},
78+
{
79+
"name": "iyTJRX",
80+
"options": {
81+
"suffix": "years"
82+
},
83+
"type": "NumberField",
84+
"title": "How many years old ",
85+
"schema": {
86+
"min": "10",
87+
"max": "100"
88+
}
89+
},
90+
{
91+
"name": "IdoZHN",
92+
"options": {
93+
"prefix": "£"
94+
},
95+
"type": "NumberField",
96+
"title": "Amount your salary ?",
97+
"schema": {
98+
"min": "10",
99+
"max": "10000"
100+
}
101+
}
102+
],
103+
"next": [
104+
{
105+
"path": "/summary"
106+
}
107+
],
108+
"section": "FabDefault"
109+
},
110+
{
111+
"path": "/summary",
112+
"title": "Check your answers",
113+
"components": [],
114+
"next": [],
115+
"controller": "./pages/summary.js",
116+
"section": "FabDefault"
117+
},
118+
{
119+
"path": "/management-case-oqAeVI",
120+
"title": "Management case",
121+
"components": [
122+
{
123+
"name": "mPqjks",
124+
"options": {},
125+
"type": "Html",
126+
"content": "<h2 class=\"govuk-heading-m\">Project costs</h2>",
127+
"schema": {}
128+
},
129+
{
130+
"name": "UplABn",
131+
"options": {},
132+
"type": "Para",
133+
"content": "<label class=\"govuk-!-font-weight-bold\">In this section, we'll ask about:\n</label>\n\n<ul class=\"govuk-list govuk-list--bullet\">\n<li>cash flow summary</li>\n<li>income sources</li>\n<li>running costs</li>\n</ul>\n",
134+
"schema": {}
135+
}
136+
],
137+
"next": [
138+
{
139+
"path": "/management-case-kYpnwk"
140+
}
141+
],
142+
"controller": "./pages/start.js",
143+
"section": "FabDefault"
144+
}
145+
],
146+
"lists": [],
147+
"sections": [
148+
{
149+
"name": "FabDefault",
150+
"title": "Default Section",
151+
"hideTitle": true
152+
}
153+
],
154+
"conditions": [],
155+
"fees": [],
156+
"outputs": [],
157+
"version": 2,
158+
"skipSummary": false,
159+
"name": "Apply for funding to save an asset in your community",
160+
"feedback": {
161+
"feedbackForm": false,
162+
"url": ""
163+
},
164+
"phaseBanner": {
165+
"phase": "beta"
166+
},
167+
"feeOptions": {
168+
"allowSubmissionWithoutPayment": true,
169+
"maxAttempts": 3,
170+
"showPaymentSkippedWarningPage": false
171+
},
172+
"markAsComplete": false
173+
}

0 commit comments

Comments
 (0)