@ukhomeoffice/cop-react-form-renderer 5.27.0 → 5.27.1

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.
@@ -193,7 +193,9 @@ var Collection = function Collection(_ref) {
193
193
  onChange: onCollectionChange,
194
194
  onTopLevelChange: onTopLevelChange,
195
195
  wrap: wrap
196
- }), removeStyle === 'end' && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, null, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
196
+ }), removeStyle === 'end' && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, {
197
+ className: "govuk-!-margin-top-1"
198
+ }, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
197
199
  onClick: function onClick() {
198
200
  return onRemoveItem(item);
199
201
  },
@@ -33,6 +33,27 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
33
33
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global imports
34
34
  // Local imports
35
35
  // JSON
36
+ var setDate = function setDate(element, date) {
37
+ var items = element.children;
38
+ _react.fireEvent.change(items[0].childNodes[0].childNodes[1], {
39
+ target: {
40
+ name: 'date-day',
41
+ value: date[0]
42
+ }
43
+ });
44
+ _react.fireEvent.change(items[1].childNodes[0].childNodes[1], {
45
+ target: {
46
+ name: 'date-month',
47
+ value: date[1]
48
+ }
49
+ });
50
+ _react.fireEvent.change(items[2].childNodes[0].childNodes[1], {
51
+ target: {
52
+ name: 'date-year',
53
+ value: date[2]
54
+ }
55
+ });
56
+ };
36
57
  describe('components', function () {
37
58
  describe('FormRenderer', function () {
38
59
  var mockAxios = new _axiosMockAdapter.default(_axios.default);
@@ -414,7 +435,7 @@ describe('components', function () {
414
435
  }
415
436
  }, _callee14);
416
437
  })));
417
- it('should render a tasklist', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
438
+ it('should render a task list', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
418
439
  var taskList;
419
440
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
420
441
  while (1) switch (_context16.prev = _context16.next) {
@@ -466,7 +487,7 @@ describe('components', function () {
466
487
  }
467
488
  }, _callee18);
468
489
  })));
469
- it('should load tasklist with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
490
+ it('should load task list with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
470
491
  var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, TASK_LIST_WITH_NOTES, taskList;
471
492
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
472
493
  while (1) switch (_context20.prev = _context20.next) {
@@ -514,7 +535,7 @@ describe('components', function () {
514
535
  }
515
536
  }, _callee20);
516
537
  })));
517
- it('should not load tasklist with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
538
+ it('should not load task list with notes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
518
539
  var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, TASK_LIST_WITH_NOTES, taskList;
519
540
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
520
541
  while (1) switch (_context22.prev = _context22.next) {
@@ -567,7 +588,7 @@ describe('components', function () {
567
588
  }, _callee22);
568
589
  })));
569
590
  it('should handle navigating between task list pages', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
570
- var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, taskList, firstTaskStatus, secondTaskStatus, firstTask, newPage, continueButton, seaButton, cyaPageChange, modeChangeLink, changePage, airButton, cyaPage, finalSubmit;
591
+ var ON_SUBMIT_CALLS, ON_SUBMIT, HOOKS, taskList, firstTaskStatus, secondTaskStatus, firstTask, newPage, fieldset, continueButton, seaButton, cyaPageChange, modeChangeLink, changePage, airButton, cyaPage, finalSubmit;
571
592
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
572
593
  while (1) switch (_context24.prev = _context24.next) {
573
594
  case 0:
@@ -608,24 +629,8 @@ describe('components', function () {
608
629
  // Fill first page and navigate
609
630
  newPage = container.childNodes[0].childNodes[0];
610
631
  expect(newPage.childNodes[0].textContent).toEqual('Event Date');
611
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[1], {
612
- target: {
613
- name: 'date-day',
614
- value: '7'
615
- }
616
- });
617
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[1].childNodes[1], {
618
- target: {
619
- name: 'date-month',
620
- value: '7'
621
- }
622
- });
623
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[2].childNodes[1], {
624
- target: {
625
- name: 'date-year',
626
- value: '2022'
627
- }
628
- });
632
+ fieldset = newPage.childNodes[1].childNodes[0]; // child nodes of fieldset are legend and date
633
+ setDate(fieldset.children[1], ['7', '7', '2022']);
629
634
  continueButton = newPage.childNodes[2].childNodes[0];
630
635
  _react.fireEvent.click(continueButton, {});
631
636
 
@@ -676,14 +681,14 @@ describe('components', function () {
676
681
  expect(finalSubmit.date).toEqual('7-7-2022');
677
682
  expect(finalSubmit.mode).toEqual('air');
678
683
  expect(finalSubmit.formStatus.tasks['Date, location and mode details'].complete).toEqual(true);
679
- case 54:
684
+ case 53:
680
685
  case "end":
681
686
  return _context24.stop();
682
687
  }
683
688
  }, _callee24);
684
689
  })));
