@ukhomeoffice/cop-react-form-renderer 4.64.0 → 4.65.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.
@@ -500,8 +500,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
500
500
 
501
501
  if (currentTask.state === _models.TaskStates.TYPES.COMPLETE) {
502
502
  if (hubDetails !== null && hubDetails !== void 0 && hubDetails.noTaskCYAs) {
503
+ // If the task is complete and there are no CYA's then show user first page
503
504
  var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
504
- onPageChange(currentPage || currentTask.pages[0]);
505
+ onPageChange(currentTask.pages[0] || currentPage);
505
506
  } else if (currentTask.customCYA) {
506
507
  onPageChange(currentTask.customCYA);
507
508
  } else {
@@ -990,7 +990,7 @@ describe('components', function () {
990
990
  }
991
991
  }, _callee28);
992
992
  })));
993
- it('should go to the last page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee30() {
993
+ it('should go to the first page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee30() {
994
994
  var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage;
995
995
  return regeneratorRuntime.wrap(function _callee30$(_context30) {
996
996
  while (1) {
@@ -1066,10 +1066,10 @@ describe('components', function () {
1066
1066
  _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {}); // Launch same task again
1067
1067
 
1068
1068
 
1069
- _react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[0].childNodes[0], {}); // Should be on the second page
1069
+ _react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[1].childNodes[0].childNodes[0], {}); // Should be on the first page
1070
1070
 
1071
1071
 
1072
- expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Mode');
1072
+ expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Date');
1073
1073
 
1074
1074
  case 19:
1075
1075
  case "end":
@@ -14,9 +14,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
14
14
  // Global imports.
15
15
  // Local imports.
16
16
  var getFirstOf = function getFirstOf(config, data) {
17
- var fieldValue;
18
-
19
17
  if (config !== null && config !== void 0 && config.fields) {
18
+ var fieldValue;
20
19
  config.fields.find(function (field) {
21
20
  var fieldPath = _copReactComponents.Utils.interpolateString(field, data);
22
21
 
@@ -29,7 +28,7 @@ var getFirstOf = function getFirstOf(config, data) {
29
28
 
30
29
  return false;
31
30
  });
32
- return fieldValue || '';
31
+ return fieldValue || (config.fallback ? _copReactComponents.Utils.interpolateString(config.fallback, data) : '');
33
32
  }
34
33
 
35
34
  return (config === null || config === void 0 ? void 0 : config.value) || null;
@@ -29,6 +29,15 @@ describe('Utils.Operate.addToFormData', function () {
29
29
  var result = (0, _getFirstOf.default)(CONFIG, DATA);
30
30
  expect(result).toEqual(CONFIG.value);
31
31
  });
32
+ it('Should return the fallback if the requested fields are not found', function () {
33
+ var CONFIG = {
34
+ value: '2',
35
+ fields: ['nonExistent'],
36
+ fallback: "Test ${name}"
37
+ };
38
+ var result = (0, _getFirstOf.default)(CONFIG, DATA);
39
+ expect(result).toEqual("Test ".concat(DATA.name));
40
+ });
32
41
  it('Should return the value of the passportNumber field given in config', function () {
33
42
  var CONFIG = {
34
43
  fields: ['passportNumber', 'anotherMadeUpId', 'otherIdDoc']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.64.0",
3
+ "version": "4.65.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,7 +16,7 @@
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": "^2.11.0",
19
+ "@ukhomeoffice/cop-react-components": "^2.11.2",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^4.3.1",