@ukhomeoffice/cop-react-form-renderer 6.0.0 → 6.0.1-peter

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.
Files changed (50) hide show
  1. package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +2 -2
  2. package/dist/components/CollectionSummary/BannerStrip.js +3 -1
  3. package/dist/components/CollectionSummary/BannerStrip.scss +7 -3
  4. package/dist/components/CollectionSummary/CollectionSummary.js +34 -7
  5. package/dist/components/CollectionSummary/CollectionSummary.scss +1 -1
  6. package/dist/components/CollectionSummary/CollectionSummary.test.js +82 -4
  7. package/dist/components/CollectionSummary/Confirmation.scss +1 -1
  8. package/dist/components/CollectionSummary/RenderListView.js +9 -5
  9. package/dist/components/CollectionSummary/RenderListView.scss +1 -1
  10. package/dist/components/CollectionSummary/RenderListView.test.js +24 -3
  11. package/dist/components/CollectionSummary/SummaryCard.js +18 -45
  12. package/dist/components/CollectionSummary/SummaryCard.scss +4 -147
  13. package/dist/components/CollectionSummary/SummaryCard.test.js +53 -191
  14. package/dist/components/CollectionSummary/SummaryCardDetails.js +117 -0
  15. package/dist/components/CollectionSummary/SummaryCardDetails.scss +158 -0
  16. package/dist/components/CollectionSummary/SummaryCardDetails.test.js +319 -0
  17. package/dist/components/FormPage/FormPage.scss +1 -1
  18. package/dist/components/FormRenderer/FormRenderer.scss +1 -1
  19. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-data.json +4 -0
  20. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-form.json +61 -0
  21. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collection-data-removed.json +4 -0
  22. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collections.json +8 -0
  23. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components-removed.json +3 -0
  24. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components.json +5 -0
  25. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-entire-collection-removed.json +3 -0
  26. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-component-removed.json +10 -0
  27. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-components.json +11 -0
  28. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-for-nested-components.json +96 -0
  29. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections-delete-entire.json +47 -0
  30. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections.json +46 -0
  31. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-components.json +48 -0
  32. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +134 -0
  33. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +113 -0
  34. package/dist/components/FormRenderer/helpers/deleteNodeByPath.js +20 -0
  35. package/dist/components/FormRenderer/helpers/deleteNodeByPath.test.js +56 -0
  36. package/dist/components/FormRenderer/helpers/index.js +3 -1
  37. package/dist/components/FormRenderer/onPageAction.js +8 -2
  38. package/dist/components/FormRenderer/onPageAction.test.js +5 -0
  39. package/dist/components/SummaryList/SummaryList.scss +2 -2
  40. package/dist/components/TaskList/TaskList.scss +1 -1
  41. package/dist/utils/CollectionPage/mergeCollectionPages.js +15 -5
  42. package/dist/utils/CollectionPage/mergeCollectionPages.test.js +48 -1
  43. package/dist/utils/CollectionPage/setCollectionPageData.js +2 -2
  44. package/dist/utils/CollectionPage/setCollectionPageData.test.js +31 -0
  45. package/dist/utils/FormPage/getConditionalText.js +54 -0
  46. package/dist/utils/FormPage/getConditionalText.test.js +162 -0
  47. package/dist/utils/FormPage/index.js +5 -2
  48. package/package.json +4 -4
  49. package/dist/utils/FormPage/getPageTitle.js +0 -32
  50. package/dist/utils/FormPage/getPageTitle.test.js +0 -138
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ var _getConditionalText = _interopRequireDefault(require("./getConditionalText"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ describe('utils.FormPage.getConditionalText', function () {
6
+ var FORM_DATA = {
7
+ testField: 'Alpha',
8
+ testField2: 'yes'
9
+ };
10
+ it('should return null if no options are provided', function () {
11
+ var result = (0, _getConditionalText.default)(null, FORM_DATA);
12
+ expect(result).toEqual(null);
13
+ });
14
+ it('should return the option if it\'s just a string', function () {
15
+ var result = (0, _getConditionalText.default)('abc123', FORM_DATA);
16
+ expect(result).toEqual('abc123');
17
+ });
18
+ it('should return a correctly interpolated string', function () {
19
+ // eslint-disable-next-line no-template-curly-in-string
20
+ var result = (0, _getConditionalText.default)('${testField} string', FORM_DATA);
21
+ expect(result).toEqual("".concat(FORM_DATA.testField, " string"));
22
+ });
23
+ it('should return the option that has it\'s conditions met', function () {
24
+ var OPTIONS = [{
25
+ text: 'Text A',
26
+ show_when: [{
27
+ field: 'testField2',
28
+ op: '=',
29
+ value: 'no'
30
+ }]
31
+ }, {
32
+ text: 'Text B',
33
+ show_when: [{
34
+ field: 'testField2',
35
+ op: '=',
36
+ value: 'yes'
37
+ }]
38
+ }];
39
+ var result = (0, _getConditionalText.default)(OPTIONS, FORM_DATA);
40
+ expect(result).toEqual('Text B');
41
+ });
42
+ it('should return a plain string option if one is encountered in the array', function () {
43
+ var OPTIONS = [{
44
+ text: 'Text A',
45
+ show_when: [{
46
+ field: 'testField2',
47
+ op: '=',
48
+ value: 'notTheValue'
49
+ }]
50
+ }, {
51
+ text: 'Text B',
52
+ show_when: [{
53
+ field: 'testField2',
54
+ op: '=',
55
+ value: 'notTheValue'
56
+ }]
57
+ }, "Default text"];
58
+ var result = (0, _getConditionalText.default)(OPTIONS, FORM_DATA);
59
+ expect(result).toEqual('Default text');
60
+ });
61
+ it('should correctly interpolate a plain string option in the array', function () {
62
+ var OPTIONS = [{
63
+ text: 'Text A',
64
+ show_when: [{
65
+ field: 'testField2',
66
+ op: '=',
67
+ value: 'notTheValue'
68
+ }]
69
+ }, {
70
+ text: 'Text B',
71
+ show_when: [{
72
+ field: 'testField2',
73
+ op: '=',
74
+ value: 'notTheValue'
75
+ }]
76
+ },
77
+ // eslint-disable-next-line no-template-curly-in-string
78
+ "${testField} text"];
79
+ var result = (0, _getConditionalText.default)(OPTIONS, FORM_DATA);
80
+ expect(result).toEqual("".concat(FORM_DATA.testField, " text"));
81
+ });
82
+ it('should correctly interpolate a conditional option', function () {
83
+ var OPTIONS = [{
84
+ text: 'Text A',
85
+ show_when: [{
86
+ field: 'testField2',
87
+ op: '=',
88
+ value: 'no'
89
+ }]
90
+ }, {
91
+ // eslint-disable-next-line no-template-curly-in-string
92
+ text: '${testField} text',
93
+ show_when: [{
94
+ field: 'testField2',
95
+ op: '=',
96
+ value: 'yes'
97
+ }]
98
+ }];
99
+ var result = (0, _getConditionalText.default)(OPTIONS, FORM_DATA);
100
+ expect(result).toEqual("".concat(FORM_DATA.testField, " text"));
101
+ });
102
+ it('should correctly use a conditional option', function () {
103
+ var OPTIONS = [{
104
+ text: 'Text A',
105
+ show_when: [{
106
+ field: 'testField2',
107
+ op: '=',
108
+ value: 'no'
109
+ }]
110
+ }, {
111
+ // eslint-disable-next-line no-template-curly-in-string
112
+ text: '${testField} text',
113
+ show_when: [{
114
+ field: 'testField2',
115
+ op: '=',
116
+ value: 'yes'
117
+ }]
118
+ }];
119
+ var result = (0, _getConditionalText.default)(OPTIONS, FORM_DATA);
120
+ expect(result).toEqual("".concat(FORM_DATA.testField, " text"));
121
+ });
122
+ it('should correctly use a different key to find the text if one is provided', function () {
123
+ var OPTIONS = [{
124
+ customKey: 'Text A',
125
+ show_when: [{
126
+ field: 'testField2',
127
+ op: '=',
128
+ value: 'no'
129
+ }]
130
+ }, {
131
+ // eslint-disable-next-line no-template-curly-in-string
132
+ customKey: '${testField} text',
133
+ show_when: [{
134
+ field: 'testField2',
135
+ op: '=',
136
+ value: 'yes'
137
+ }]
138
+ }];
139
+ var result = (0, _getConditionalText.default)(OPTIONS, FORM_DATA, 'customKey');
140
+ expect(result).toEqual("".concat(FORM_DATA.testField, " text"));
141
+ });
142
+ it('should return null for a conditional option if formData is empty', function () {
143
+ var OPTIONS = [{
144
+ text: 'Text A',
145
+ show_when: [{
146
+ field: 'testField2',
147
+ op: '=',
148
+ value: 'no'
149
+ }]
150
+ }, {
151
+ // eslint-disable-next-line no-template-curly-in-string
152
+ text: '${testField} text',
153
+ show_when: [{
154
+ field: 'testField2',
155
+ op: '=',
156
+ value: 'yes'
157
+ }]
158
+ }];
159
+ var result = (0, _getConditionalText.default)(OPTIONS, {});
160
+ expect(result).toEqual(null);
161
+ });
162
+ });
@@ -5,17 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _applyConditionalProperties = _interopRequireDefault(require("./applyConditionalProperties"));
8
+ var _getConditionalText = _interopRequireDefault(require("./getConditionalText"));
8
9
  var _getFormPage = _interopRequireDefault(require("./getFormPage"));
9
10
  var _getFormPages = _interopRequireDefault(require("./getFormPages"));
10
- var _getPageTitle = _interopRequireDefault(require("./getPageTitle"));
11
11
  var _showFormPage = _interopRequireDefault(require("./showFormPage"));
12
12
  var _showFormPageCYA = _interopRequireDefault(require("./showFormPageCYA"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  var FormPage = {
15
15
  applyConditionalProperties: _applyConditionalProperties.default,
16
+ getConditionalText: _getConditionalText.default,
16
17
  get: _getFormPage.default,
17
18
  getAll: _getFormPages.default,
18
- getTitle: _getPageTitle.default,
19
+ getTitle: function getTitle(options, formData) {
20
+ return (0, _getConditionalText.default)(options, formData, 'title');
21
+ },
19
22
  show: _showFormPage.default,
20
23
  showCYA: _showFormPageCYA.default
21
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "6.0.0",
3
+ "version": "6.0.1-peter",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,11 +16,10 @@
16
16
  "post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
17
17
  },
18
18
  "dependencies": {
19
- "@ukhomeoffice/cop-react-components": "^4.0.0",
19
+ "@ukhomeoffice/cop-react-components": "^3.19.1",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
- "govuk-frontend": "^5.0.0",
23
- "sass": "^1.69.5",
22
+ "govuk-frontend": "^4.3.1",
24
23
  "web-vitals": "^1.0.1"
25
24
  },
26
25
  "devDependencies": {
@@ -49,6 +48,7 @@
49
48
  "eslint-config-airbnb": "^19.0.4",
50
49
  "eslint-config-prettier": "^8.6.0",
51
50
  "html-react-parser": "^0.10.5",
51
+ "node-sass": "^6.0.1",
52
52
  "prop-types": "^15.8.1",
53
53
  "react": "^16.13.1",
54
54
  "react-dom": "^16.13.1",
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _copReactComponents = require("@ukhomeoffice/cop-react-components");
8
- var _meetsAllConditions = _interopRequireDefault(require("../Condition/meetsAllConditions"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- // Global imports.
11
-
12
- // Local imports.
13
-
14
- var getPageTitle = function getPageTitle(title, formData) {
15
- if (typeof title === 'string') {
16
- return _copReactComponents.Utils.interpolateString(title, formData);
17
- }
18
- if (!Array.isArray(title) || Object.keys(formData).length === 0) {
19
- return null;
20
- }
21
- var shownOption = title.find(function (option) {
22
- if (typeof option === 'string') {
23
- // This is intended to allow a plain string 'fallback' option in the array.
24
- // As such, it should be the last option in the array as any options after
25
- // it will not be considered.
26
- return true;
27
- }
28
- return (0, _meetsAllConditions.default)(option.show_when, formData);
29
- });
30
- return typeof shownOption === 'string' ? _copReactComponents.Utils.interpolateString(shownOption, formData) : _copReactComponents.Utils.interpolateString(shownOption.title, formData);
31
- };
32
- var _default = exports.default = getPageTitle;
@@ -1,138 +0,0 @@
1
- "use strict";
2
-
3
- var _getPageTitle = _interopRequireDefault(require("./getPageTitle"));
4
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
- describe('utils.FormPage.getPageTitle', function () {
6
- var FORM_DATA = {
7
- testField: 'Alpha',
8
- testField2: 'yes'
9
- };
10
- it('should return null if title is not defined', function () {
11
- var result = (0, _getPageTitle.default)(null, FORM_DATA);
12
- expect(result).toEqual(null);
13
- });
14
- it('should return the defined page title if it\'s just a string', function () {
15
- var PAGE = {
16
- title: 'Page title'
17
- };
18
- var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
19
- expect(result).toEqual('Page title');
20
- });
21
- it('should return a correctly interpolated title', function () {
22
- // eslint-disable-next-line no-template-curly-in-string
23
- var PAGE = {
24
- title: '${testField} title'
25
- };
26
- var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
27
- expect(result).toEqual("".concat(FORM_DATA.testField, " title"));
28
- });
29
- it('should return the title that has it\'s conditions met', function () {
30
- var PAGE = {
31
- title: [{
32
- title: 'First title',
33
- show_when: [{
34
- field: 'testField2',
35
- op: '=',
36
- value: 'no'
37
- }]
38
- }, {
39
- title: 'Second title',
40
- show_when: [{
41
- field: 'testField2',
42
- op: '=',
43
- value: 'yes'
44
- }]
45
- }]
46
- };
47
- var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
48
- expect(result).toEqual('Second title');
49
- });
50
- it('should return a plain string title if one is encountered in the array', function () {
51
- var PAGE = {
52
- title: [{
53
- title: 'First title',
54
- show_when: [{
55
- field: 'testField2',
56
- op: '=',
57
- value: 'notTheValue'
58
- }]
59
- }, {
60
- title: 'Second title',
61
- show_when: [{
62
- field: 'testField2',
63
- op: '=',
64
- value: 'notTheValue'
65
- }]
66
- }, "Default title"]
67
- };
68
- var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
69
- expect(result).toEqual('Default title');
70
- });
71
- it('should correctly interpolate a plain string option in the title array', function () {
72
- var PAGE = {
73
- title: [{
74
- title: 'First title',
75
- show_when: [{
76
- field: 'testField2',
77
- op: '=',
78
- value: 'notTheValue'
79
- }]
80
- }, {
81
- title: 'Second title',
82
- show_when: [{
83
- field: 'testField2',
84
- op: '=',
85
- value: 'notTheValue'
86
- }]
87
- },
88
- // eslint-disable-next-line no-template-curly-in-string
89
- "${testField} title"]
90
- };
91
- var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
92
- expect(result).toEqual("".concat(FORM_DATA.testField, " title"));
93
- });
94
- it('should correctly interpolate a conditional title', function () {
95
- var PAGE = {
96
- title: [{
97
- title: 'First title',
98
- show_when: [{
99
- field: 'testField2',
100
- op: '=',
101
- value: 'no'
102
- }]
103
- }, {
104
- // eslint-disable-next-line no-template-curly-in-string
105
- title: '${testField} title',
106
- show_when: [{
107
- field: 'testField2',
108
- op: '=',
109
- value: 'yes'
110
- }]
111
- }]
112
- };
113
- var result = (0, _getPageTitle.default)(PAGE.title, FORM_DATA);
114
- expect(result).toEqual("".concat(FORM_DATA.testField, " title"));
115
- });
116
- it('should return null for a conditional title if formData is empty', function () {
117
- var PAGE = {
118
- title: [{
119
- title: 'First title',
120
- show_when: [{
121
- field: 'testField2',
122
- op: '=',
123
- value: 'no'
124
- }]
125
- }, {
126
- // eslint-disable-next-line no-template-curly-in-string
127
- title: '${testField} title',
128
- show_when: [{
129
- field: 'testField2',
130
- op: '=',
131
- value: 'yes'
132
- }]
133
- }]
134
- };
135
- var result = (0, _getPageTitle.default)(PAGE.title, {});
136
- expect(result).toEqual(null);
137
- });
138
- });