@ukhomeoffice/cop-react-form-renderer 5.0.1 → 5.1.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.
@@ -97,6 +97,92 @@ describe('utils.Component.get', function () {
97
97
  expect(ON_CHANGE_CALLS.length).toEqual(2); // No change, so no new event should have fired.
98
98
  });
99
99
 
100
+ it('should work correctly with the returnFullData property on the radios component', function () {
101
+ var ID = 'test-id';
102
+ var FIELD_ID = 'field-id';
103
+ var LABEL = 'label';
104
+ var OPTIONS = [{
105
+ value: 'a',
106
+ label: 'Alpha'
107
+ }, {
108
+ value: 'b',
109
+ label: 'Bravo'
110
+ }];
111
+ var ON_CHANGE_CALLS = [];
112
+ var ON_CHANGE = function ON_CHANGE(e) {
113
+ ON_CHANGE_CALLS.push(e.target);
114
+ };
115
+ var COMPONENT = {
116
+ type: _models.ComponentTypes.RADIOS,
117
+ id: ID,
118
+ fieldId: FIELD_ID,
119
+ label: LABEL,
120
+ data: {
121
+ options: OPTIONS
122
+ },
123
+ returnFullData: true,
124
+ onChange: ON_CHANGE,
125
+ 'data-testid': ID
126
+ };
127
+ var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
128
+ container = _render2.container;
129
+ var _getAllByTestId3 = (0, _react.getAllByTestId)(container, ID),
130
+ _getAllByTestId4 = _slicedToArray(_getAllByTestId3, 2),
131
+ formGroup = _getAllByTestId4[0],
132
+ radios = _getAllByTestId4[1];
133
+ expect(formGroup.tagName).toEqual('DIV');
134
+ expect(formGroup.classList).toContain('govuk-form-group');
135
+ var label;
136
+ formGroup.childNodes.forEach(function (node) {
137
+ // Check if it's an element.
138
+ if (node instanceof Element) {
139
+ if (node.tagName === 'LABEL') {
140
+ label = node;
141
+ }
142
+ }
143
+ });
144
+ expect(label).toBeDefined();
145
+ expect(label.innerHTML).toContain(LABEL);
146
+ expect(label.getAttribute('for')).toEqual(ID);
147
+ expect(radios.tagName).toEqual('DIV');
148
+ expect(radios.classList).toContain('govuk-radios');
149
+ expect(radios.childNodes.length).toEqual(OPTIONS.length);
150
+ var radioItems = [];
151
+ OPTIONS.forEach(function (_, index) {
152
+ var radio = radios.childNodes[index];
153
+ expect(radio instanceof Element).toBeTruthy();
154
+ if (radio instanceof Element) {
155
+ radioItems.push(radio);
156
+ }
157
+ });
158
+ expect(radioItems.length).toEqual(OPTIONS.length);
159
+ OPTIONS.forEach(function (option, index) {
160
+ var radio = radioItems[index];
161
+ expect(radio.tagName).toEqual('DIV');
162
+ expect(radio.classList).toContain('govuk-radios__item');
163
+ var _radio$childNodes2 = _slicedToArray(radio.childNodes, 2),
164
+ input = _radio$childNodes2[0],
165
+ inputLabel = _radio$childNodes2[1];
166
+ expect(input.tagName).toEqual('INPUT');
167
+ expect(input.type).toEqual('radio');
168
+ expect(inputLabel.textContent).toEqual(option.label);
169
+ });
170
+ _react.fireEvent.click(radioItems[0].childNodes[0]); // alpha
171
+ expect(ON_CHANGE_CALLS.length).toEqual(1);
172
+ expect(ON_CHANGE_CALLS[0]).toMatchObject({
173
+ name: FIELD_ID,
174
+ value: OPTIONS[0]
175
+ });
176
+ _react.fireEvent.click(radioItems[1].childNodes[0]); // bravo
177
+ expect(ON_CHANGE_CALLS.length).toEqual(2);
178
+ expect(ON_CHANGE_CALLS[1]).toMatchObject({
179
+ name: FIELD_ID,
180
+ value: OPTIONS[1]
181
+ });
182
+ _react.fireEvent.click(radioItems[1].childNodes[0]); // bravo (already selected, above)
183
+ expect(ON_CHANGE_CALLS.length).toEqual(2); // No change, so no new event should have fired.
184
+ });
185
+
100
186
  it('should return an appropriately rendered radios component with nested components', function () {
101
187
  var ID = 'test-id';
102
188
  var FIELD_ID = 'field-id';
@@ -132,10 +218,10 @@ describe('utils.Component.get', function () {
132
218
  };
133
219
  var _renderWithValidation = (0, _setupTests.renderWithValidation)((0, _getComponent.default)(COMPONENT)),
134
220
  container = _renderWithValidation.container;
135
- var _getAllByTestId3 = (0, _react.getAllByTestId)(container, ID),
136
- _getAllByTestId4 = _slicedToArray(_getAllByTestId3, 2),
137
- formGroup = _getAllByTestId4[0],
138
- radios = _getAllByTestId4[1];
221
+ var _getAllByTestId5 = (0, _react.getAllByTestId)(container, ID),
222
+ _getAllByTestId6 = _slicedToArray(_getAllByTestId5, 2),
223
+ formGroup = _getAllByTestId6[0],
224
+ radios = _getAllByTestId6[1];
139
225
  expect(formGroup.tagName).toEqual('DIV');
140
226
  expect(formGroup.classList).toContain('govuk-form-group');
141
227
  expect(radios.tagName).toEqual('DIV');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.0.1",
3
+ "version": "5.1.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": "^3.0.0",
19
+ "@ukhomeoffice/cop-react-components": "^3.1.0",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^4.3.1",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@babel/cli": "^7.15.4",
27
+ "@babel/eslint-parser": "^7.19.1",
27
28
  "@babel/preset-env": "^7.15.6",
28
29
  "@babel/preset-react": "^7.14.5",
29
30
  "@monaco-editor/react": "^4.3.1",
@@ -44,6 +45,8 @@
44
45
  "@testing-library/user-event": "^12.1.10",
45
46
  "axios-mock-adapter": "^1.18.1",
46
47
  "cross-env": "^7.0.3",
48
+ "eslint-config-airbnb": "^19.0.4",
49
+ "eslint-config-prettier": "^8.6.0",
47
50
  "html-react-parser": "^0.10.5",
48
51
  "node-sass": "^6.0.1",
49
52
  "prop-types": "^15.8.1",