685
690
  it('should go straight to CYA page if a complete task is selected', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
686
- var ON_SUBMIT, HOOKS, taskList, newPage;
691
+ var ON_SUBMIT, HOOKS, taskList, newPage, fieldset;
687
692
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
688
693
  while (1) switch (_context26.prev = _context26.next) {
689
694
  case 0:
@@ -713,24 +718,10 @@ describe('components', function () {
713
718
 
714
719
  // Fill first page and navigate
715
720
  newPage = container.childNodes[0].childNodes[0];
716
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[1], {
717
- target: {
718
- name: 'date-day',
719
- value: '7'
720
- }
721
- });
722
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[1].childNodes[1], {
723
- target: {
724
- name: 'date-month',
725
- value: '7'
726
- }
727
- });
728
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[2].childNodes[1], {
729
- target: {
730
- name: 'date-year',
731
- value: '2022'
732
- }
733
- });
721
+ fieldset = newPage.childNodes[1].childNodes[0];
722
+ setDate(fieldset.children[1], ['7', '7', '2022']);
723
+ // child nodes of fieldset are legend and date
724
+
734
725
  _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
735
726
 
736
727
  // Fill second page and navigate
@@ -746,7 +737,7 @@ describe('components', function () {
746
737
 
747
738
  // Should be at CYA page
748
739
  expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Check your answers');
749
- case 17:
740
+ case 16:
750
741
  case "end":
751
742
  return _context26.stop();
752
743
  }
@@ -803,7 +794,7 @@ describe('components', function () {
803
794
  }, _callee28);
804
795
  })));
