@planning-inspectorate/dynamic-forms 3.3.1 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/controller.js +7 -0
- package/src/controller.test.js +7 -1
package/package.json
CHANGED
package/src/controller.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SECTION_STATUS } from './section.js';
|
|
2
2
|
import questionUtils from './components/utils/question-utils.js';
|
|
3
3
|
import { answerObjectForManageListSaving } from '#src/components/manage-list/utils.js';
|
|
4
|
+
import { booleanToYesNoValue } from '#src/components/boolean/question.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {import('./journey/journey.js').Journey} Journey
|
|
@@ -258,6 +259,12 @@ export function buildSave(saveData, redirectToTaskListOnSuccess) {
|
|
|
258
259
|
answers = answerObjectForManageListSaving(journeyResponse, manageListQuestion, req.params);
|
|
259
260
|
}
|
|
260
261
|
for (const [k, v] of Object.entries(data?.answers || {})) {
|
|
262
|
+
if (typeof v === 'boolean') {
|
|
263
|
+
// boolean answers are saved at booleans, but stored in session and
|
|
264
|
+
// checked by display logic as yes/no
|
|
265
|
+
answers[k] = booleanToYesNoValue(v);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
261
268
|
answers[k] = v;
|
|
262
269
|
}
|
|
263
270
|
// move to the next question
|
package/src/controller.test.js
CHANGED
|
@@ -6,6 +6,7 @@ import { Journey } from './journey/journey.js';
|
|
|
6
6
|
import { SECTION_STATUS } from './section.js';
|
|
7
7
|
|
|
8
8
|
import { mockReq, mockRes } from '#test/utils/utils.js';
|
|
9
|
+
import { BOOLEAN_OPTIONS } from '#src/components/boolean/question.js';
|
|
9
10
|
|
|
10
11
|
const res = mockRes();
|
|
11
12
|
const mockBaseUrl = '/manage-appeals/questionnaire';
|
|
@@ -501,7 +502,10 @@ describe('dynamic-form/controller', () => {
|
|
|
501
502
|
...sampleQuestionObj
|
|
502
503
|
};
|
|
503
504
|
sampleQuestionObjWithActions.getDataToSave.mock.mockImplementationOnce(() => ({
|
|
504
|
-
answers: {
|
|
505
|
+
answers: {
|
|
506
|
+
[sampleQuestionObj.fieldName]: 'my-answer',
|
|
507
|
+
aBooleanToTest: true
|
|
508
|
+
}
|
|
505
509
|
}));
|
|
506
510
|
|
|
507
511
|
req.params = {
|
|
@@ -528,6 +532,8 @@ describe('dynamic-form/controller', () => {
|
|
|
528
532
|
assert.strictEqual(res.redirect.mock.calls[0].arguments[0], expectedUrl);
|
|
529
533
|
// journey response should be edited if redirecting to next question
|
|
530
534
|
assert.strictEqual(res.locals.journeyResponse.answers?.sampleFieldName, 'my-answer');
|
|
535
|
+
// booleans must be strings in journey response
|
|
536
|
+
assert.strictEqual(res.locals.journeyResponse.answers?.aBooleanToTest, BOOLEAN_OPTIONS.YES);
|
|
531
537
|
});
|
|
532
538
|
|
|
533
539
|
it('should redirect to task list if configured', async () => {
|