@ukhomeoffice/cop-react-form-renderer 4.84.0 → 4.86.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.
@@ -143,15 +143,11 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
143
143
  });
144
144
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, {
145
145
  key: taskIndex
146
- }, /*#__PURE__*/_react.default.createElement("h3", {
147
- className: "govuk-heading-m govuk-!-margin-top-8 govuk-!-margin-bottom-0"
148
- }, filterPages.length > 0 && task.name), filterPages.map(function (page, pageIndex) {
146
+ }, /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, filterPages.length > 0 && task.name), filterPages.map(function (page, pageIndex) {
149
147
  var hideActionButtons = isGroup(page.id) || noChangeAction;
150
148
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, {
151
149
  key: pageIndex
152
- }, !hide_page_titles && page.title && !isGroup(page.id) && /*#__PURE__*/_react.default.createElement("h4", {
153
- className: "govuk-heading-m govuk-!-margin-top-6 govuk-!-margin-bottom-5"
154
- }, _utils.default.interpolateString(page.title, page.formData)), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
150
+ }, !hide_page_titles && page.title && !isGroup(page.id) && /*#__PURE__*/_react.default.createElement(_copReactComponents.SmallHeading, null, _utils.default.interpolateString(page.title, page.formData)), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
155
151
  rows: page.rows,
156
152
  classModifiers: summaryListClassModifiers,
157
153
  noChangeAction: hideActionButtons,
@@ -334,25 +334,22 @@ describe('components', function () {
334
334
  })));
335
335
  case 3:
336
336
  taskHeading1 = container.childNodes[0].childNodes[0];
337
- expect(taskHeading1.tagName).toEqual('H3');
337
+ expect(taskHeading1.tagName).toEqual('H2');
338
338
  expect(taskHeading1.textContent).toEqual('Task 1');
339
- expect(taskHeading1.classList).toContain("govuk-!-margin-top-8");
340
- expect(taskHeading1.classList).toContain("govuk-!-margin-bottom-0");
339
+ expect(taskHeading1.classList).toContain("govuk-heading-m");
341
340
  namesPageHeading = container.childNodes[0].childNodes[1];
342
341
  expect(namesPageHeading.tagName).toEqual('DIV');
343
342
  expect(namesPageHeading.textContent).toContain('John');
344
343
  expect(namesPageHeading.classList).toContain("group-of-rows");
345
344
  taskHeading2 = container.childNodes[0].childNodes[2];
346
- expect(taskHeading2.tagName).toEqual('H3');
345
+ expect(taskHeading2.tagName).toEqual('H2');
347
346
  expect(taskHeading2.textContent).toEqual('Task 2');
348
- expect(taskHeading2.classList).toContain("govuk-!-margin-top-8");
349
- expect(taskHeading2.classList).toContain("govuk-!-margin-bottom-0");
347
+ expect(taskHeading2.classList).toContain("govuk-heading-m");
350
348
  gradePageHeading = container.childNodes[0].childNodes[3];
351
- expect(gradePageHeading.tagName).toEqual('H4');
349
+ expect(gradePageHeading.tagName).toEqual('H3');
352
350
  expect(gradePageHeading.textContent).toEqual("What's your grade?");
353
- expect(gradePageHeading.classList).toContain("govuk-!-margin-top-6");
354
- expect(gradePageHeading.classList).toContain("govuk-!-margin-bottom-5");
355
- case 22:
351
+ expect(gradePageHeading.classList).toContain("govuk-heading-s");
352
+ case 19:
356
353
  case "end":
357
354
  return _context14.stop();
358
355
  }
@@ -9,6 +9,7 @@ var _Component = _interopRequireDefault(require("../Component"));
9
9
  var _Container = _interopRequireDefault(require("../Container"));
10
10
  var _getSourceData = _interopRequireDefault(require("../Data/getSourceData"));
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ /* eslint-disable no-console */
12
13
  // Local imports
13
14
 
14
15
  var EXCLUDE_FROM_CYA = [_models.ComponentTypes.ALERT, _models.ComponentTypes.HEADING, _models.ComponentTypes.HTML, _models.ComponentTypes.INSET_TEXT];
