@ukhomeoffice/cop-react-form-renderer 4.84.0 → 4.85.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.
@@ -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.85.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",