@ukhomeoffice/cop-react-form-renderer 3.15.0 → 3.16.1-alpha
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/dist/components/FormPage/FormPage.js +3 -1
- package/dist/components/FormPage/FormPage.test.js +59 -0
- package/dist/components/TaskList/Task.js +1 -1
- package/dist/components/TaskList/TaskList.js +1 -1
- package/dist/components/TaskList/TaskState.js +7 -7
- package/dist/components/TaskList/TaskState.test.js +15 -10
- package/package.json +1 -1
|
@@ -104,7 +104,9 @@ var FormPage = function FormPage(_ref) {
|
|
|
104
104
|
formData: _objectSpread(_objectSpread({}, page.formData), patch)
|
|
105
105
|
});
|
|
106
106
|
}), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
107
|
-
actions: page.actions
|
|
107
|
+
actions: page.actions.filter(function (action) {
|
|
108
|
+
return _utils.default.Component.show(action, page.formData);
|
|
109
|
+
}),
|
|
108
110
|
onAction: function onAction(action) {
|
|
109
111
|
return _onAction(action, patch);
|
|
110
112
|
}
|
|
@@ -92,6 +92,44 @@ describe('components.FormPage', function () {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
|
+
var PAGE_WITH_CONDITIONAL_BUTTONS = {
|
|
96
|
+
id: 'pageId',
|
|
97
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
98
|
+
title: '${title}',
|
|
99
|
+
components: [TEXT_WITH_EXPRESSION, AUTO_WITH_EXPRESSION],
|
|
100
|
+
actions: [{
|
|
101
|
+
type: 'submit',
|
|
102
|
+
validate: true,
|
|
103
|
+
label: 'Button 1',
|
|
104
|
+
show_when: [{
|
|
105
|
+
field: 'currentUser.givenName',
|
|
106
|
+
op: '!=',
|
|
107
|
+
value: 'Doe'
|
|
108
|
+
}]
|
|
109
|
+
}, {
|
|
110
|
+
type: 'submit',
|
|
111
|
+
validate: false,
|
|
112
|
+
label: 'Button 2',
|
|
113
|
+
show_when: [{
|
|
114
|
+
field: 'currentUser.givenName',
|
|
115
|
+
op: '=',
|
|
116
|
+
value: 'Doe'
|
|
117
|
+
}]
|
|
118
|
+
}],
|
|
119
|
+
formData: {
|
|
120
|
+
title: 'Order Form',
|
|
121
|
+
text1: "Text1 ".concat(VALUE),
|
|
122
|
+
text2: "Text2 ".concat(VALUE),
|
|
123
|
+
wrapper: {
|
|
124
|
+
email: 'test@example.email',
|
|
125
|
+
nextAction: 'Payment',
|
|
126
|
+
prevAction: 'User Details'
|
|
127
|
+
},
|
|
128
|
+
currentUser: {
|
|
129
|
+
givenName: 'Doe'
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
95
133
|
var ON_ACTION_CALLS = [];
|
|
96
134
|
|
|
97
135
|
var checkInputField = function checkInputField(formGroup, fieldId, lbl, hnt, val) {
|
|
@@ -305,5 +343,26 @@ describe('components.FormPage', function () {
|
|
|
305
343
|
}
|
|
306
344
|
}, _callee4);
|
|
307
345
|
})));
|
|
346
|
+
it('should render only the conditionally shown button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
347
|
+
var _renderWithValidation5, container, page;
|
|
348
|
+
|
|
349
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
350
|
+
while (1) {
|
|
351
|
+
switch (_context5.prev = _context5.next) {
|
|
352
|
+
case 0:
|
|
353
|
+
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormPage.default, {
|
|
354
|
+
page: PAGE_WITH_CONDITIONAL_BUTTONS,
|
|
355
|
+
onAction: ON_ACTION
|
|
356
|
+
})), container = _renderWithValidation5.container;
|
|
357
|
+
page = container.childNodes[0];
|
|
358
|
+
checkFormButtonGroup(page.childNodes[3], ['Button 2']); // Just the second button shown
|
|
359
|
+
|
|
360
|
+
case 3:
|
|
361
|
+
case "end":
|
|
362
|
+
return _context5.stop();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}, _callee5);
|
|
366
|
+
})));
|
|
308
367
|
});
|
|
309
368
|
});
|
|
@@ -81,7 +81,7 @@ Task.propTypes = {
|
|
|
81
81
|
task: _propTypes.default.shape({
|
|
82
82
|
name: _propTypes.default.string.isRequired,
|
|
83
83
|
pages: _propTypes.default.array.isRequired,
|
|
84
|
-
state: _propTypes.default.string
|
|
84
|
+
state: _propTypes.default.string
|
|
85
85
|
}).isRequired,
|
|
86
86
|
onClick: _propTypes.default.func.isRequired
|
|
87
87
|
};
|
|
@@ -100,7 +100,7 @@ TaskList.propTypes = {
|
|
|
100
100
|
tasks: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
101
101
|
name: _propTypes.default.string.isRequired,
|
|
102
102
|
pages: _propTypes.default.array.isRequired,
|
|
103
|
-
state: _propTypes.default.string
|
|
103
|
+
state: _propTypes.default.string
|
|
104
104
|
})).isRequired
|
|
105
105
|
})).isRequired,
|
|
106
106
|
classBlock: _propTypes.default.string,
|
|
@@ -25,18 +25,18 @@ var TaskState = function TaskState(_ref) {
|
|
|
25
25
|
|
|
26
26
|
var classes = _copReactComponents.Utils.classBuilder(DEFAULT_CLASS, undefined, undefined);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
28
|
+
var details = _models.TaskStates.DETAILS[state] || _models.TaskStates.DETAILS.cannotStartYet;
|
|
32
29
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Tag, {
|
|
33
|
-
classModifiers:
|
|
30
|
+
classModifiers: details.colour,
|
|
34
31
|
className: classes('tag')
|
|
35
|
-
},
|
|
32
|
+
}, details.label);
|
|
36
33
|
};
|
|
37
34
|
|
|
38
35
|
TaskState.propTypes = {
|
|
39
|
-
state: _propTypes.default.string
|
|
36
|
+
state: _propTypes.default.string
|
|
37
|
+
};
|
|
38
|
+
TaskState.defaultProps = {
|
|
39
|
+
state: _models.TaskStates.TYPES.CANNOT_START_YET
|
|
40
40
|
};
|
|
41
41
|
var _default = TaskState;
|
|
42
42
|
exports.default = _default;
|
|
@@ -14,6 +14,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
14
|
// Local imports
|
|
15
15
|
describe('components', function () {
|
|
16
16
|
describe('TaskList.TaskState', function () {
|
|
17
|
+
var checkIsCannotStartYet = function checkIsCannotStartYet(container) {
|
|
18
|
+
expect(container.childNodes.length).toEqual(1);
|
|
19
|
+
expect(container.childNodes[0].classList).toContain('hods-tag');
|
|
20
|
+
expect(container.childNodes[0].classList).toContain("hods-tag--".concat(_models.TaskStates.DETAILS.cannotStartYet.colour));
|
|
21
|
+
expect(container.childNodes[0].textContent).toEqual(_models.TaskStates.DETAILS.cannotStartYet.label);
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
|
|
17
25
|
it('should render a complete state icon', function () {
|
|
18
26
|
var STATE = _models.TaskStates.TYPES.COMPLETE;
|
|
19
27
|
|
|
@@ -60,12 +68,9 @@ describe('components', function () {
|
|
|
60
68
|
})),
|
|
61
69
|
container = _render4.container;
|
|
62
70
|
|
|
63
|
-
expect(container
|
|
64
|
-
expect(container.childNodes[0].classList).toContain('hods-tag');
|
|
65
|
-
expect(container.childNodes[0].classList).toContain("hods-tag--".concat(_models.TaskStates.DETAILS.cannotStartYet.colour));
|
|
66
|
-
expect(container.childNodes[0].textContent).toEqual(_models.TaskStates.DETAILS.cannotStartYet.label);
|
|
71
|
+
expect(checkIsCannotStartYet(container)).toBeTruthy();
|
|
67
72
|
});
|
|
68
|
-
it('should
|
|
73
|
+
it('should render the "Cannot start yet" state if given an unknown value', function () {
|
|
69
74
|
var STATE = 'spellingError';
|
|
70
75
|
|
|
71
76
|
var _render5 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskState.default, {
|
|
@@ -73,9 +78,9 @@ describe('components', function () {
|
|
|
73
78
|
})),
|
|
74
79
|
container = _render5.container;
|
|
75
80
|
|
|
76
|
-
expect(container
|
|
81
|
+
expect(checkIsCannotStartYet(container)).toBeTruthy();
|
|
77
82
|
});
|
|
78
|
-
it('should
|
|
83
|
+
it('should render the "Cannot start yet" state if given null', function () {
|
|
79
84
|
var STATE = null;
|
|
80
85
|
|
|
81
86
|
var _render6 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskState.default, {
|
|
@@ -83,9 +88,9 @@ describe('components', function () {
|
|
|
83
88
|
})),
|
|
84
89
|
container = _render6.container;
|
|
85
90
|
|
|
86
|
-
expect(container
|
|
91
|
+
expect(checkIsCannotStartYet(container)).toBeTruthy();
|
|
87
92
|
});
|
|
88
|
-
it('should
|
|
93
|
+
it('should render the "Cannot start yet" state if given undefined', function () {
|
|
89
94
|
var STATE = undefined;
|
|
90
95
|
|
|
91
96
|
var _render7 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_TaskState.default, {
|
|
@@ -93,7 +98,7 @@ describe('components', function () {
|
|
|
93
98
|
})),
|
|
94
99
|
container = _render7.container;
|
|
95
100
|
|
|
96
|
-
expect(container
|
|
101
|
+
expect(checkIsCannotStartYet(container)).toBeTruthy();
|
|
97
102
|
});
|
|
98
103
|
});
|
|
99
104
|
});
|