@ukhomeoffice/cop-react-form-renderer 4.81.1 → 4.82.1-alpha
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.
|
@@ -12,9 +12,12 @@ var _models = require("../../models");
|
|
|
12
12
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
13
|
var _Container = _interopRequireDefault(require("./Container"));
|
|
14
14
|
require("./Collection.scss");
|
|
15
|
+
var _excluded = ["firstOnlyLabel"];
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
20
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
18
21
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
22
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
20
23
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -149,9 +152,21 @@ var Collection = function Collection(_ref) {
|
|
|
149
152
|
required: config.required,
|
|
150
153
|
full_path: fullPath,
|
|
151
154
|
components: config.item.map(function (component) {
|
|
152
|
-
|
|
155
|
+
var firstOnlyLabel = component.firstOnlyLabel,
|
|
156
|
+
cleanedComponent = _objectWithoutProperties(component, _excluded);
|
|
157
|
+
var hint = component.hint;
|
|
158
|
+
if (config.restrictHint && index > 0) {
|
|
159
|
+
hint = undefined;
|
|
160
|
+
}
|
|
161
|
+
var label = component.label;
|
|
162
|
+
if (index === 0) {
|
|
163
|
+
var _component$firstOnlyL;
|
|
164
|
+
label = (_component$firstOnlyL = component.firstOnlyLabel) !== null && _component$firstOnlyL !== void 0 ? _component$firstOnlyL : component.label;
|
|
165
|
+
}
|
|
166
|
+
return _objectSpread(_objectSpread({}, cleanedComponent), {}, {
|
|
167
|
+
hint: hint,
|
|
153
168
|
readonly: !!(config !== null && config !== void 0 && config.readonly || component.readonly),
|
|
154
|
-
label: _utils.default.interpolateString(
|
|
169
|
+
label: _utils.default.interpolateString(label, _objectSpread(_objectSpread({}, item), {}, {
|
|
155
170
|
index: labelCount
|
|
156
171
|
})),
|
|
157
172
|
fullPath: "".concat(fullPath, ".").concat(component.fieldId)
|
|
@@ -182,6 +197,7 @@ Collection.propTypes = {
|
|
|
182
197
|
id: _propTypes.default.string.isRequired,
|
|
183
198
|
fieldId: _propTypes.default.string.isRequired,
|
|
184
199
|
fullPath: _propTypes.default.string,
|
|
200
|
+
restrictHint: _propTypes.default.bool,
|
|
185
201
|
item: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
186
202
|
fieldId: _propTypes.default.string,
|
|
187
203
|
type: _propTypes.default.string
|
|
@@ -11,6 +11,8 @@ var _Container = require("./Container");
|
|
|
11
11
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
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); }
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
16
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
15
17
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
18
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -451,4 +453,279 @@ describe('components.FormComponent.Collection', function () {
|
|
|
451
453
|
}
|
|
452
454
|
}, _callee10);
|
|
453
455
|
})));
|
|
456
|
+
it('should render a collection component with only a hint on the first item(s) when restrictHint is truthy', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
457
|
+
var FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation7, container, c, item, _item$childNodes4, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
|
|
458
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
459
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
460
|
+
case 0:
|
|
461
|
+
FORM_DATA_TWO_ITEMS = [{
|
|
462
|
+
id: '1',
|
|
463
|
+
text: 'alpha',
|
|
464
|
+
textTwo: 'charlie'
|
|
465
|
+
}, {
|
|
466
|
+
id: '2',
|
|
467
|
+
text: 'beta',
|
|
468
|
+
textTwo: 'delta'
|
|
469
|
+
}];
|
|
470
|
+
TEXT_COMPONENT_TWO = {
|
|
471
|
+
id: 'textTwo',
|
|
472
|
+
fieldId: 'textTwo',
|
|
473
|
+
type: _models.ComponentTypes.TEXT,
|
|
474
|
+
label: 'Text component two',
|
|
475
|
+
hint: 'Text hint two'
|
|
476
|
+
};
|
|
477
|
+
COLLECTION = {
|
|
478
|
+
id: ID,
|
|
479
|
+
fieldId: ID,
|
|
480
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
481
|
+
item: [TEXT_COMPONENT, TEXT_COMPONENT_TWO]
|
|
482
|
+
};
|
|
483
|
+
_renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
484
|
+
component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
|
|
485
|
+
restrictHint: true
|
|
486
|
+
}),
|
|
487
|
+
value: FORM_DATA_TWO_ITEMS,
|
|
488
|
+
formData: FORM_DATA
|
|
489
|
+
})), container = _renderWithValidation7.container; // Check the container itself.
|
|
490
|
+
c = container.childNodes[0];
|
|
491
|
+
expect(c.tagName).toEqual('DIV');
|
|
492
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
493
|
+
|
|
494
|
+
// And now check the first text component within it.
|
|
495
|
+
item = c.childNodes[0];
|
|
496
|
+
expect(item.tagName).toEqual('DIV');
|
|
497
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
498
|
+
_item$childNodes4 = _slicedToArray(item.childNodes, 2), title = _item$childNodes4[0], itemContainer = _item$childNodes4[1];
|
|
499
|
+
expect(title.tagName).toEqual('LABEL');
|
|
500
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
501
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
502
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
503
|
+
|
|
504
|
+
// First item component 1
|
|
505
|
+
formGroup = itemContainer.childNodes[0];
|
|
506
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
507
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
508
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
509
|
+
expect(label.tagName).toEqual('LABEL');
|
|
510
|
+
expect(label.classList).toContain('govuk-label');
|
|
511
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
512
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
513
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
514
|
+
expect(hint.tagName).toEqual('DIV');
|
|
515
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
516
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
517
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
518
|
+
expect(input.tagName).toEqual('INPUT');
|
|
519
|
+
expect(input.classList).toContain('govuk-input');
|
|
520
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
521
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
522
|
+
|
|
523
|
+
// First item component 2
|
|
524
|
+
formGroup = itemContainer.childNodes[1];
|
|
525
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
526
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
527
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
528
|
+
expect(label.tagName).toEqual('LABEL');
|
|
529
|
+
expect(label.classList).toContain('govuk-label');
|
|
530
|
+
expect(label.textContent).toEqual('Text component two (optional)');
|
|
531
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
532
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
533
|
+
expect(hint.tagName).toEqual('DIV');
|
|
534
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
535
|
+
expect(hint.textContent).toEqual('Text hint two');
|
|
536
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
537
|
+
expect(input.tagName).toEqual('INPUT');
|
|
538
|
+
expect(input.classList).toContain('govuk-input');
|
|
539
|
+
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
540
|
+
expect(input.value).toEqual('charlie');
|
|
541
|
+
|
|
542
|
+
// Check the second item and confirm there is no hint
|
|
543
|
+
itemTwo = c.childNodes[1];
|
|
544
|
+
expect(itemTwo.tagName).toEqual('DIV');
|
|
545
|
+
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
546
|
+
_itemTwo$childNodes = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes[0], itemContainerTwo = _itemTwo$childNodes[1];
|
|
547
|
+
expect(titleTwo.tagName).toEqual('LABEL');
|
|
548
|
+
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
549
|
+
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
550
|
+
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
551
|
+
|
|
552
|
+
// Second item first component
|
|
553
|
+
formGroupTwo = itemContainerTwo.childNodes[0];
|
|
554
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
555
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
556
|
+
labelTwo = formGroupTwo.childNodes[0].childNodes[0].childNodes[0];
|
|
557
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
558
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
559
|
+
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
560
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
561
|
+
hintTwo = formGroupTwo.childNodes[0].childNodes[1];
|
|
562
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
563
|
+
inputTwo = formGroupTwo.childNodes[0].childNodes[2];
|
|
564
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
565
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
566
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
567
|
+
expect(inputTwo.value).toEqual('beta');
|
|
568
|
+
|
|
569
|
+
// Second item second component
|
|
570
|
+
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
571
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
572
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
573
|
+
labelTwo = formGroupTwo.childNodes[0].childNodes[0].childNodes[0];
|
|
574
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
575
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
576
|
+
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
577
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
578
|
+
hintTwo = formGroupTwo.childNodes[0].childNodes[1];
|
|
579
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
580
|
+
inputTwo = formGroupTwo.childNodes[0].childNodes[2];
|
|
581
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
582
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
583
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
584
|
+
expect(inputTwo.value).toEqual('delta');
|
|
585
|
+
case 87:
|
|
586
|
+
case "end":
|
|
587
|
+
return _context11.stop();
|
|
588
|
+
}
|
|
589
|
+
}, _callee11);
|
|
590
|
+
})));
|
|
591
|
+
it('should render a unique label for the first item(s) when firstOnlyLabel is defined', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
592
|
+
var UNIQUE_FIRST_LABEL_ONE, UNIQUE_FIRST_LABEL_TWO, FORM_DATA_TWO_ITEMS, TEXT_COMPONENT_TWO, COLLECTION, _renderWithValidation8, container, c, item, _item$childNodes5, title, itemContainer, formGroup, label, hint, input, itemTwo, _itemTwo$childNodes2, titleTwo, itemContainerTwo, formGroupTwo, labelTwo, hintTwo, inputTwo;
|
|
593
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
594
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
595
|
+
case 0:
|
|
596
|
+
UNIQUE_FIRST_LABEL_ONE = 'justForTextOne';
|
|
597
|
+
UNIQUE_FIRST_LABEL_TWO = 'justForTextTwo';
|
|
598
|
+
FORM_DATA_TWO_ITEMS = [{
|
|
599
|
+
id: '1',
|
|
600
|
+
text: 'alpha',
|
|
601
|
+
textTwo: 'charlie'
|
|
602
|
+
}, {
|
|
603
|
+
id: '2',
|
|
604
|
+
text: 'beta',
|
|
605
|
+
textTwo: 'delta'
|
|
606
|
+
}];
|
|
607
|
+
TEXT_COMPONENT_TWO = {
|
|
608
|
+
id: 'textTwo',
|
|
609
|
+
fieldId: 'textTwo',
|
|
610
|
+
type: _models.ComponentTypes.TEXT,
|
|
611
|
+
label: 'Text component two',
|
|
612
|
+
hint: 'Text hint two',
|
|
613
|
+
firstOnlyLabel: UNIQUE_FIRST_LABEL_TWO
|
|
614
|
+
};
|
|
615
|
+
COLLECTION = {
|
|
616
|
+
id: ID,
|
|
617
|
+
fieldId: ID,
|
|
618
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
619
|
+
item: [_objectSpread(_objectSpread({}, TEXT_COMPONENT), {}, {
|
|
620
|
+
firstOnlyLabel: UNIQUE_FIRST_LABEL_ONE
|
|
621
|
+
}), TEXT_COMPONENT_TWO]
|
|
622
|
+
};
|
|
623
|
+
_renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
624
|
+
component: _objectSpread(_objectSpread({}, COLLECTION), {}, {
|
|
625
|
+
restrictHint: true
|
|
626
|
+
}),
|
|
627
|
+
value: FORM_DATA_TWO_ITEMS,
|
|
628
|
+
formData: FORM_DATA
|
|
629
|
+
})), container = _renderWithValidation8.container; // Check the container itself.
|
|
630
|
+
c = container.childNodes[0];
|
|
631
|
+
expect(c.tagName).toEqual('DIV');
|
|
632
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
633
|
+
|
|
634
|
+
// And now check the first text component within it.
|
|
635
|
+
item = c.childNodes[0];
|
|
636
|
+
expect(item.tagName).toEqual('DIV');
|
|
637
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
638
|
+
_item$childNodes5 = _slicedToArray(item.childNodes, 2), title = _item$childNodes5[0], itemContainer = _item$childNodes5[1];
|
|
639
|
+
expect(title.tagName).toEqual('LABEL');
|
|
640
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
641
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
642
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
643
|
+
|
|
644
|
+
// First item component 1
|
|
645
|
+
formGroup = itemContainer.childNodes[0];
|
|
646
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
647
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
648
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
649
|
+
expect(label.tagName).toEqual('LABEL');
|
|
650
|
+
expect(label.classList).toContain('govuk-label');
|
|
651
|
+
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_ONE, " (optional)"));
|
|
652
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
653
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
654
|
+
expect(hint.tagName).toEqual('DIV');
|
|
655
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
656
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
657
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
658
|
+
expect(input.tagName).toEqual('INPUT');
|
|
659
|
+
expect(input.classList).toContain('govuk-input');
|
|
660
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
661
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
662
|
+
|
|
663
|
+
// First item component 2
|
|
664
|
+
formGroup = itemContainer.childNodes[1];
|
|
665
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
666
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
667
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
668
|
+
expect(label.tagName).toEqual('LABEL');
|
|
669
|
+
expect(label.classList).toContain('govuk-label');
|
|
670
|
+
expect(label.textContent).toEqual("".concat(UNIQUE_FIRST_LABEL_TWO, " (optional)"));
|
|
671
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].textTwo"));
|
|
672
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
673
|
+
expect(hint.tagName).toEqual('DIV');
|
|
674
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
675
|
+
expect(hint.textContent).toEqual('Text hint two');
|
|
676
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
677
|
+
expect(input.tagName).toEqual('INPUT');
|
|
678
|
+
expect(input.classList).toContain('govuk-input');
|
|
679
|
+
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
680
|
+
expect(input.value).toEqual('charlie');
|
|
681
|
+
|
|
682
|
+
// Check the second item and confirm there is no hint
|
|
683
|
+
itemTwo = c.childNodes[1];
|
|
684
|
+
expect(itemTwo.tagName).toEqual('DIV');
|
|
685
|
+
expect(itemTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
686
|
+
_itemTwo$childNodes2 = _slicedToArray(itemTwo.childNodes, 2), titleTwo = _itemTwo$childNodes2[0], itemContainerTwo = _itemTwo$childNodes2[1];
|
|
687
|
+
expect(titleTwo.tagName).toEqual('LABEL');
|
|
688
|
+
expect(titleTwo.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
689
|
+
expect(itemContainerTwo.tagName).toEqual('DIV');
|
|
690
|
+
expect(itemContainerTwo.classList).toContain(_Container.DEFAULT_CLASS);
|
|
691
|
+
|
|
692
|
+
// Second item first component
|
|
693
|
+
formGroupTwo = itemContainerTwo.childNodes[0];
|
|
694
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
695
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
696
|
+
labelTwo = formGroupTwo.childNodes[0].childNodes[0].childNodes[0];
|
|
697
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
698
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
699
|
+
expect(labelTwo.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
700
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
701
|
+
hintTwo = formGroupTwo.childNodes[0].childNodes[1];
|
|
702
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
703
|
+
inputTwo = formGroupTwo.childNodes[0].childNodes[2];
|
|
704
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
705
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
706
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
707
|
+
expect(inputTwo.value).toEqual('beta');
|
|
708
|
+
|
|
709
|
+
// Second item second component
|
|
710
|
+
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
711
|
+
expect(formGroupTwo.tagName).toEqual('DIV');
|
|
712
|
+
expect(formGroupTwo.classList).toContain('govuk-form-group');
|
|
713
|
+
labelTwo = formGroupTwo.childNodes[0].childNodes[0].childNodes[0];
|
|
714
|
+
expect(labelTwo.tagName).toEqual('LABEL');
|
|
715
|
+
expect(labelTwo.classList).toContain('govuk-label');
|
|
716
|
+
expect(labelTwo.textContent).toEqual('Text component two (optional)');
|
|
717
|
+
expect(labelTwo.getAttribute('for')).toEqual("".concat(ID, "[1].textTwo"));
|
|
718
|
+
hintTwo = formGroupTwo.childNodes[0].childNodes[1];
|
|
719
|
+
expect(hintTwo.tagName).toEqual(undefined);
|
|
720
|
+
inputTwo = formGroupTwo.childNodes[0].childNodes[2];
|
|
721
|
+
expect(inputTwo.tagName).toEqual('INPUT');
|
|
722
|
+
expect(inputTwo.classList).toContain('govuk-input');
|
|
723
|
+
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
724
|
+
expect(inputTwo.value).toEqual('delta');
|
|
725
|
+
case 89:
|
|
726
|
+
case "end":
|
|
727
|
+
return _context12.stop();
|
|
728
|
+
}
|
|
729
|
+
}, _callee12);
|
|
730
|
+
})));
|
|
454
731
|
});
|
|
@@ -349,12 +349,16 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
349
349
|
(0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors);
|
|
350
350
|
},
|
|
351
351
|
onChange: onChange,
|
|
352
|
-
hashLink: hashLink
|
|
352
|
+
hashLink: hashLink,
|
|
353
|
+
classModifiers: formState.page.classModifiers,
|
|
354
|
+
className: formState.page.className
|
|
353
355
|
}), formState.page && !formState.cya && formState.page.collection && /*#__PURE__*/_react.default.createElement(_CollectionPage.default, {
|
|
354
356
|
page: formState.page,
|
|
355
357
|
onAction: function onAction(action, patch, patchLabel) {
|
|
356
358
|
(0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors);
|
|
357
|
-
}
|
|
359
|
+
},
|
|
360
|
+
classModifiers: formState.page.classModifiers,
|
|
361
|
+
className: formState.page.className
|
|
358
362
|
}));
|
|
359
363
|
};
|
|
360
364
|
var propTypes = {
|