@ukhomeoffice/cop-react-form-renderer 5.77.1 → 5.77.3

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.
@@ -167,7 +167,9 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
167
167
  rows = rows.concat(headingRow);
168
168
  }
169
169
  var container = getContainerForPage(childPage, item, labelCount, fullPath);
170
- var containerRows = (0, _getCYARowsForContainer.default)(childPage, container, _objectSpread(_objectSpread({}, childPage.formData), item), changeAction, fnOverride);
170
+ var containerRows = (0, _getCYARowsForContainer.default)(_objectSpread(_objectSpread({}, childPage), {}, {
171
+ formData: _objectSpread(_objectSpread({}, childPage.formData), item)
172
+ }), container, _objectSpread(_objectSpread({}, childPage.formData), item), changeAction, fnOverride);
171
173
  rows = rows.concat(containerRows);
172
174
  }
173
175
  }
@@ -681,4 +681,80 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
681
681
  key: 'Test text'
682
682
  });
683
683
  });
684
+ it('should create rows for the Collection component correctly', function () {
685
+ var FORM_DATA = {
686
+ collection: [{
687
+ id: '01',
688
+ testCollection: [{
689
+ testText: 'collection value'
690
+ }],
691
+ otherComp: 'one'
692
+ }]
693
+ };
694
+ var COLLECTION_COMP = {
695
+ id: 'testCollection',
696
+ fieldId: 'testCollection',
697
+ label: 'Test collection',
698
+ type: 'collection',
699
+ item: [{
700
+ id: 'testText',
701
+ fieldId: 'testText',
702
+ type: 'text',
703
+ label: 'Some nice text'
704
+ }],
705
+ show_when: [{
706
+ field: 'otherComp',
707
+ op: 'eq',
708
+ value: 'one'
709
+ }]
710
+ };
711
+ var MASTER_PAGE_WITH_COLLECTION = {
712
+ id: 'page1',
713
+ collection: {
714
+ name: 'collection',
715
+ labels: {
716
+ // eslint-disable-next-line no-template-curly-in-string
717
+ item: 'Collection entry ${index}'
718
+ },
719
+ actions: [{
720
+ type: 'change'
721
+ }, {
722
+ type: 'remove',
723
+ label: 'custom remove label'
724
+ }, {
725
+ type: 'change',
726
+ label: 'custom change label',
727
+ page: 'confirmDelete'
728
+ }]
729
+ },
730
+ childPages: [{
731
+ id: 'page1',
732
+ collection: {
733
+ name: 'collection'
734
+ },
735
+ components: [COLLECTION_COMP]
736
+ }],
737
+ formData: FORM_DATA
738
+ };
739
+ var ROWS = (0, _getCYARowsForCollectionPage.default)(MASTER_PAGE_WITH_COLLECTION, null, null, FORM_DATA);
740
+ expect(ROWS.length).toEqual(7); // Title row + component row for each item
741
+ expect(ROWS[0]).toMatchObject({
742
+ type: 'heading',
743
+ key: 'Collection'
744
+ });
745
+ expect(ROWS[1]).toMatchObject({
746
+ type: 'heading',
747
+ key: 'Collection entry 1'
748
+ });
749
+ expect(ROWS[2].action.label).toEqual('Change');
750
+ expect(ROWS[3].action.label).toEqual('custom remove label');
751
+ expect(ROWS[4].action.label).toEqual('custom change label');
752
+ expect(ROWS[5]).toMatchObject({
753
+ key: 'Item 1'
754
+ });
755
+ expect(ROWS[6]).toMatchObject({
756
+ value: 'collection value',
757
+ key: 'Some nice text'
758
+ });
759
+ });
684
760
  });
@@ -39,6 +39,11 @@ var validateTime = function validateTime(time) {
39
39
  var intMinute = parseInt(minute, 10);
40
40
  var badProps = [];
41
41
  var messages = [];
42
+ var numericRegex = /^\d{0,2}:\d{0,2}$/;
43
+ if (!numericRegex.test(time)) {
44
+ badProps.push('invalid');
45
+ messages.push('Enter a valid time');
46
+ }
42
47
  if (hour.length === 0) {
43
48
  badProps.push('hour');
44
49
  messages.push('Time must include a hour');
@@ -61,6 +66,9 @@ var validateTime = function validateTime(time) {
61
66
  if (badProps.includes('minute')) {
62
67
  propsInError.minute = true;
63
68
  }
69
+ if (badProps.includes('invalid')) {
70
+ propsInError.invalid = true;
71
+ }
64
72
  return {
65
73
  message: badProps.length > 1 ? 'Enter a valid time' : messages[0],
66
74
  propsInError: propsInError
@@ -64,6 +64,52 @@ describe('utils', function () {
64
64
  }
65
65
  });
66
66
  });
67
+ test('should return an error if the time string contains non-numeric characters', function () {
68
+ var output = (0, _validateTime.default)('14:3A');
69
+ expect(output).toEqual({
70
+ message: 'Enter a valid time',
71
+ propsInError: {
72
+ invalid: true,
73
+ minute: true
74
+ }
75
+ });
76
+ });
77
+ test('should return an error if the time string contains more than two digits in hour', function () {
78
+ var output = (0, _validateTime.default)('144:30');
79
+ expect(output).toEqual({
80
+ message: 'Enter a valid time',
81
+ propsInError: {
82
+ invalid: true,
83
+ hour: true
84
+ }
85
+ });
86
+ });
87
+ test('should return an error if the time string contains more than two digits in minute', function () {
88
+ var output = (0, _validateTime.default)('14:309');
89
+ expect(output).toEqual({
90
+ message: 'Enter a valid time',
91
+ propsInError: {
92
+ invalid: true,
93
+ minute: true
94
+ }
95
+ });
96
+ });
97
+ test('should return an error if there is an additional colon in the time string', function () {
98
+ var output = (0, _validateTime.default)('14:30:');
99
+ expect(output).toEqual({
100
+ message: 'Enter a valid time',
101
+ propsInError: {
102
+ invalid: true
103
+ }
104
+ });
105
+ });
106
+ test('should return no error if there is a single digit for both hour and minute', function () {
107
+ var output = (0, _validateTime.default)('1:1');
108
+ expect(output).toEqual({
109
+ message: undefined,
110
+ propsInError: undefined
111
+ });
112
+ });
67
113
  });
68
114
  });
69
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.77.1",
3
+ "version": "5.77.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",