@planning-inspectorate/dynamic-forms 3.8.0 → 3.8.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/.azure/pipelines/azure-pipelines-pr.yml +1 -2
- package/package.json +1 -1
- package/src/controller.js +2 -4
- package/src/controller.test.js +50 -0
- package/src/validator/address-validator.js +2 -3
- package/src/validator/string-validator.js +3 -3
- package/types/src/components/address/question.d.ts +5 -1
- package/types/src/components/address/question.d.ts.map +1 -1
- package/types/src/controller.d.ts.map +1 -1
- package/types/src/validator/address-validator.d.ts +13 -7
- package/types/src/validator/address-validator.d.ts.map +1 -1
- package/types/src/validator/string-validator.d.ts +6 -6
|
@@ -16,14 +16,13 @@ resources:
|
|
|
16
16
|
type: github
|
|
17
17
|
endpoint: Planning-Inspectorate
|
|
18
18
|
name: Planning-Inspectorate/common-pipeline-templates
|
|
19
|
-
ref: refs/tags/release/3.
|
|
19
|
+
ref: refs/tags/release/3.25.2
|
|
20
20
|
|
|
21
21
|
extends:
|
|
22
22
|
template: stages/wrapper_ci.yml@templates
|
|
23
23
|
parameters:
|
|
24
24
|
gitFetchDepth: 0
|
|
25
25
|
skipAzureAuth: true
|
|
26
|
-
skipGitTagging: true
|
|
27
26
|
validationJobs:
|
|
28
27
|
- name: Run Linting & Tests
|
|
29
28
|
steps:
|
package/package.json
CHANGED
package/src/controller.js
CHANGED
|
@@ -53,7 +53,7 @@ function buildSectionViewModel(name, status = '') {
|
|
|
53
53
|
* build a view model for a row in the journey overview
|
|
54
54
|
* @param {string} key
|
|
55
55
|
* @param {string} value
|
|
56
|
-
* @param {ActionView|ActionView[]} action
|
|
56
|
+
* @param {ActionView|ActionView[]} [action]
|
|
57
57
|
* @returns {RowView} a representation of a row
|
|
58
58
|
*/
|
|
59
59
|
function buildSectionRowViewModel(key, value, action) {
|
|
@@ -64,9 +64,7 @@ function buildSectionRowViewModel(key, value, action) {
|
|
|
64
64
|
value: {
|
|
65
65
|
html: value
|
|
66
66
|
},
|
|
67
|
-
actions: {
|
|
68
|
-
items: toArray(action)
|
|
69
|
-
}
|
|
67
|
+
actions: action ? { items: toArray(action) } : undefined
|
|
70
68
|
};
|
|
71
69
|
}
|
|
72
70
|
|
package/src/controller.test.js
CHANGED
|
@@ -299,6 +299,56 @@ describe('dynamic-form/controller', () => {
|
|
|
299
299
|
assert.strictEqual(args[0], mockJourney.sections[0].segment);
|
|
300
300
|
assert.strictEqual(args[2], expectedAnswer.value);
|
|
301
301
|
});
|
|
302
|
+
it('should format an undefined action as undefined', async () => {
|
|
303
|
+
const mockFn = res.render.mock;
|
|
304
|
+
mockFn.resetCalls();
|
|
305
|
+
mockJourney.sections[0].questions[0].formatAnswerForSummary.mock.mockImplementation(() => [
|
|
306
|
+
{
|
|
307
|
+
key: 'Title 1a',
|
|
308
|
+
value: mockAnswer,
|
|
309
|
+
action: undefined
|
|
310
|
+
}
|
|
311
|
+
]);
|
|
312
|
+
res.locals.journeyResponse.referenceId = mockRef;
|
|
313
|
+
const appeal = { a: 1, caseReference: 2 };
|
|
314
|
+
|
|
315
|
+
const pageCaption = `Appeal ${appeal.caseReference}`;
|
|
316
|
+
await list(req, res, pageCaption, { appeal });
|
|
317
|
+
|
|
318
|
+
const renderCall = mockFn.calls[0].arguments[1];
|
|
319
|
+
const firstRowActions = renderCall.summaryListData.sections[0].list.rows[0].actions;
|
|
320
|
+
assert.strictEqual(firstRowActions, undefined);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('should format a single action object as an array in the actions property', async () => {
|
|
324
|
+
const mockFn = res.render.mock;
|
|
325
|
+
mockFn.resetCalls();
|
|
326
|
+
mockJourney.sections[0].questions[0].formatAnswerForSummary.mock.mockImplementation(() => [
|
|
327
|
+
{
|
|
328
|
+
key: 'Title 1a',
|
|
329
|
+
value: mockAnswer,
|
|
330
|
+
action: {
|
|
331
|
+
href: '/manage-appeals/questionnaire/123456/segment-1/title-1a',
|
|
332
|
+
text: 'Answer',
|
|
333
|
+
visuallyHiddenText: 'Answer'
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
]);
|
|
337
|
+
res.locals.journeyResponse.referenceId = mockRef;
|
|
338
|
+
|
|
339
|
+
await list(req, res);
|
|
340
|
+
|
|
341
|
+
const renderCall = mockFn.calls[0].arguments[1];
|
|
342
|
+
const rowActions = renderCall.summaryListData.sections[0].list.rows[0].actions;
|
|
343
|
+
assert.ok(rowActions);
|
|
344
|
+
assert.ok(Array.isArray(rowActions.items));
|
|
345
|
+
assert.strictEqual(rowActions.items.length, 1);
|
|
346
|
+
assert.deepStrictEqual(rowActions.items[0], {
|
|
347
|
+
href: '/manage-appeals/questionnaire/123456/segment-1/title-1a',
|
|
348
|
+
text: 'Answer',
|
|
349
|
+
visuallyHiddenText: 'Answer'
|
|
350
|
+
});
|
|
351
|
+
});
|
|
302
352
|
});
|
|
303
353
|
|
|
304
354
|
describe('question', () => {
|
|
@@ -31,9 +31,8 @@ export const postcodeMinLength = 5;
|
|
|
31
31
|
export default class AddressValidator extends BaseValidator {
|
|
32
32
|
/**
|
|
33
33
|
* creates an instance of an AddressValidator
|
|
34
|
-
* @param {Object} opts
|
|
35
|
-
* @param {boolean} [opts.
|
|
36
|
-
* @param {{[key: string]: boolean}} [opts.requiredFields]
|
|
34
|
+
* @param {Object} [opts]
|
|
35
|
+
* @param {{addressLine1: boolean, addressLine2: boolean, townCity: boolean, county: boolean, postcode: boolean}} [opts.requiredFields]
|
|
37
36
|
*/
|
|
38
37
|
constructor(opts) {
|
|
39
38
|
super();
|
|
@@ -4,19 +4,19 @@ import BaseValidator from './base-validator.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {Object} MinLength
|
|
6
6
|
* @property {Number} minLength
|
|
7
|
-
* @property {String} minLengthMessage
|
|
7
|
+
* @property {String} [minLengthMessage]
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @typedef {Object} MaxLength
|
|
12
12
|
* @property {Number} maxLength
|
|
13
|
-
* @property {String} maxLengthMessage
|
|
13
|
+
* @property {String} [maxLengthMessage]
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {Object} Regex
|
|
18
18
|
* @property {String | RegExp} regex
|
|
19
|
-
* @property {String} regexMessage
|
|
19
|
+
* @property {String} [regexMessage]
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
export default class StringValidator extends BaseValidator {
|
|
@@ -4,7 +4,11 @@ export default class AddressQuestion extends Question {
|
|
|
4
4
|
*/
|
|
5
5
|
constructor(params: import("#question-types").QuestionParameters);
|
|
6
6
|
requiredFields: {
|
|
7
|
-
|
|
7
|
+
addressLine1: boolean;
|
|
8
|
+
addressLine2: boolean;
|
|
9
|
+
townCity: boolean;
|
|
10
|
+
county: boolean;
|
|
11
|
+
postcode: boolean;
|
|
8
12
|
} | undefined;
|
|
9
13
|
addressLabels: {
|
|
10
14
|
addressLine1: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/address/question.js"],"names":[],"mappings":"AAOA;IACC;;OAEG;IACH,oBAFW,OAAO,iBAAiB,EAAE,kBAAkB,EAqBtD;IAXE
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/address/question.js"],"names":[],"mappings":"AAOA;IACC;;OAEG;IACH,oBAFW,OAAO,iBAAiB,EAAE,kBAAkB,EAqBtD;IAXE;;;;;;kBAA8C;IAIhD;;;;;;MAMC;IAGF;;;OAGG;IACH,4BAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,GAAC,GAAC,MAAM,CAqBpB;IAqCD;;;OAGG;IACH;;eAUC;IAuBD,kEAMC;CACD;yBAxIwB,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.js"],"names":[],"mappings":"AAsEA;;;GAGG;AACH,qCAHW,MAAM,OAKhB;AAED;;;;;GAKG;AACH,sDAHW,MAAM,YACN,MAAM,gBA8DhB;AAED;;;;GAIG;AACH,2DA0CC;AAED;;;;;;;;;;GAUG;AAEH;;GAEG;AAEH;;;;GAIG;AACH,oCAJW,UAAU,gCACV,OAAO,OAuFjB;sBApSY,OAAO,sBAAsB,EAAE,OAAO;uBACtC,OAAO,yBAAyB,EAAE,QAAQ;;;aAMzC,MAAM;YACN,MAAM;UAEjB;QAAiC,IAAI,EAA1B,KAAK,CAAE,OAAO,CAAC;KAC5B;;;SAIa;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;WAChB;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;;eAC1B,UAAU,EAAE;;;;UAKrB,MAAM;UACN,MAAM;;;;;;eAwKN,MAAM;iBACN,MAAM;sBACN,OAAO;;;;;;;yBAOR,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC"}
|
|
@@ -16,18 +16,24 @@ export const postcodeMinLength: 5;
|
|
|
16
16
|
export default class AddressValidator extends BaseValidator {
|
|
17
17
|
/**
|
|
18
18
|
* creates an instance of an AddressValidator
|
|
19
|
-
* @param {Object} opts
|
|
20
|
-
* @param {boolean} [opts.
|
|
21
|
-
* @param {{[key: string]: boolean}} [opts.requiredFields]
|
|
19
|
+
* @param {Object} [opts]
|
|
20
|
+
* @param {{addressLine1: boolean, addressLine2: boolean, townCity: boolean, county: boolean, postcode: boolean}} [opts.requiredFields]
|
|
22
21
|
*/
|
|
23
|
-
constructor(opts
|
|
24
|
-
required?: boolean | undefined;
|
|
22
|
+
constructor(opts?: {
|
|
25
23
|
requiredFields?: {
|
|
26
|
-
|
|
24
|
+
addressLine1: boolean;
|
|
25
|
+
addressLine2: boolean;
|
|
26
|
+
townCity: boolean;
|
|
27
|
+
county: boolean;
|
|
28
|
+
postcode: boolean;
|
|
27
29
|
} | undefined;
|
|
28
30
|
});
|
|
29
31
|
requiredFields: {
|
|
30
|
-
|
|
32
|
+
addressLine1: boolean;
|
|
33
|
+
addressLine2: boolean;
|
|
34
|
+
townCity: boolean;
|
|
35
|
+
county: boolean;
|
|
36
|
+
postcode: boolean;
|
|
31
37
|
} | undefined;
|
|
32
38
|
/**
|
|
33
39
|
* validates response body using questionObj fieldname
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/address-validator.js"],"names":[],"mappings":"AAIO,4EAQN;AAGD,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,gCAAiC,GAAG,CAAC;AACrC,gCAAiC,CAAC,CAAC;AACnC,8BAA+B,GAAG,CAAC;AACnC,8BAA+B,CAAC,CAAC;AACjC,gCAAiC,CAAC,CAAC;AACnC,gCAAiC,CAAC,CAAC;AAEnC;;;GAGG;AACH;IACC
|
|
1
|
+
{"version":3,"file":"address-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/address-validator.js"],"names":[],"mappings":"AAIO,4EAQN;AAGD,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,gCAAiC,GAAG,CAAC;AACrC,gCAAiC,CAAC,CAAC;AACnC,8BAA+B,GAAG,CAAC;AACnC,8BAA+B,CAAC,CAAC;AACjC,gCAAiC,CAAC,CAAC;AACnC,gCAAiC,CAAC,CAAC;AAEnC;;;GAGG;AACH;IACC;;;;OAIG;IACH,mBAFG;QAAqH,cAAc;0BAA5G,OAAO;0BAAgB,OAAO;sBAAY,OAAO;oBAAU,OAAO;sBAAY,OAAO;;KAAwB,EAKtI;IADA;sBAJyB,OAAO;sBAAgB,OAAO;kBAAY,OAAO;gBAAU,OAAO;kBAAY,OAAO;kBAIpE;IAG3C;;;OAGG;IACH,sBAFW,QAAQ,iDAYlB;IA+FD,sBAKC;;CACD;0BA1JyB,qBAAqB"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {Object} MinLength
|
|
3
3
|
* @property {Number} minLength
|
|
4
|
-
* @property {String} minLengthMessage
|
|
4
|
+
* @property {String} [minLengthMessage]
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* @typedef {Object} MaxLength
|
|
8
8
|
* @property {Number} maxLength
|
|
9
|
-
* @property {String} maxLengthMessage
|
|
9
|
+
* @property {String} [maxLengthMessage]
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
12
|
* @typedef {Object} Regex
|
|
13
13
|
* @property {String | RegExp} regex
|
|
14
|
-
* @property {String} regexMessage
|
|
14
|
+
* @property {String} [regexMessage]
|
|
15
15
|
*/
|
|
16
16
|
export default class StringValidator extends BaseValidator {
|
|
17
17
|
/**
|
|
@@ -44,15 +44,15 @@ export default class StringValidator extends BaseValidator {
|
|
|
44
44
|
}
|
|
45
45
|
export type MinLength = {
|
|
46
46
|
minLength: number;
|
|
47
|
-
minLengthMessage
|
|
47
|
+
minLengthMessage?: string | undefined;
|
|
48
48
|
};
|
|
49
49
|
export type MaxLength = {
|
|
50
50
|
maxLength: number;
|
|
51
|
-
maxLengthMessage
|
|
51
|
+
maxLengthMessage?: string | undefined;
|
|
52
52
|
};
|
|
53
53
|
export type Regex = {
|
|
54
54
|
regex: string | RegExp;
|
|
55
|
-
regexMessage
|
|
55
|
+
regexMessage?: string | undefined;
|
|
56
56
|
};
|
|
57
57
|
import BaseValidator from './base-validator.js';
|
|
58
58
|
//# sourceMappingURL=string-validator.d.ts.map
|