@ukhomeoffice/cop-react-form-renderer 5.19.1 → 5.20.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.
@@ -137,7 +137,9 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
137
137
  }, title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
138
138
  errors: errors
139
139
  }), type === _models.FormTypes.TASK_CYA && pages.length > 0 && sections && sections.map(function (section) {
140
- return section.tasks.map(function (task, taskIndex) {
140
+ return section.tasks.filter(function (task) {
141
+ return task.state !== _models.TaskStates.TYPES.SKIPPED;
142
+ }).map(function (task, taskIndex) {
141
143
  var filterPages = pages.filter(function (page) {
142
144
  return task.pages.some(function (p) {
143
145
  return p === page.name;
@@ -548,5 +548,57 @@ describe('components', function () {
548
548
  }
549
549
  }, _callee22);
550
550
  })));
551
+ it('should show task list in CYA style and hide pages from skipped tasks', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
552
+ var sections, taskHeading1, namesPageHeading;
553
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
554
+ while (1) switch (_context24.prev = _context24.next) {
555
+ case 0:
556
+ sections = [{
557
+ name: 'These are your tasks',
558
+ tasks: [{
559
+ name: 'Task 1',
560
+ state: 'complete',
561
+ pages: ['names']
562
+ }, {
563
+ name: 'Task 2',
564
+ state: 'skipped',
565
+ pages: ['grade']
566
+ }]
567
+ }];
568
+ _context24.next = 3;
569
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
570
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
571
+ while (1) switch (_context23.prev = _context23.next) {
572
+ case 0:
573
+ (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
574
+ pages: PAGES,
575
+ onRowAction: ON_ROW_ACTION,
576
+ onAction: ON_ACTION,
577
+ hide_title: true,
578
+ sections: sections,
579
+ type: "task-list-cya"
580
+ }), container);
581
+ case 1:
582
+ case "end":
583
+ return _context23.stop();
584
+ }
585
+ }, _callee23);
586
+ })));
587
+ case 3:
588
+ taskHeading1 = container.childNodes[0].childNodes[0];
589
+ expect(taskHeading1.tagName).toEqual('H2');
590
+ expect(taskHeading1.textContent).toEqual('Task 1');
591
+ expect(taskHeading1.classList).toContain("govuk-heading-m");
592
+ namesPageHeading = container.childNodes[0].childNodes[1];
593
+ expect(namesPageHeading.tagName).toEqual('DIV');
594
+ expect(namesPageHeading.textContent).toContain('John');
595
+ expect(namesPageHeading.classList).toContain("group-of-rows");
596
+ expect(container.childNodes[0].childNodes.length).toEqual(2); // second task skipped so not shown
597
+ case 12:
598
+ case "end":
599
+ return _context24.stop();
600
+ }
601
+ }, _callee24);
602
+ })));
551
603
  });
552
604
  });
@@ -17,6 +17,7 @@ var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
17
17
  var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
18
18
  var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
19
19
  var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
20
+ var _mustNotContainSql = _interopRequireDefault(require("./mustNotContainSql"));
20
21
  var _mustSelectOnlyOne = _interopRequireDefault(require("./mustSelectOnlyOne"));
21
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23
  // Local imports
@@ -26,15 +27,16 @@ var functions = {
26
27
  mustBeAfter: _mustBeAfter.default,
27
28
  mustBeBefore: _mustBeBefore.default,
28
29
  mustBeEarlierDateTime: _mustBeEarlierDateTime.default,
29
- mustBeInThePast: _mustBeInThePast.default,
30
+ mustBeGreaterThan: _mustBeGreaterThan.default,
30
31
  mustBeInTheFuture: _mustBeInTheFuture.default,
32
+ mustBeInThePast: _mustBeInThePast.default,
33
+ mustBeLessThan: _mustBeLessThan.default,
31
34
  mustBeLongerThan: _mustBeLongerThan.default,
35
+ mustBeNumbersOnly: _mustBeNumbersOnly.default,
32
36
  mustBeShorterThan: _mustBeShorterThan.default,
33
37
  mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
34
- mustBeNumbersOnly: _mustBeNumbersOnly.default,
35
- mustBeLessThan: _mustBeLessThan.default,
36
- mustBeGreaterThan: _mustBeGreaterThan.default,
37
38
  mustHaveLessThanDecimalPlaces: _mustHaveLessThanDecimalPlaces.default,
39
+ mustNotContainSql: _mustNotContainSql.default,
38
40
  mustSelectOnlyOne: _mustSelectOnlyOne.default
39
41
  };
40
42
  var additionalValidation = function additionalValidation(value, config, component) {
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
8
+ // NOTE: SQL RegEx reference:
9
+ // http://www.symantec.com/connect/articles/detection-sql-injection-and-cross-site-scripting-attacks
10
+ var SQL_COMBINED = /(%27)|(')|(--)|(%23)|(#)|((%3D)|(=))[^\n]*((%27)|(')|(--)|(%3B)|(;))|w*((%27)|('))((%6F)|o|(%4F))((%72)|r|(%52))|((%27)|('))union/i;
11
+ var mustNotContainSql = function mustNotContainSql(value) {
12
+ // eslint-disable-next-line no-extra-boolean-cast
13
+ if (!!value) {
14
+ var string = _typeof(value) === 'object' ? JSON.stringify(value) : String(value);
15
+ return !SQL_COMBINED.test(string);
16
+ }
17
+ return false;
18
+ };
19
+ var _default = mustNotContainSql;
20
+ exports.default = _default;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _mustNotContainSql = _interopRequireDefault(require("./mustNotContainSql"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ describe('utils', function () {
6
+ describe('Validate', function () {
7
+ describe('additional', function () {
8
+ describe('mustNotContainSql', function () {
9
+ test('should return true given a string not containing sql characters', function () {
10
+ var result = (0, _mustNotContainSql.default)('test');
11
+ expect(result).toEqual(true);
12
+ });
13
+ test('should return true given non-string datatype is converted to string', function () {
14
+ var result = (0, _mustNotContainSql.default)(123);
15
+ expect(result).toEqual(true);
16
+ });
17
+ test('should return false given a string containing sql characters', function () {
18
+ var result = (0, _mustNotContainSql.default)("test' OR '1'='1'");
19
+ expect(result).toEqual(false);
20
+ });
21
+ test('should return false given string is null', function () {
22
+ var result = (0, _mustNotContainSql.default)(null);
23
+ expect(result).toEqual(false);
24
+ });
25
+ test('should return false given string is not defined', function () {
26
+ var result = (0, _mustNotContainSql.default)(undefined);
27
+ expect(result).toEqual(false);
28
+ });
29
+ });
30
+ });
31
+ });
32
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.19.1",
3
+ "version": "5.20.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",