@planning-inspectorate/dynamic-forms 3.15.6 → 3.17.0
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/.gitattributes +3 -0
- package/.prettierrc +1 -0
- package/README.md +123 -4
- package/package.json +6 -4
- package/{types/src → src}/components/address/question.d.ts +6 -2
- package/src/components/address/question.d.ts.map +1 -0
- package/src/components/address/question.js +7 -19
- package/{types/src → src}/components/boolean/question.d.ts +2 -2
- package/src/components/boolean/question.d.ts.map +1 -0
- package/src/components/boolean/question.js +1 -1
- package/src/components/checkbox/question.d.ts +9 -0
- package/src/components/checkbox/question.d.ts.map +1 -0
- package/src/components/checkbox/question.js +37 -54
- package/src/components/checkbox/question.test.js +170 -27
- package/{types/src → src}/components/date/question.d.ts +2 -2
- package/src/components/date/question.d.ts.map +1 -0
- package/src/components/date/question.js +7 -16
- package/{types/src → src}/components/date-period/question.d.ts +12 -4
- package/src/components/date-period/question.d.ts.map +1 -0
- package/src/components/date-period/question.js +2 -3
- package/{types/src → src}/components/date-time/question.d.ts +2 -2
- package/src/components/date-time/question.d.ts.map +1 -0
- package/src/components/date-time/question.js +5 -14
- package/src/components/email/question.d.ts +23 -0
- package/src/components/email/question.d.ts.map +1 -0
- package/src/components/email/question.js +1 -9
- package/src/components/manage-list/answer-summary-list.njk +1 -1
- package/src/components/manage-list/manage-list-actions.d.ts.map +1 -0
- package/src/components/manage-list/manage-list-section.d.ts.map +1 -0
- package/{types/src → src}/components/manage-list/question.d.ts +6 -3
- package/src/components/manage-list/question.d.ts.map +1 -0
- package/src/components/manage-list/question.js +5 -2
- package/{types/src → src}/components/manage-list/utils.d.ts +3 -3
- package/src/components/manage-list/utils.d.ts.map +1 -0
- package/src/components/manage-list/utils.js +2 -2
- package/src/components/multi-field-input/question.d.ts +52 -0
- package/src/components/multi-field-input/question.d.ts.map +1 -0
- package/src/components/multi-field-input/question.js +5 -13
- package/src/components/number-entry/question.d.ts +12 -0
- package/src/components/number-entry/question.d.ts.map +1 -0
- package/src/components/number-entry/question.js +4 -22
- package/src/components/radio/question.d.ts +11 -0
- package/src/components/radio/question.d.ts.map +1 -0
- package/src/components/radio/question.js +30 -51
- package/src/components/radio/question.test.js +139 -60
- package/src/components/select/question.d.ts +12 -0
- package/src/components/select/question.d.ts.map +1 -0
- package/src/components/select/question.js +5 -48
- package/{types/src → src}/components/single-line-input/question.d.ts +2 -2
- package/src/components/single-line-input/question.d.ts.map +1 -0
- package/src/components/single-line-input/question.js +2 -2
- package/{types/src → src}/components/text-entry/question.d.ts +3 -3
- package/src/components/text-entry/question.d.ts.map +1 -0
- package/src/components/text-entry/question.js +2 -2
- package/{types/src → src}/components/text-entry-redact/question.d.ts +8 -9
- package/src/components/text-entry-redact/question.d.ts.map +1 -0
- package/src/components/text-entry-redact/question.js +5 -2
- package/{types/src → src}/components/unit-option-entry/question.d.ts +12 -8
- package/src/components/unit-option-entry/question.d.ts.map +1 -0
- package/src/components/unit-option-entry/question.js +5 -6
- package/src/components/utils/component-types.d.ts.map +1 -0
- package/src/components/utils/persisted-number-answer.d.ts.map +1 -0
- package/src/components/utils/question-has-answer.d.ts.map +1 -0
- package/src/components/utils/question-has-answer.js +1 -1
- package/src/components/utils/question-utils.d.ts +33 -0
- package/src/components/utils/question-utils.d.ts.map +1 -0
- package/src/components/utils/question-utils.js +31 -2
- package/src/components/utils/question-utils.test.js +89 -2
- package/{types/src → src}/controller.d.ts +2 -7
- package/src/controller.d.ts.map +1 -0
- package/src/controller.js +3 -10
- package/{types/src → src}/index.d.ts +4 -3
- package/src/index.d.ts.map +1 -0
- package/src/index.js +6 -4
- package/src/journey/journey-response.d.ts +28 -0
- package/src/journey/journey-response.d.ts.map +1 -0
- package/src/journey/journey-response.js +4 -8
- package/{types/src → src}/journey/journey.d.ts +8 -8
- package/src/journey/journey.d.ts.map +1 -0
- package/src/journey/journey.js +6 -6
- package/src/lib/address-utils.d.ts.map +1 -0
- package/src/lib/address.d.ts.map +1 -0
- package/src/lib/date-utils.d.ts.map +1 -0
- package/src/lib/session-answer-store.d.ts.map +1 -0
- package/src/lib/utils.d.ts.map +1 -0
- package/src/lib/uuid.d.ts.map +1 -0
- package/src/middleware/build-get-journey.d.ts.map +1 -0
- package/src/middleware/redirect-to-unanswered-question.d.ts +12 -0
- package/src/middleware/redirect-to-unanswered-question.d.ts.map +1 -0
- package/src/middleware/redirect-to-unanswered-question.js +1 -1
- package/src/questions/create-questions.d.ts +18 -0
- package/src/questions/create-questions.d.ts.map +1 -0
- package/src/questions/create-questions.js +3 -3
- package/{types/src → src}/questions/options-question.d.ts +7 -7
- package/src/questions/options-question.d.ts.map +1 -0
- package/src/questions/options-question.js +29 -4
- package/src/questions/options-question.test.js +106 -0
- package/{types/src → src}/questions/question.d.ts +48 -79
- package/src/questions/question.d.ts.map +1 -0
- package/src/questions/question.js +83 -60
- package/src/questions/question.test.js +86 -0
- package/src/questions/questions.d.ts +3 -0
- package/src/questions/questions.d.ts.map +1 -0
- package/src/questions/questions.js +1 -1
- package/{types/src → src}/section.d.ts +16 -15
- package/src/section.d.ts.map +1 -0
- package/src/section.js +12 -14
- package/src/validator/address-validator.d.ts.map +1 -0
- package/src/validator/base-validator.d.ts.map +1 -0
- package/src/validator/conditional-required-validator.d.ts.map +1 -0
- package/src/validator/confirmation-checkbox-validator.d.ts.map +1 -0
- package/src/validator/coordinates-validator.d.ts.map +1 -0
- package/src/validator/cross-question-validator.d.ts.map +1 -0
- package/src/validator/date-period-validator.d.ts.map +1 -0
- package/src/validator/date-time-validator.d.ts.map +1 -0
- package/src/validator/date-validator.d.ts.map +1 -0
- package/src/validator/document-upload-validator.d.ts.map +1 -0
- package/src/validator/email-validator.d.ts.map +1 -0
- package/{types/src → src}/validator/multi-field-input-validator.d.ts +3 -3
- package/src/validator/multi-field-input-validator.d.ts.map +1 -0
- package/src/validator/multi-field-input-validator.js +3 -3
- package/{types/src → src}/validator/numeric-validator.d.ts +2 -2
- package/src/validator/numeric-validator.d.ts.map +1 -0
- package/src/validator/numeric-validator.js +2 -2
- package/src/validator/required-validator.d.ts.map +1 -0
- package/src/validator/same-answer-validator.d.ts.map +1 -0
- package/{types/src → src}/validator/string-validator.d.ts +3 -3
- package/src/validator/string-validator.d.ts.map +1 -0
- package/src/validator/string-validator.js +3 -3
- package/src/validator/unit-option-entry-validator.d.ts.map +1 -0
- package/src/validator/valid-option-validator.d.ts.map +1 -0
- package/src/validator/validation-error-handler.d.ts.map +1 -0
- package/src/validator/validator.d.ts.map +1 -0
- package/test/journey.js +2 -0
- package/test/questions.js +51 -1
- package/test/secondary-actions.test.js +1 -1
- package/test/snapshots/check-your-answers-not-started.html +22 -0
- package/test/snapshots/check-your-answers-with-answers.html +22 -0
- package/test/snapshots/favourite-activity-reason.html +54 -0
- package/test/snapshots/travel-requirements.html +48 -0
- package/test/utils/question-test-utils.js +36 -6
- package/tsconfig.json +11 -4
- package/{types/src/questions → typedefs}/question-props.d.ts +28 -26
- package/typedefs/question-types.d.ts +141 -0
- package/{src → typedefs}/section-types.d.ts +1 -1
- package/typedefs/section-types.js +1 -0
- package/move-types.js +0 -12
- package/src/questions/question-props.d.ts +0 -295
- package/src/questions/question-types.d.ts +0 -86
- package/types/commitlint.config.d.ts +0 -7
- package/types/commitlint.config.d.ts.map +0 -1
- package/types/eslint.config.d.ts +0 -97
- package/types/eslint.config.d.ts.map +0 -1
- package/types/move-types.d.ts +0 -2
- package/types/move-types.d.ts.map +0 -1
- package/types/src/components/address/question.d.ts.map +0 -1
- package/types/src/components/boolean/question.d.ts.map +0 -1
- package/types/src/components/checkbox/question.d.ts +0 -33
- package/types/src/components/checkbox/question.d.ts.map +0 -1
- package/types/src/components/date/question.d.ts.map +0 -1
- package/types/src/components/date-period/question.d.ts.map +0 -1
- package/types/src/components/date-time/question.d.ts.map +0 -1
- package/types/src/components/email/question.d.ts +0 -35
- package/types/src/components/email/question.d.ts.map +0 -1
- package/types/src/components/manage-list/manage-list-actions.d.ts.map +0 -1
- package/types/src/components/manage-list/manage-list-section.d.ts.map +0 -1
- package/types/src/components/manage-list/question.d.ts.map +0 -1
- package/types/src/components/manage-list/utils.d.ts.map +0 -1
- package/types/src/components/multi-field-input/question.d.ts +0 -64
- package/types/src/components/multi-field-input/question.d.ts.map +0 -1
- package/types/src/components/number-entry/question.d.ts +0 -36
- package/types/src/components/number-entry/question.d.ts.map +0 -1
- package/types/src/components/radio/question.d.ts +0 -23
- package/types/src/components/radio/question.d.ts.map +0 -1
- package/types/src/components/select/question.d.ts +0 -22
- package/types/src/components/select/question.d.ts.map +0 -1
- package/types/src/components/single-line-input/question.d.ts.map +0 -1
- package/types/src/components/text-entry/question.d.ts.map +0 -1
- package/types/src/components/text-entry-redact/question.d.ts.map +0 -1
- package/types/src/components/unit-option-entry/question.d.ts.map +0 -1
- package/types/src/components/utils/component-types.d.ts.map +0 -1
- package/types/src/components/utils/persisted-number-answer.d.ts.map +0 -1
- package/types/src/components/utils/question-has-answer.d.ts.map +0 -1
- package/types/src/components/utils/question-utils.d.ts +0 -15
- package/types/src/components/utils/question-utils.d.ts.map +0 -1
- package/types/src/controller.d.ts.map +0 -1
- package/types/src/index.d.ts.map +0 -1
- package/types/src/journey/journey-response.d.ts +0 -32
- package/types/src/journey/journey-response.d.ts.map +0 -1
- package/types/src/journey/journey-types.d.ts +0 -28
- package/types/src/journey/journey-types.d.ts.map +0 -1
- package/types/src/journey/journey.d.ts.map +0 -1
- package/types/src/lib/address-utils.d.ts.map +0 -1
- package/types/src/lib/address.d.ts.map +0 -1
- package/types/src/lib/date-utils.d.ts.map +0 -1
- package/types/src/lib/session-answer-store.d.ts.map +0 -1
- package/types/src/lib/utils.d.ts.map +0 -1
- package/types/src/lib/uuid.d.ts.map +0 -1
- package/types/src/middleware/build-get-journey.d.ts.map +0 -1
- package/types/src/middleware/redirect-to-unanswered-question.d.ts +0 -12
- package/types/src/middleware/redirect-to-unanswered-question.d.ts.map +0 -1
- package/types/src/questions/create-questions.d.ts +0 -18
- package/types/src/questions/create-questions.d.ts.map +0 -1
- package/types/src/questions/options-question.d.ts.map +0 -1
- package/types/src/questions/question-props.d.ts.map +0 -1
- package/types/src/questions/question-types.d.ts +0 -86
- package/types/src/questions/question-types.d.ts.map +0 -1
- package/types/src/questions/question.d.ts.map +0 -1
- package/types/src/questions/questions.d.ts +0 -3
- package/types/src/questions/questions.d.ts.map +0 -1
- package/types/src/section.d.ts.map +0 -1
- package/types/src/validator/address-validator.d.ts.map +0 -1
- package/types/src/validator/base-validator.d.ts.map +0 -1
- package/types/src/validator/conditional-required-validator.d.ts.map +0 -1
- package/types/src/validator/confirmation-checkbox-validator.d.ts.map +0 -1
- package/types/src/validator/coordinates-validator.d.ts.map +0 -1
- package/types/src/validator/cross-question-validator.d.ts.map +0 -1
- package/types/src/validator/date-period-validator.d.ts.map +0 -1
- package/types/src/validator/date-time-validator.d.ts.map +0 -1
- package/types/src/validator/date-validator.d.ts.map +0 -1
- package/types/src/validator/document-upload-validator.d.ts.map +0 -1
- package/types/src/validator/email-validator.d.ts.map +0 -1
- package/types/src/validator/multi-field-input-validator.d.ts.map +0 -1
- package/types/src/validator/numeric-validator.d.ts.map +0 -1
- package/types/src/validator/required-validator.d.ts.map +0 -1
- package/types/src/validator/same-answer-validator.d.ts.map +0 -1
- package/types/src/validator/string-validator.d.ts.map +0 -1
- package/types/src/validator/unit-option-entry-validator.d.ts.map +0 -1
- package/types/src/validator/valid-option-validator.d.ts.map +0 -1
- package/types/src/validator/validation-error-handler.d.ts.map +0 -1
- package/types/src/validator/validator.d.ts.map +0 -1
- /package/{types/src → src}/components/manage-list/manage-list-actions.d.ts +0 -0
- /package/{types/src → src}/components/manage-list/manage-list-section.d.ts +0 -0
- /package/{types/src → src}/components/utils/component-types.d.ts +0 -0
- /package/{types/src → src}/components/utils/persisted-number-answer.d.ts +0 -0
- /package/{types/src → src}/components/utils/question-has-answer.d.ts +0 -0
- /package/{types/src → src}/lib/address-utils.d.ts +0 -0
- /package/{types/src → src}/lib/address.d.ts +0 -0
- /package/{types/src → src}/lib/date-utils.d.ts +0 -0
- /package/{types/src → src}/lib/session-answer-store.d.ts +0 -0
- /package/{types/src → src}/lib/utils.d.ts +0 -0
- /package/{types/src → src}/lib/uuid.d.ts +0 -0
- /package/{types/src → src}/middleware/build-get-journey.d.ts +0 -0
- /package/{types/src → src}/validator/address-validator.d.ts +0 -0
- /package/{types/src → src}/validator/base-validator.d.ts +0 -0
- /package/{types/src → src}/validator/conditional-required-validator.d.ts +0 -0
- /package/{types/src → src}/validator/confirmation-checkbox-validator.d.ts +0 -0
- /package/{types/src → src}/validator/coordinates-validator.d.ts +0 -0
- /package/{types/src → src}/validator/cross-question-validator.d.ts +0 -0
- /package/{types/src → src}/validator/date-period-validator.d.ts +0 -0
- /package/{types/src → src}/validator/date-time-validator.d.ts +0 -0
- /package/{types/src → src}/validator/date-validator.d.ts +0 -0
- /package/{types/src → src}/validator/document-upload-validator.d.ts +0 -0
- /package/{types/src → src}/validator/email-validator.d.ts +0 -0
- /package/{types/src → src}/validator/required-validator.d.ts +0 -0
- /package/{types/src → src}/validator/same-answer-validator.d.ts +0 -0
- /package/{types/src → src}/validator/unit-option-entry-validator.d.ts +0 -0
- /package/{types/src → src}/validator/valid-option-validator.d.ts +0 -0
- /package/{types/src → src}/validator/validation-error-handler.d.ts +0 -0
- /package/{types/src → src}/validator/validator.d.ts +0 -0
- /package/{src/journey → typedefs}/journey-types.d.ts +0 -0
- /package/{src/journey → typedefs}/journey-types.js +0 -0
- /package/{src/questions → typedefs}/question-props.js +0 -0
- /package/{src/questions → typedefs}/question-types.js +0 -0
|
@@ -96,78 +96,157 @@ describe('./src/dynamic-forms/components/radio/question.js', () => {
|
|
|
96
96
|
assert.strictEqual(preppedQuestion.question.label, LABEL);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
describe('formatAnswer', () => {
|
|
100
|
+
it('should delegate simple string answers to parent class', () => {
|
|
101
|
+
const radioQuestion = new RadioQuestion({
|
|
102
|
+
title: TITLE,
|
|
103
|
+
question: QUESTION,
|
|
104
|
+
description: DESCRIPTION,
|
|
105
|
+
fieldName: FIELDNAME,
|
|
106
|
+
options: [
|
|
107
|
+
{ text: 'Option 1', value: 'op-1' },
|
|
108
|
+
{ text: 'Option 2', value: 'op-2' }
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const result = radioQuestion.formatAnswer('op-1');
|
|
113
|
+
assert.strictEqual(result, 'Option 1');
|
|
109
114
|
});
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
it('should format object answer with value only (no conditional)', () => {
|
|
117
|
+
const radioQuestion = new RadioQuestion({
|
|
118
|
+
title: TITLE,
|
|
119
|
+
question: QUESTION,
|
|
120
|
+
description: DESCRIPTION,
|
|
121
|
+
fieldName: FIELDNAME,
|
|
122
|
+
options: OPTIONS
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const result = radioQuestion.formatAnswer({ value: 'no' });
|
|
126
|
+
assert.strictEqual(result, 'No');
|
|
114
127
|
});
|
|
115
|
-
assert.strictEqual(rowParams[0].value, 'Yes<br>test');
|
|
116
|
-
});
|
|
117
128
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
{
|
|
130
|
-
|
|
129
|
+
it('should format object answer with conditional', () => {
|
|
130
|
+
const radioQuestion = new RadioQuestion({
|
|
131
|
+
title: TITLE,
|
|
132
|
+
question: QUESTION,
|
|
133
|
+
description: DESCRIPTION,
|
|
134
|
+
fieldName: FIELDNAME,
|
|
135
|
+
options: OPTIONS
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const result = radioQuestion.formatAnswer({
|
|
139
|
+
value: 'yes',
|
|
140
|
+
conditional: { yes: 'test details' }
|
|
141
|
+
});
|
|
142
|
+
assert.strictEqual(result, 'Yes<br>test details');
|
|
131
143
|
});
|
|
132
144
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
145
|
+
it('should format object answer with conditional and label', () => {
|
|
146
|
+
const optionsWithLabel = [...OPTIONS];
|
|
147
|
+
optionsWithLabel[0] = {
|
|
148
|
+
...optionsWithLabel[0],
|
|
149
|
+
conditional: {
|
|
150
|
+
...optionsWithLabel[0].conditional,
|
|
151
|
+
label: 'label:'
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const radioQuestion = new RadioQuestion({
|
|
155
|
+
title: TITLE,
|
|
156
|
+
question: QUESTION,
|
|
157
|
+
description: DESCRIPTION,
|
|
158
|
+
fieldName: FIELDNAME,
|
|
159
|
+
options: optionsWithLabel
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const result = radioQuestion.formatAnswer({
|
|
163
|
+
value: 'yes',
|
|
164
|
+
conditional: { yes: 'test details' }
|
|
165
|
+
});
|
|
166
|
+
assert.strictEqual(result, 'Yes<br>label: test details');
|
|
167
|
+
});
|
|
136
168
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
options: optionsWithLabel
|
|
169
|
+
it('should fall back to value when option not found in object answer', () => {
|
|
170
|
+
const radioQuestion = new RadioQuestion({
|
|
171
|
+
title: TITLE,
|
|
172
|
+
question: QUESTION,
|
|
173
|
+
description: DESCRIPTION,
|
|
174
|
+
fieldName: FIELDNAME,
|
|
175
|
+
options: OPTIONS
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const result = radioQuestion.formatAnswer({ value: 'unknown' });
|
|
179
|
+
assert.strictEqual(result, 'unknown');
|
|
149
180
|
});
|
|
150
181
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
182
|
+
it('should escape HTML in option text', () => {
|
|
183
|
+
const radioQuestion = new RadioQuestion({
|
|
184
|
+
title: TITLE,
|
|
185
|
+
question: QUESTION,
|
|
186
|
+
description: DESCRIPTION,
|
|
187
|
+
fieldName: FIELDNAME,
|
|
188
|
+
options: [{ text: '<script>alert("xss")</script>', value: 'xss' }]
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const result = radioQuestion.formatAnswer('xss');
|
|
192
|
+
assert.strictEqual(result, '<script>alert("xss")</script>');
|
|
154
193
|
});
|
|
155
|
-
assert.strictEqual(rowParams[0].value, 'Yes<br>label: test');
|
|
156
|
-
});
|
|
157
194
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
195
|
+
it('should escape HTML in conditional value', () => {
|
|
196
|
+
const radioQuestion = new RadioQuestion({
|
|
197
|
+
title: TITLE,
|
|
198
|
+
question: QUESTION,
|
|
199
|
+
description: DESCRIPTION,
|
|
200
|
+
fieldName: FIELDNAME,
|
|
201
|
+
options: [
|
|
202
|
+
{
|
|
203
|
+
text: 'Yes',
|
|
204
|
+
value: 'yes',
|
|
205
|
+
conditional: { fieldName: 'details', type: 'text' }
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const result = radioQuestion.formatAnswer({
|
|
211
|
+
value: 'yes',
|
|
212
|
+
conditional: { yes: '<img src=x onerror=alert(1)>' }
|
|
213
|
+
});
|
|
214
|
+
assert.strictEqual(result, 'Yes<br><img src=x onerror=alert(1)>');
|
|
168
215
|
});
|
|
169
216
|
|
|
170
|
-
|
|
171
|
-
|
|
217
|
+
it('should escape HTML in conditional label', () => {
|
|
218
|
+
const radioQuestion = new RadioQuestion({
|
|
219
|
+
title: TITLE,
|
|
220
|
+
question: QUESTION,
|
|
221
|
+
description: DESCRIPTION,
|
|
222
|
+
fieldName: FIELDNAME,
|
|
223
|
+
options: [
|
|
224
|
+
{
|
|
225
|
+
text: 'Yes',
|
|
226
|
+
value: 'yes',
|
|
227
|
+
conditional: { fieldName: 'details', type: 'text', label: '<b>Label</b>' }
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const result = radioQuestion.formatAnswer({
|
|
233
|
+
value: 'yes',
|
|
234
|
+
conditional: { yes: 'safe value' }
|
|
235
|
+
});
|
|
236
|
+
assert.strictEqual(result, 'Yes<br><b>Label</b> safe value');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('should escape HTML in fallback value when option not found', () => {
|
|
240
|
+
const radioQuestion = new RadioQuestion({
|
|
241
|
+
title: TITLE,
|
|
242
|
+
question: QUESTION,
|
|
243
|
+
description: DESCRIPTION,
|
|
244
|
+
fieldName: FIELDNAME,
|
|
245
|
+
options: OPTIONS
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const result = radioQuestion.formatAnswer({ value: '<script>xss</script>' });
|
|
249
|
+
assert.strictEqual(result, '<script>xss</script>');
|
|
250
|
+
});
|
|
172
251
|
});
|
|
173
252
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class SelectQuestion extends OptionsQuestion {
|
|
2
|
+
/**
|
|
3
|
+
* @param {import('#typedefs/question-props.d.ts').SelectQuestionParams} params
|
|
4
|
+
*/
|
|
5
|
+
constructor({ label, html, legend, disableAccessibleAutocomplete, viewFolder, ...parentParams }: import("#typedefs/question-props.d.ts").SelectQuestionParams);
|
|
6
|
+
label: string | undefined;
|
|
7
|
+
legend: string | undefined;
|
|
8
|
+
#private;
|
|
9
|
+
}
|
|
10
|
+
export default SelectQuestion;
|
|
11
|
+
import OptionsQuestion from '../../questions/options-question.js';
|
|
12
|
+
//# sourceMappingURL=question.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["question.js"],"names":[],"mappings":"AAEA;IAEC;;OAEG;IACH,iGAFW,OAAO,+BAA+B,EAAE,oBAAoB,EAYtE;IAHA,0BAAkB;IAClB,2BAAoB;;CAYrB;;4BA3B2B,qCAAqC"}
|
|
@@ -3,37 +3,12 @@ import OptionsQuestion from '../../questions/options-question.js';
|
|
|
3
3
|
export class SelectQuestion extends OptionsQuestion {
|
|
4
4
|
#disableAccessibleAutocomplete;
|
|
5
5
|
/**
|
|
6
|
-
* @param {import('
|
|
6
|
+
* @param {import('#typedefs/question-props.d.ts').SelectQuestionParams} params
|
|
7
7
|
*/
|
|
8
|
-
constructor({
|
|
9
|
-
title,
|
|
10
|
-
question,
|
|
11
|
-
fieldName,
|
|
12
|
-
viewFolder,
|
|
13
|
-
url,
|
|
14
|
-
hint,
|
|
15
|
-
pageTitle,
|
|
16
|
-
description,
|
|
17
|
-
label,
|
|
18
|
-
html,
|
|
19
|
-
legend,
|
|
20
|
-
disableAccessibleAutocomplete,
|
|
21
|
-
options,
|
|
22
|
-
validators,
|
|
23
|
-
viewData
|
|
24
|
-
}) {
|
|
8
|
+
constructor({ label, html, legend, disableAccessibleAutocomplete, viewFolder, ...parentParams }) {
|
|
25
9
|
super({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
viewFolder: !viewFolder ? 'select' : viewFolder,
|
|
29
|
-
fieldName,
|
|
30
|
-
url,
|
|
31
|
-
hint,
|
|
32
|
-
pageTitle,
|
|
33
|
-
description,
|
|
34
|
-
options,
|
|
35
|
-
validators,
|
|
36
|
-
viewData
|
|
10
|
+
...parentParams,
|
|
11
|
+
viewFolder: viewFolder || 'select'
|
|
37
12
|
});
|
|
38
13
|
|
|
39
14
|
this.html = html;
|
|
@@ -43,31 +18,13 @@ export class SelectQuestion extends OptionsQuestion {
|
|
|
43
18
|
}
|
|
44
19
|
|
|
45
20
|
/**
|
|
46
|
-
* @param {import('#question').QuestionViewModel} viewModel
|
|
21
|
+
* @param {import('#typedefs/question-types.d.ts').QuestionViewModel} viewModel
|
|
47
22
|
*/
|
|
48
23
|
addCustomDataToViewModel(viewModel) {
|
|
49
24
|
viewModel.question.label = this.label;
|
|
50
25
|
viewModel.question.legend = this.legend;
|
|
51
26
|
viewModel.question.disableAccessibleAutocomplete = this.#disableAccessibleAutocomplete;
|
|
52
27
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* returns the formatted answers values to be used to build task list elements
|
|
56
|
-
* note: only supports a single answer
|
|
57
|
-
*
|
|
58
|
-
* @param {unknown} answer
|
|
59
|
-
* @param {Journey} journey
|
|
60
|
-
* @param {String} sectionSegment
|
|
61
|
-
* @returns {Array.<Object>}
|
|
62
|
-
*/
|
|
63
|
-
formatAnswerForSummary(sectionSegment, journey, answer) {
|
|
64
|
-
if (answer) {
|
|
65
|
-
const selectedOption = this.options.find((option) => option.value === answer);
|
|
66
|
-
const selectedText = selectedOption?.text || '';
|
|
67
|
-
return super.formatAnswerForSummary(sectionSegment, journey, selectedText, false);
|
|
68
|
-
}
|
|
69
|
-
return super.formatAnswerForSummary(sectionSegment, journey, answer);
|
|
70
|
-
}
|
|
71
28
|
}
|
|
72
29
|
|
|
73
30
|
export default SelectQuestion;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export class SingleLineInputQuestion extends Question {
|
|
5
5
|
/**
|
|
6
|
-
* @param {import('
|
|
6
|
+
* @param {import('#typedefs/question-props.d.ts').SingleLineInputQuestionParams} params
|
|
7
7
|
*/
|
|
8
|
-
constructor(params: import("
|
|
8
|
+
constructor(params: import("#typedefs/question-props.d.ts").SingleLineInputQuestionParams);
|
|
9
9
|
/** @type {Record<string, string>} */
|
|
10
10
|
inputAttributes: Record<string, string>;
|
|
11
11
|
label: string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["question.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IAIC;;OAEG;IACH,oBAFW,OAAO,+BAA+B,EAAE,6BAA6B,EAW/E;IAfD,qCAAqC;IACrC,iBADW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACjB;IAWf,0BAAyB;IAEzB,gBAAmC;CAepC;;yBAnCwB,WAAW"}
|
|
@@ -8,7 +8,7 @@ export class SingleLineInputQuestion extends Question {
|
|
|
8
8
|
inputAttributes;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* @param {import('
|
|
11
|
+
* @param {import('#typedefs/question-props.d.ts').SingleLineInputQuestionParams} params
|
|
12
12
|
*/
|
|
13
13
|
constructor(params) {
|
|
14
14
|
super({
|
|
@@ -22,7 +22,7 @@ export class SingleLineInputQuestion extends Question {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @param {import('#question').QuestionViewModel} viewModel
|
|
25
|
+
* @param {import('#typedefs/question-types.d.ts').QuestionViewModel} viewModel
|
|
26
26
|
*/
|
|
27
27
|
addCustomDataToViewModel(viewModel) {
|
|
28
28
|
viewModel.question.label = this.label;
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export class TextEntryQuestion extends Question {
|
|
18
18
|
/**
|
|
19
|
-
* @param {import('
|
|
19
|
+
* @param {import('#typedefs/question-props.d.ts').TextEntryQuestionParams} params
|
|
20
20
|
*/
|
|
21
|
-
constructor({ textEntryCheckbox, label, ...parentParams }: import("
|
|
22
|
-
textEntryCheckbox: import("
|
|
21
|
+
constructor({ textEntryCheckbox, label, ...parentParams }: import("#typedefs/question-props.d.ts").TextEntryQuestionParams);
|
|
22
|
+
textEntryCheckbox: import("#typedefs/question-props.d.ts").TextEntryCheckbox | undefined;
|
|
23
23
|
label: string | undefined;
|
|
24
24
|
}
|
|
25
25
|
export default TextEntryQuestion;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["question.js"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;GAEG;AACH;IACC;;OAEG;IACH,2DAFW,OAAO,+BAA+B,EAAE,uBAAuB,EAUzE;IAFA,yFAA0C;IAC1C,0BAAkB;CAUnB;;;YA9Ba,MAAM;UACN,MAAM;UACN,MAAM;;;yBAZK,WAAW"}
|
|
@@ -19,7 +19,7 @@ import { Question } from '#question';
|
|
|
19
19
|
*/
|
|
20
20
|
export class TextEntryQuestion extends Question {
|
|
21
21
|
/**
|
|
22
|
-
* @param {import('
|
|
22
|
+
* @param {import('#typedefs/question-props.d.ts').TextEntryQuestionParams} params
|
|
23
23
|
*/
|
|
24
24
|
constructor({ textEntryCheckbox, label, ...parentParams }) {
|
|
25
25
|
super({
|
|
@@ -32,7 +32,7 @@ export class TextEntryQuestion extends Question {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* @param {import('#question').QuestionViewModel} viewModel
|
|
35
|
+
* @param {import('#typedefs/question-types.d.ts').QuestionViewModel} viewModel
|
|
36
36
|
*/
|
|
37
37
|
addCustomDataToViewModel(viewModel) {
|
|
38
38
|
viewModel.question.label = this.label;
|
|
@@ -5,23 +5,22 @@ export const TRUNCATED_MAX_LENGTH: 500;
|
|
|
5
5
|
*/
|
|
6
6
|
export class TextEntryRedactQuestion extends Question {
|
|
7
7
|
/**
|
|
8
|
-
* @param {import('
|
|
8
|
+
* @param {import('#typedefs/question-props.d.ts').TextEntryRedactQuestionParams} params
|
|
9
9
|
*/
|
|
10
|
-
constructor({ textEntryCheckbox, label, onlyShowRedactedValueForSummary, useRedactedFieldNameForSave, showSuggestionsUi, summaryText, shouldTruncateSummary, ...parentParams }: import("
|
|
11
|
-
textEntryCheckbox: import("
|
|
10
|
+
constructor({ textEntryCheckbox, label, onlyShowRedactedValueForSummary, useRedactedFieldNameForSave, showSuggestionsUi, summaryText, shouldTruncateSummary, ...parentParams }: import("#typedefs/question-props.d.ts").TextEntryRedactQuestionParams);
|
|
11
|
+
textEntryCheckbox: import("#typedefs/question-props.d.ts").TextEntryCheckbox | undefined;
|
|
12
12
|
label: string | undefined;
|
|
13
13
|
onlyShowRedactedValueForSummary: boolean | undefined;
|
|
14
14
|
useRedactedFieldNameForSave: boolean | undefined;
|
|
15
15
|
showSuggestionsUi: boolean | undefined;
|
|
16
16
|
summaryText: string | undefined;
|
|
17
17
|
shouldTruncateSummary: boolean | undefined;
|
|
18
|
-
prepQuestionForRendering(section: any, journey: any, customViewData: any, payload: any, options: any): import("#question").QuestionViewModel
|
|
18
|
+
prepQuestionForRendering(section: any, journey: any, customViewData: any, payload: any, options: any): import("#typedefs/question-types.d.ts").QuestionViewModel<import("#typedefs/question-types.d.ts").BaseQuestionViewData>;
|
|
19
19
|
answerForViewModel(answers: any): string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}[];
|
|
20
|
+
/**
|
|
21
|
+
* returns the formatted answers values to be used to build task list elements
|
|
22
|
+
*/
|
|
23
|
+
formatAnswerForSummary(sectionSegment: any, journey: any, answer: any, capitals?: boolean): import("#typedefs/question-types.d.ts").SummaryRow[];
|
|
25
24
|
}
|
|
26
25
|
export default TextEntryRedactQuestion;
|
|
27
26
|
import { Question } from '#question';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["question.js"],"names":[],"mappings":"AAGA,+BAAgC,QAAG,CAAC;AACpC,mCAAoC,GAAG,CAAC;AAExC;;GAEG;AACH;IACC;;OAEG;IACH,gLAFW,OAAO,+BAA+B,EAAE,6BAA6B,EAwB/E;IAPA,yFAA0C;IAC1C,0BAAkB;IAClB,qDAAsE;IACtE,iDAA8D;IAC9D,uCAA0C;IAC1C,gCAA8B;IAC9B,2CAAkD;IAkBnD,+NAOC;IAED,yCAEC;IAYD;;OAEG;IACH,iJAuBC;CACD;;yBAtGwB,WAAW"}
|
|
@@ -9,7 +9,7 @@ export const TRUNCATED_MAX_LENGTH = 500;
|
|
|
9
9
|
*/
|
|
10
10
|
export class TextEntryRedactQuestion extends Question {
|
|
11
11
|
/**
|
|
12
|
-
* @param {import('
|
|
12
|
+
* @param {import('#typedefs/question-props.d.ts').TextEntryRedactQuestionParams} params
|
|
13
13
|
*/
|
|
14
14
|
constructor({
|
|
15
15
|
textEntryCheckbox,
|
|
@@ -64,7 +64,7 @@ export class TextEntryRedactQuestion extends Question {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* @param {import('#question').QuestionViewModel} viewModel
|
|
67
|
+
* @param {import('#typedefs/question-types.d.ts').QuestionViewModel} viewModel
|
|
68
68
|
*/
|
|
69
69
|
addCustomDataToViewModel(viewModel) {
|
|
70
70
|
viewModel.question.label = this.label;
|
|
@@ -73,6 +73,9 @@ export class TextEntryRedactQuestion extends Question {
|
|
|
73
73
|
viewModel.showSuggestionsUi = this.showSuggestionsUi;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* returns the formatted answers values to be used to build task list elements
|
|
78
|
+
*/
|
|
76
79
|
formatAnswerForSummary(sectionSegment, journey, answer, capitals = true) {
|
|
77
80
|
const redacted = journey.response.answers[this.fieldName + 'Redacted'];
|
|
78
81
|
let toShow;
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
*/
|
|
25
25
|
export class UnitOptionEntryQuestion extends Question {
|
|
26
26
|
/**
|
|
27
|
-
* @param {import('
|
|
27
|
+
* @param {import('#typedefs/question-props.d.ts').UnitOptionEntryQuestionParams} params
|
|
28
28
|
* @param {Record<string, Function>} [methodOverrides]
|
|
29
29
|
*/
|
|
30
|
-
constructor({ conditionalFieldName, options, label, ...parentParams }: import("
|
|
30
|
+
constructor({ conditionalFieldName, options, label, ...parentParams }: import("#typedefs/question-props.d.ts").UnitOptionEntryQuestionParams, methodOverrides?: Record<string, Function>);
|
|
31
31
|
/** @type {Array<UnitOption>} */
|
|
32
32
|
options: Array<UnitOption>;
|
|
33
33
|
conditionalFieldName: string;
|
|
@@ -35,19 +35,19 @@ export class UnitOptionEntryQuestion extends Question {
|
|
|
35
35
|
optionJoinString: string;
|
|
36
36
|
/**
|
|
37
37
|
* gets the view model for this question
|
|
38
|
-
* @param {import('../../section').Section} section - the current section
|
|
38
|
+
* @param {import('../../section.js').Section} section - the current section
|
|
39
39
|
* @param {import('#journey').Journey} journey - the journey we are in
|
|
40
40
|
* @param {Record<string, unknown>} [customViewData] additional data to send to view
|
|
41
41
|
* @param {Record<string, unknown>} [payload]
|
|
42
|
-
* @param {import('#question-types').PrepQuestionForRenderingOptions} options
|
|
43
|
-
* @returns {import('
|
|
44
|
-
* question: import('
|
|
42
|
+
* @param {import('#typedefs/question-types.d.ts').PrepQuestionForRenderingOptions} options
|
|
43
|
+
* @returns {import('#typedefs/question-types.d.ts').QuestionViewModel & {
|
|
44
|
+
* question: import('#typedefs/question-types.d.ts').QuestionViewModel['question'] & {
|
|
45
45
|
* options:UnitOption[]
|
|
46
46
|
* }
|
|
47
47
|
* }}
|
|
48
48
|
*/
|
|
49
|
-
prepQuestionForRendering(section:
|
|
50
|
-
question: import("
|
|
49
|
+
prepQuestionForRendering(section: import("../../section.js").Section, journey: import("#journey").Journey, customViewData?: Record<string, unknown>, payload?: Record<string, unknown>, options: import("#typedefs/question-types.d.ts").PrepQuestionForRenderingOptions): import("#typedefs/question-types.d.ts").QuestionViewModel & {
|
|
50
|
+
question: import("#typedefs/question-types.d.ts").QuestionViewModel["question"] & {
|
|
51
51
|
options: UnitOption[];
|
|
52
52
|
};
|
|
53
53
|
};
|
|
@@ -59,6 +59,10 @@ export class UnitOptionEntryQuestion extends Question {
|
|
|
59
59
|
*/ getDataToSave(req: import("express").Request, journeyResponse: JourneyResponse): Promise<{
|
|
60
60
|
answers: Record<string, unknown>;
|
|
61
61
|
}>;
|
|
62
|
+
/**
|
|
63
|
+
* returns the formatted answers values to be used to build task list elements
|
|
64
|
+
*/
|
|
65
|
+
formatAnswerForSummary(sectionSegment: any, journey: any, answer: any): import("#typedefs/question-types.d.ts").SummaryRow[];
|
|
62
66
|
}
|
|
63
67
|
export default UnitOptionEntryQuestion;
|
|
64
68
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["question.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;IAIC;;;OAGG;IACH,uEAHW,OAAO,+BAA+B,EAAE,6BAA6B,oBACrE,MAAM,CAAC,MAAM,WAAW,EAkBlC;IAvBD,gCAAgC;IAChC,SADW,KAAK,CAAC,UAAU,CAAC,CACpB;IAkBP,6BAAgD;IAEhD,0BAAkB;IAClB,yBAA+C;IAGhD;;;;;;;;;;;;OAYG;IACH,kCAXW,OAAO,kBAAkB,EAAE,OAAO,WAClC,OAAO,UAAU,EAAE,OAAO,mBAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WACvB,OAAO,+BAA+B,EAAE,+BAA+B,GACrE,OAAO,+BAA+B,EAAE,iBAAiB,GAAG;QACpE,QAAQ,EAAE,OAAO,+BAA+B,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG;YAChF,OAAO,EAAC,UAAU,EAAE,CAAA;SACrB,CAAA;KACF,CAmDH;IAED;;;;;OAKG,CACH,mBAJW,OAAO,SAAS,EAAE,OAAO,mBACzB,eAAe,GACb,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAgCzD;IAED;;OAEG;IACH,6HAaC;CACD;;;;;;;;;;yBAnKY;IACR,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,WAAW,EAAE;QACX,SAAS,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,OAAO,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAA;CACH;yBA5BsB,6BAA6B"}
|
|
@@ -35,7 +35,7 @@ export class UnitOptionEntryQuestion extends Question {
|
|
|
35
35
|
options;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* @param {import('
|
|
38
|
+
* @param {import('#typedefs/question-props.d.ts').UnitOptionEntryQuestionParams} params
|
|
39
39
|
* @param {Record<string, Function>} [methodOverrides]
|
|
40
40
|
*/
|
|
41
41
|
constructor({ conditionalFieldName, options, label, ...parentParams }, methodOverrides) {
|
|
@@ -58,13 +58,13 @@ export class UnitOptionEntryQuestion extends Question {
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* gets the view model for this question
|
|
61
|
-
* @param {import('../../section').Section} section - the current section
|
|
61
|
+
* @param {import('../../section.js').Section} section - the current section
|
|
62
62
|
* @param {import('#journey').Journey} journey - the journey we are in
|
|
63
63
|
* @param {Record<string, unknown>} [customViewData] additional data to send to view
|
|
64
64
|
* @param {Record<string, unknown>} [payload]
|
|
65
|
-
* @param {import('#question-types').PrepQuestionForRenderingOptions} options
|
|
66
|
-
* @returns {import('
|
|
67
|
-
* question: import('
|
|
65
|
+
* @param {import('#typedefs/question-types.d.ts').PrepQuestionForRenderingOptions} options
|
|
66
|
+
* @returns {import('#typedefs/question-types.d.ts').QuestionViewModel & {
|
|
67
|
+
* question: import('#typedefs/question-types.d.ts').QuestionViewModel['question'] & {
|
|
68
68
|
* options:UnitOption[]
|
|
69
69
|
* }
|
|
70
70
|
* }}
|
|
@@ -160,7 +160,6 @@ export class UnitOptionEntryQuestion extends Question {
|
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* returns the formatted answers values to be used to build task list elements
|
|
163
|
-
* @type {Question['formatAnswerForSummary']}
|
|
164
163
|
*/
|
|
165
164
|
formatAnswerForSummary(sectionSegment, journey, answer) {
|
|
166
165
|
if (answer == null) return super.formatAnswerForSummary(sectionSegment, journey, answer);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-types.d.ts","sourceRoot":"","sources":["component-types.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persisted-number-answer.d.ts","sourceRoot":"","sources":["persisted-number-answer.js"],"names":[],"mappings":"AAGO,iDAFI,MAAM,mBAYhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-has-answer.d.ts","sourceRoot":"","sources":["question-has-answer.js"],"names":[],"mappings":"AAOO,8CAHI,OAAO,mCAAmC,EAAE,eAAe,GACzD;IAAC,GAAG,EAAE,eAAe,CAAC;IAAC,EAAE,EAAE,eAAe,CAAA;CAAC,CAOtD;AAYK,gDAJI,OAAO,6BAA6B,EAAE,QAAQ,iBAC9C,OAAO,GACL,OAAO,kBAAkB,EAAE,iBAAiB,CAIxD;AAUM,4CALI,OAAO,mCAAmC,EAAE,eAAe,YAC3D,OAAO,6BAA6B,EAAE,QAAQ,GAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAC,iBACzE,OAAO,GACL,OAAO,CAgBnB;AAUM,sDALI,OAAO,mCAAmC,EAAE,eAAe,YAC3D,GAAG,gBACH,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,GACpB,OAAO,CAWnB;AASM,+CANI,OAAO,mCAAmC,EAAE,eAAe,qBAC3D,iBAAiB,0BAEzB;IAA8B,iBAAiB,EAAvC,KAAK,GAAG,IAAI;CACpB,GAAU,OAAO,CAUnB;AAOM,0DAJI,OAAO,mCAAmC,EAAE,eAAe,YAC3D,OAAO,6BAA6B,EAAE,QAAQ,GAC5C,OAAO,CAMnB;AAOM,0DAJI,OAAO,mCAAmC,EAAE,eAAe,YAC3D,OAAO,6BAA6B,EAAE,QAAQ,GAC5C,OAAO,CAMnB;gCA5Ga,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;8BAChB,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,OAAO"}
|
|
@@ -41,7 +41,7 @@ export const questionHasAnswer = (response, question, expectedValue) => {
|
|
|
41
41
|
if (Array.isArray(answerField)) {
|
|
42
42
|
return answerField.includes(expectedValue);
|
|
43
43
|
} else if (question.optionJoinString && typeof answerField === 'string') {
|
|
44
|
-
// todo: answers from options questions sometimes are array sometimes string, why?
|
|
44
|
+
// todo: DF-51 answers from options questions sometimes are array sometimes string, why?
|
|
45
45
|
if (!answerField) return false;
|
|
46
46
|
const answers = answerField.split(question.optionJoinString);
|
|
47
47
|
return answers.includes(expectedValue);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function getConditionalFieldName(parentField: any, conditionalField: any): string;
|
|
2
|
+
/**
|
|
3
|
+
* Get conditional answer(s) for a question.
|
|
4
|
+
* Returns an object keyed by option value with conditional answers, or null if no conditionals exist.
|
|
5
|
+
*
|
|
6
|
+
* @param {Record<string, unknown>} answers - all answers
|
|
7
|
+
* @param {{options?: Array<{value: string, conditional?: {fieldName: string}}>, fieldName: string, optionJoinString?: string}} question - question with options
|
|
8
|
+
* @param {string} answer - the answer value (may be separated by optionJoinString for checkboxes)
|
|
9
|
+
* @returns {Record<string, string> | null} conditional answer(s) keyed by option value
|
|
10
|
+
*/
|
|
11
|
+
export function getConditionalAnswer(answers: Record<string, unknown>, question: {
|
|
12
|
+
options?: Array<{
|
|
13
|
+
value: string;
|
|
14
|
+
conditional?: {
|
|
15
|
+
fieldName: string;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
fieldName: string;
|
|
19
|
+
optionJoinString?: string;
|
|
20
|
+
}, answer: string): Record<string, string> | null;
|
|
21
|
+
/**
|
|
22
|
+
* @param {unknown} conditional
|
|
23
|
+
* @returns {conditional is {html: string}}
|
|
24
|
+
*/
|
|
25
|
+
export function conditionalIsJustHTML(conditional: unknown): conditional is {
|
|
26
|
+
html: string;
|
|
27
|
+
};
|
|
28
|
+
declare namespace _default {
|
|
29
|
+
export { getConditionalAnswer };
|
|
30
|
+
export { getConditionalFieldName };
|
|
31
|
+
}
|
|
32
|
+
export default _default;
|
|
33
|
+
//# sourceMappingURL=question-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-utils.d.ts","sourceRoot":"","sources":["question-utils.js"],"names":[],"mappings":"AAAA,yFAEC;AAED;;;;;;;;GAQG;AACH,8CALW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACvB;IAAC,OAAO,CAAC,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE;YAAC,SAAS,EAAE,MAAM,CAAA;SAAC,CAAA;KAAC,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAC,UACnH,MAAM,GACJ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAyBzC;AAED;;;GAGG;AACH,mDAHW,OAAO,GACL,WAAW,IAAI;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAIzC"}
|
|
@@ -2,9 +2,38 @@ export function getConditionalFieldName(parentField, conditionalField) {
|
|
|
2
2
|
return `${parentField}_${conditionalField}`;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Get conditional answer(s) for a question.
|
|
7
|
+
* Returns an object keyed by option value with conditional answers, or null if no conditionals exist.
|
|
8
|
+
*
|
|
9
|
+
* @param {Record<string, unknown>} answers - all answers
|
|
10
|
+
* @param {{options?: Array<{value: string, conditional?: {fieldName: string}}>, fieldName: string, optionJoinString?: string}} question - question with options
|
|
11
|
+
* @param {string} answer - the answer value (may be separated by optionJoinString for checkboxes)
|
|
12
|
+
* @returns {Record<string, string> | null} conditional answer(s) keyed by option value
|
|
13
|
+
*/
|
|
5
14
|
export function getConditionalAnswer(answers, question, answer) {
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
if (!answer || !question.options) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// TODO DF-51 treat as an array
|
|
20
|
+
const joinString = question.optionJoinString || ',';
|
|
21
|
+
const answerValues = String(answer)
|
|
22
|
+
.split(joinString)
|
|
23
|
+
.map((v) => v.trim());
|
|
24
|
+
|
|
25
|
+
const conditionals = {};
|
|
26
|
+
for (const value of answerValues) {
|
|
27
|
+
const option = question.options.find((opt) => opt.value === value);
|
|
28
|
+
if (!option?.conditional?.fieldName) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const conditionalValue = answers[getConditionalFieldName(question.fieldName, option.conditional.fieldName)];
|
|
32
|
+
if (conditionalValue) {
|
|
33
|
+
conditionals[value] = conditionalValue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return Object.keys(conditionals).length > 0 ? conditionals : null;
|
|
8
37
|
}
|
|
9
38
|
|
|
10
39
|
/**
|