805
796
  it('should go to the first page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
806
- var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage;
797
+ var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage, fieldset;
807
798
  return _regeneratorRuntime().wrap(function _callee30$(_context30) {
808
799
  while (1) switch (_context30.prev = _context30.next) {
809
800
  case 0:
@@ -839,24 +830,8 @@ describe('components', function () {
839
830
 
840
831
  // Fill first page and navigate
841
832
  newPage = container.childNodes[0].childNodes[0];
842
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[0].childNodes[1], {
843
- target: {
844
- name: 'date-day',
845
- value: '7'
846
- }
847
- });
848
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[1].childNodes[1], {
849
- target: {
850
- name: 'date-month',
851
- value: '7'
852
- }
853
- });
854
- _react.fireEvent.change(newPage.childNodes[1].childNodes[0].childNodes[2].childNodes[2].childNodes[1], {
855
- target: {
856
- name: 'date-year',
857
- value: '2022'
858
- }
859
- });
833
+ fieldset = newPage.childNodes[1].childNodes[0];
834
+ setDate(fieldset.children[1], ['7', '7', '2022']);
860
835
  _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {});
861
836
 
862
837
  // Fill second page
@@ -870,7 +845,7 @@ describe('components', function () {
870
845
 
871
846
  // Should be on the first page
872
847
  expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Date');
873
- case 19:
848
+ case 18:
874
849
  case "end":
875
850
  return _context30.stop();
876
851
  }
@@ -28,53 +28,53 @@ describe('utils.Component.get', function () {
28
28
  onChange: ON_CHANGE,
29
29
  'data-testid': ID
30
30
  };
31
+ var checkDateField = function checkDateField(node, option) {
32
+ expect(node.tagName).toEqual('DIV');
33
+ expect(node.classList).toContain('govuk-date-input__item');
34
+ var group = node.childNodes[0]; // form group
35
+ var _group$childNodes = _slicedToArray(group.childNodes, 2),
36
+ label = _group$childNodes[0],
37
+ input = _group$childNodes[1];
38
+ expect(label.tagName).toEqual('LABEL');
39
+ expect(label.classList).toContain('govuk-label');
40
+ expect(label.textContent).toEqual(option.label);
41
+ expect(input.tagName).toEqual('INPUT');
42
+ expect(input.id).toEqual(option.id);
43
+ return input;
44
+ };
31
45
  var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
32
46
  container = _render.container;
33
47
  var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
34
48
  _getAllByTestId2 = _slicedToArray(_getAllByTestId, 2),
35
49
  formGroup = _getAllByTestId2[0],
36
- dateinput = _getAllByTestId2[1];
50
+ dateInput = _getAllByTestId2[1];
37
51
  expect(formGroup.tagName).toEqual('DIV');
38
52
  expect(formGroup.classList).toContain('govuk-form-group');
39
53
  var label = formGroup.childNodes[0];
40
54
  expect(label.innerHTML).toContain(LABEL);
41
55
  expect(label.getAttribute('for')).toEqual(ID);
42
- expect(dateinput.tagName).toEqual('DIV');
43
- expect(dateinput.classList).toContain('govuk-date-input');
44
- expect(dateinput.id).toEqual(ID);
45
- var dayitem = dateinput.childNodes[0];
46
- expect(dayitem.tagName).toEqual('DIV');
47
- expect(dayitem.classList).toContain('govuk-date-input__item');
48
- var daylabel = dayitem.childNodes[0];
49
- expect(daylabel.tagName).toEqual('LABEL');
50
- expect(daylabel.classList).toContain('govuk-label');
51
- expect(daylabel.textContent).toEqual('Day');
52
- var dayinput = dayitem.childNodes[1];
53
- expect(dayinput.tagName).toEqual('INPUT');
54
- expect(dayinput.id).toEqual("".concat(ID, "-day"));
55
- var monthitem = dateinput.childNodes[1];
56
- expect(monthitem.tagName).toEqual('DIV');
57
- expect(monthitem.classList).toContain('govuk-date-input__item');
58
- var monthlabel = monthitem.childNodes[0];
59
- expect(monthlabel.tagName).toEqual('LABEL');
60
- expect(monthlabel.classList).toContain('govuk-label');
61
- expect(monthlabel.textContent).toEqual('Month');
62
- var monthinput = monthitem.childNodes[1];
63
- expect(monthinput.tagName).toEqual('INPUT');
64
- expect(monthinput.id).toEqual("".concat(ID, "-month"));
65
- var yearitem = dateinput.childNodes[2];
66
- expect(yearitem.tagName).toEqual('DIV');
67
- expect(yearitem.classList).toContain('govuk-date-input__item');
68
- var yearlabel = yearitem.childNodes[0];
69
- expect(yearlabel.tagName).toEqual('LABEL');
70
- expect(yearlabel.classList).toContain('govuk-label');
71
- expect(yearlabel.textContent).toEqual('Year');
72
- var yearinput = yearitem.childNodes[1];
73
- expect(yearinput.tagName).toEqual('INPUT');
74
- expect(yearinput.id).toEqual("".concat(ID, "-year"));
56
+ expect(dateInput.tagName).toEqual('DIV');
57
+ expect(dateInput.classList).toContain('govuk-date-input');
58
+ expect(dateInput.id).toEqual(ID);
59
+ var _dateInput$childNodes = _slicedToArray(dateInput.childNodes, 3),
60
+ dayItem = _dateInput$childNodes[0],
61
+ monthItem = _dateInput$childNodes[1],
62
+ yearItem = _dateInput$childNodes[2];
63
+ var dayInput = checkDateField(dayItem, {
64
+ id: "".concat(ID, "-day"),
65
+ label: 'Day'
66
+ });
67
+ var monthInput = checkDateField(monthItem, {
68
+ id: "".concat(ID, "-month"),
69
+ label: 'Month'
70
+ });
71
+ var yearInput = checkDateField(yearItem, {
72
+ id: "".concat(ID, "-year"),
73
+ label: 'Year'
74
+ });
75
75
 
76
76
  // Add something to the day and make sure it fires.
77
- _react.fireEvent.change(dayinput, {
77
+ _react.fireEvent.change(dayInput, {
78
78
  target: {
79
79
  name: "".concat(FIELD_ID, "-day"),
80
80
  value: '5'
@@ -86,7 +86,7 @@ describe('utils.Component.get', function () {
86
86
  value: '5--'
87
87
  });
88
88
  // And now the month...
89
- _react.fireEvent.change(monthinput, {
89
+ _react.fireEvent.change(monthInput, {
90
90
  target: {
91
91
  name: "".concat(FIELD_ID, "-month"),
92
92
  value: '11'
@@ -98,7 +98,7 @@ describe('utils.Component.get', function () {
98
98
  value: '5-11-'
99
99
  });
100
100
  // And finally the year.
101
- _react.fireEvent.change(yearinput, {
101
+ _react.fireEvent.change(yearInput, {
102
102
  target: {
103
103
  name: "".concat(FIELD_ID, "-year"),
104
104
  value: '2022'
@@ -63,9 +63,9 @@ describe('utils.Component.get', function () {
63
63
  expect(input2.tagName).toEqual('DIV');
64
64
  expect(input2.classList).toContain('govuk-date-input');
65
65
  expect(input2.id).toEqual(ID2);
66
- expect(input2.childNodes[0].childNodes[1].value).toEqual('1');
67
- expect(input2.childNodes[1].childNodes[1].value).toEqual('2');
68
- expect(input2.childNodes[2].childNodes[1].value).toEqual('2022');
66
+ expect(input2.childNodes[0].childNodes[0].childNodes[1].value).toEqual('1');
67
+ expect(input2.childNodes[1].childNodes[0].childNodes[1].value).toEqual('2');
68
+ expect(input2.childNodes[2].childNodes[0].childNodes[1].value).toEqual('2022');
69
69
  case 35:
70
70
  case "end":
71
71
  return _context.stop();
@@ -61,7 +61,7 @@ describe('utils.Component.get', function () {
61
61
  }].forEach(function (part) {
62
62
  expect(part.item.tagName).toEqual('DIV');
63
63
  expect(part.item.classList).toContain('govuk-date-input__item');
64
- var _part$item$childNodes = _slicedToArray(part.item.childNodes, 2),
64
+ var _part$item$childNodes = _slicedToArray(part.item.childNodes[0].childNodes, 2),
65
65
  inputLabel = _part$item$childNodes[0],
66
66
  input = _part$item$childNodes[1];
67
67
  expect(inputLabel.tagName).toEqual('LABEL');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.27.0",
3
+ "version": "5.27.1",
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": "^3.9.0",
19
+ "@ukhomeoffice/cop-react-components": "^3.14.2",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^4.3.1",