@@ -32,10 +33,17 @@ var showComponentCYA = function showComponentCYA(options, data) {
32
33
  if (Object.prototype.hasOwnProperty.call(options, 'show_on_cya') && !options.show_on_cya) {
33
34
  return false;
34
35
  }
35
- if (options.hideOnCyaWhenEmpty && options.type === _models.ComponentTypes.COLLECTION) {
36
- var itemCollectionsData = (0, _getSourceData.default)(data, options.full_path);
37
- if (!(itemCollectionsData !== null && itemCollectionsData !== void 0 && itemCollectionsData.length)) {
38
- return false;
36
+ if (options.hideOnCyaWhenEmpty) {
37
+ if (options.type === _models.ComponentTypes.COLLECTION) {
38
+ var itemCollectionsData = (0, _getSourceData.default)(data, options.full_path);
39
+ if (!(itemCollectionsData !== null && itemCollectionsData !== void 0 && itemCollectionsData.length)) {
40
+ return false;
41
+ }
42
+ } else {
43
+ var value = (0, _getSourceData.default)(data, options.fieldId);
44
+ if (!value && value !== false && value !== 0) {
45
+ return false;
46
+ }
39
47
  }
40
48
  }
41
49
  if (options.type === _models.ComponentTypes.CONTAINER) {
@@ -57,9 +57,9 @@ describe('utils', function () {
57
57
  type: _models.ComponentTypes.TEXT
58
58
  }, null)).toBeTruthy();
59
59
  });
60
- it('should show when hideOnCyaWhenEmpty is defined and truthy', function () {
60
+ it('should show when hideOnCyaWhenEmpty is defined and falsy', function () {
61
61
  expect((0, _showComponentCYA.default)({
62
- hideOnCyaWhenEmpty: true
62
+ hideOnCyaWhenEmpty: false
63
63
  })).toBeTruthy();
64
64
  });
65
65
  it('should show collection when hideOnCyaWhenEmpty is not defined', function () {
@@ -73,11 +73,11 @@ describe('utils', function () {
73
73
  type: _models.ComponentTypes.COLLECTION
74
74
  })).toBeFalsy();
75
75
  });
76
- it('should show when it\'s not a collection and hideOnCyaWhenEmpty is truthy', function () {
76
+ it('should not show when it\'s not a collection and hideOnCyaWhenEmpty is truthy', function () {
77
77
  expect((0, _showComponentCYA.default)({
78
78
  hideOnCyaWhenEmpty: true,
79
79
  type: _models.ComponentTypes.TEXT
80
- })).toBeTruthy();
80
+ })).toBeFalsy();
81
81
  });
82
82
  it('should show when length of full_path data is 1 or more', function () {
83
83
  expect((0, _showComponentCYA.default)({
@@ -97,6 +97,47 @@ describe('utils', function () {
97
97
  example: []
98
98
  })).toBeFalsy();
99
99
  });
100
+ it('should show when value of component data does exist and hideOnCyaWhenEmpty is truthy', function () {
101
+ expect((0, _showComponentCYA.default)({
102
+ hideOnCyaWhenEmpty: true,
103
+ type: _models.ComponentTypes.TEXT,
104
+ fieldId: "example"
105
+ }, {
106
+ example: "yes"
107
+ })).toBeTruthy();
108
+ });
109
+ it('should not show when value of component data does not exist and hideOnCyaWhenEmpty is truthy', function () {
110
+ expect((0, _showComponentCYA.default)({
111
+ hideOnCyaWhenEmpty: true,
112
+ type: _models.ComponentTypes.TEXT,
113
+ fieldId: "example"
114
+ }, {})).toBeFalsy();
115
+ });
116
+ it('should show when value of component data does not exist and hideOnCyaWhenEmpty is falsy', function () {
117
+ expect((0, _showComponentCYA.default)({
118
+ hideOnCyaWhenEmpty: false,
119
+ type: _models.ComponentTypes.TEXT,
120
+ fieldId: "example"
121
+ }, {})).toBeTruthy();
122
+ });
123
+ it('should show when value of component data does is falsy and hideOnCyaWhenEmpty is truthy', function () {
124
+ expect((0, _showComponentCYA.default)({
125
+ hideOnCyaWhenEmpty: true,
126
+ type: _models.ComponentTypes.TEXT,
127
+ fieldId: "example"
128
+ }, {
129
+ example: false
130
+ })).toBeTruthy();
131
+ });
132
+ it('should show when value of component data is numerically zero and hideOnCyaWhenEmpty is truthy', function () {
133
+ expect((0, _showComponentCYA.default)({
134
+ hideOnCyaWhenEmpty: true,
135
+ type: _models.ComponentTypes.TEXT,
136
+ fieldId: "example"
137
+ }, {
138
+ example: 0
139
+ })).toBeTruthy();
140
+ });
100
141
  });
101
142
  });
102
143
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.84.0",
3
+ "version": "4.86.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",