@ukhomeoffice/cop-react-form-renderer 5.75.0 → 5.76.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.
@@ -56,7 +56,7 @@ var getTitleRowForItem = function getTitleRowForItem(page, item, pageId, labelCo
56
56
  size: page.collection.titleSize || 's'
57
57
  };
58
58
  };
59
- var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAction) {
59
+ var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAction, item) {
60
60
  if (config.text === '') {
61
61
  return null;
62
62
  }
@@ -64,7 +64,7 @@ var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAct
64
64
  pageId: pageId,
65
65
  fieldId: "heading".concat(labelCount),
66
66
  full_path: "heading".concat(labelCount),
67
- key: config.text,
67
+ key: _copReactComponents.Utils.interpolateString(config.text, item),
68
68
  type: changeAction === null ? 'heading' : 'headingWithAction',
69
69
  size: config.size || 's',
70
70
  action: changeAction === null ? null : {
@@ -159,7 +159,7 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
159
159
  var changeAction = getChangeActionForPage(childPage, onAction, activeIds);
160
160
  if (childPage.collection.heading) {
161
161
  var headingAction = childPage.collection.heading.changeLink ? changeAction : null;
162
- var headingRow = getHeadingRow(childPage.collection.heading, childPage.id, labelCount, headingAction);
162
+ var headingRow = getHeadingRow(childPage.collection.heading, childPage.id, labelCount, headingAction, item);
163
163
  rows = rows.concat(headingRow);
164
164
  }
165
165
  var container = getContainerForPage(childPage, item, labelCount, fullPath);
@@ -415,6 +415,48 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
415
415
  key: 'Test text'
416
416
  });
417
417
  });
418
+ it('should allow interpolation of custom headings', function () {
419
+ var FORM_DATA = {
420
+ collection: [{
421
+ id: '01',
422
+ testText: 'value'
423
+ }]
424
+ };
425
+ var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
426
+ formData: FORM_DATA,
427
+ childPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
428
+ collection: _objectSpread(_objectSpread({}, PAGES[0].collection), {}, {
429
+ // eslint-disable-next-line no-template-curly-in-string
430
+ heading: {
431
+ size: 'm',
432
+ text: 'interpolated text: ${testText}'
433
+ }
434
+ })
435
+ })]
436
+ });
437
+ var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
438
+ expect(ROWS.length).toEqual(7);
439
+ expect(ROWS[0]).toMatchObject({
440
+ type: 'heading',
441
+ key: 'Collection'
442
+ });
443
+ expect(ROWS[1]).toMatchObject({
444
+ type: 'heading',
445
+ key: 'Collection entry 1'
446
+ });
447
+ expect(ROWS[2].action.label).toEqual('Change');
448
+ expect(ROWS[3].action.label).toEqual('custom remove label');
449
+ expect(ROWS[4].action.label).toEqual('custom change label');
450
+ expect(ROWS[5]).toMatchObject({
451
+ type: 'heading',
452
+ key: 'interpolated text: value',
453
+ size: 'm'
454
+ });
455
+ expect(ROWS[6]).toMatchObject({
456
+ value: 'value',
457
+ key: 'Test text'
458
+ });
459
+ });
418
460
  it('should default to a title size of small if one is not specified', function () {
419
461
  var FORM_DATA = {
420
462
  collection: [{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.75.0",
3
+ "version": "5.76.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",