@ukhomeoffice/cop-react-form-renderer 5.28.1 → 5.32.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.
Files changed (61) hide show
  1. package/dist/components/CheckYourAnswers/CheckYourAnswers.js +2 -2
  2. package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +2 -2
  3. package/dist/components/CollectionPage/CollectionPage.js +2 -2
  4. package/dist/components/CollectionPage/CollectionPage.test.js +2 -2
  5. package/dist/components/CollectionSummary/BannerStrip.js +59 -0
  6. package/dist/components/CollectionSummary/BannerStrip.scss +47 -0
  7. package/dist/components/CollectionSummary/BannerStrip.test.js +111 -0
  8. package/dist/components/CollectionSummary/CollectionSummary.js +183 -0
  9. package/dist/components/CollectionSummary/CollectionSummary.scss +21 -0
  10. package/dist/components/CollectionSummary/CollectionSummary.test.js +170 -0
  11. package/dist/components/CollectionSummary/Confirmation.js +60 -0
  12. package/dist/components/CollectionSummary/Confirmation.scss +14 -0
  13. package/dist/components/CollectionSummary/Confirmation.test.js +102 -0
  14. package/dist/components/CollectionSummary/SummaryCard.js +274 -0
  15. package/dist/components/CollectionSummary/SummaryCard.scss +248 -0
  16. package/dist/components/CollectionSummary/SummaryCard.test.js +1164 -0
  17. package/dist/components/CollectionSummary/index.js +10 -0
  18. package/dist/components/FormComponent/Collection.js +2 -2
  19. package/dist/components/FormComponent/FormComponent.js +23 -6
  20. package/dist/components/FormComponent/FormComponent.test.js +66 -34
  21. package/dist/components/FormPage/FormPage.js +12 -5
  22. package/dist/components/FormPage/FormPage.test.js +2 -2
  23. package/dist/components/FormRenderer/FormRenderer.js +10 -5
  24. package/dist/components/FormRenderer/FormRenderer.test.js +218 -133
  25. package/dist/components/FormRenderer/onCYAAction.js +20 -9
  26. package/dist/components/FormRenderer/onCYAAction.test.js +8 -1
  27. package/dist/components/FormRenderer/onPageAction.js +12 -16
  28. package/dist/components/FormRenderer/onPageAction.test.js +11 -7
  29. package/dist/components/PageActions/ActionButton.test.js +2 -2
  30. package/dist/components/SummaryList/GroupAction.js +2 -2
  31. package/dist/components/SummaryList/RowAction.js +2 -2
  32. package/dist/components/SummaryList/SummaryList.test.js +2 -2
  33. package/dist/components/TaskList/Task.js +2 -2
  34. package/dist/components/TaskList/TaskList.js +2 -2
  35. package/dist/components/TaskList/TaskList.test.js +2 -2
  36. package/dist/context/HooksContext/HooksContext.js +2 -2
  37. package/dist/context/HooksContext/HooksContext.test.js +2 -2
  38. package/dist/context/HooksContext/index.js +2 -2
  39. package/dist/context/ValidationContext/ValidationContext.js +2 -2
  40. package/dist/context/ValidationContext/ValidationContext.test.js +2 -2
  41. package/dist/context/ValidationContext/index.js +2 -2
  42. package/dist/hooks/index.js +2 -2
  43. package/dist/hooks/useRefData.js +2 -2
  44. package/dist/index.js +2 -2
  45. package/dist/models/ComponentTypes.js +2 -0
  46. package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -1
  47. package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +4 -21
  48. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +32 -0
  49. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +68 -0
  50. package/dist/utils/CollectionPage/getQuickEditPage.js +74 -0
  51. package/dist/utils/CollectionPage/getQuickEditPage.test.js +109 -0
  52. package/dist/utils/CollectionPage/index.js +4 -0
  53. package/dist/utils/CollectionPage/removeCollectionPageEntry.js +36 -0
  54. package/dist/utils/CollectionPage/removeCollectionPageEntry.test.js +61 -0
  55. package/dist/utils/Component/cleanAttributes.test.js +2 -2
  56. package/dist/utils/Component/isEditable.test.js +2 -2
  57. package/dist/utils/Format/formatDataForComponent.test.js +2 -2
  58. package/dist/utils/Format/formatDataForPage.test.js +2 -2
  59. package/dist/utils/Validate/validateDate.test.js +2 -2
  60. package/dist/utils/Validate/validateMultifile.test.js +2 -2
  61. package/package.json +1 -1
@@ -0,0 +1,1164 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ var _react = require("@testing-library/react");
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
7
+ var _testUtils = require("react-dom/test-utils");
8
+ var _setupTests = require("../../setupTests");
9
+ var _SummaryCard = _interopRequireWildcard(require("./SummaryCard"));
10
+ var _BannerStrip = require("./BannerStrip");
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ 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; }
18
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
19
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // Global imports.
22
+ // Local imports.
23
+ describe('components.CollectionSummary.SummaryCard', function () {
24
+ var classes = _copReactComponents.Utils.classBuilder(_SummaryCard.DEFAULT_CLASS, [], '');
25
+ var ID = 'summaryCardId';
26
+ var ENTRY = {
27
+ id: '001',
28
+ bannerText: 'A banner',
29
+ titleText: 'A title',
30
+ detailsText: 'Some details',
31
+ index: 0,
32
+ summaryText: 'Full details'
33
+ };
34
+ var checkSetup = function checkSetup(container) {
35
+ var cardDiv = container.children[0];
36
+ expect(cardDiv.tagName).toEqual('DIV');
37
+ expect(cardDiv.classList).toContain(_SummaryCard.DEFAULT_CLASS);
38
+ var headerDiv = cardDiv.children[0];
39
+ expect(headerDiv.tagName).toEqual('DIV');
40
+ expect(headerDiv.classList).toContain(classes('header'));
41
+ var headerContentDiv = headerDiv.children[0];
42
+ expect(headerContentDiv.tagName).toEqual('DIV');
43
+ expect(headerContentDiv.classList).toContain(classes('header-content'));
44
+ var headerActionDiv = headerDiv.children[1];
45
+ expect(headerActionDiv.tagName).toEqual('DIV');
46
+ expect(headerActionDiv.className).toContain(classes('header-actions'));
47
+ var bodyDiv = cardDiv.children[1];
48
+ expect(bodyDiv.tagName).toEqual('DIV');
49
+ expect(bodyDiv.classList).toContain(classes('body'));
50
+ return {
51
+ cardDiv: cardDiv,
52
+ headerDiv: headerDiv,
53
+ headerContentDiv: headerContentDiv,
54
+ headerActionDiv: headerActionDiv,
55
+ bodyDiv: bodyDiv
56
+ };
57
+ };
58
+ it('should correctly render a SummaryCard component', function () {
59
+ var CONFIG = {
60
+ banners: ['Alpha', 'Bravo'],
61
+ title: 'Title text',
62
+ details: 'Detail text'
63
+ };
64
+ var _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
65
+ id: ID,
66
+ entryData: ENTRY,
67
+ config: CONFIG,
68
+ parentCollectionName: "parent",
69
+ pages: [],
70
+ formData: {},
71
+ masterPage: {
72
+ childPages: []
73
+ }
74
+ })),
75
+ container = _renderWithValidation.container;
76
+ var _checkSetup = checkSetup(container),
77
+ headerContentDiv = _checkSetup.headerContentDiv;
78
+ expect(headerContentDiv.children.length).toEqual(3);
79
+ var headerBanners = headerContentDiv.children[0];
80
+ expect(headerBanners.tagName).toEqual('DIV');
81
+ expect(headerBanners.classList).toContain(_BannerStrip.DEFAULT_CLASS);
82
+ var headerTitle = headerContentDiv.children[1];
83
+ expect(headerTitle.tagName).toEqual('DIV');
84
+ expect(headerTitle.classList).toContain(classes('header-content-title'));
85
+ expect(headerTitle.textContent).toEqual(CONFIG.title);
86
+ var headerDetails = headerContentDiv.children[2];
87
+ expect(headerDetails.tagName).toEqual('DIV');
88
+ expect(headerDetails.classList).toContain(classes('header-content-detail'));
89
+ expect(headerDetails.textContent).toEqual(CONFIG.details);
90
+ });
91
+ it('should not render a banner if none are supplied', function () {
92
+ var CONFIG = {
93
+ title: 'Title text',
94
+ details: 'Detail text'
95
+ };
96
+ var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
97
+ id: ID,
98
+ entryData: ENTRY,
99
+ config: CONFIG,
100
+ parentCollectionName: "parent",
101
+ pages: [],
102
+ formData: {},
103
+ masterPage: {
104
+ childPages: []
105
+ }
106
+ })),
107
+ container = _renderWithValidation2.container;
108
+ var _checkSetup2 = checkSetup(container),
109
+ headerContentDiv = _checkSetup2.headerContentDiv;
110
+ expect(headerContentDiv.children.length).toEqual(2);
111
+
112
+ // The only two children of the content div should be the title
113
+ // and the details.
114
+
115
+ var headerTitle = headerContentDiv.children[0];
116
+ expect(headerTitle.tagName).toEqual('DIV');
117
+ expect(headerTitle.classList).toContain(classes('header-content-title'));
118
+ expect(headerTitle.textContent).toEqual(CONFIG.title);
119
+ var headerDetails = headerContentDiv.children[1];
120
+ expect(headerDetails.tagName).toEqual('DIV');
121
+ expect(headerDetails.classList).toContain(classes('header-content-detail'));
122
+ expect(headerDetails.textContent).toEqual(CONFIG.details);
123
+ });
124
+ it('should not render details if none are supplied', function () {
125
+ var CONFIG = {
126
+ banners: ['Alpha', 'Bravo'],
127
+ title: 'Title text'
128
+ };
129
+ var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
130
+ id: ID,
131
+ entryData: ENTRY,
132
+ config: CONFIG,
133
+ parentCollectionName: "parent",
134
+ pages: [],
135
+ formData: {},
136
+ masterPage: {
137
+ childPages: []
138
+ }
139
+ })),
140
+ container = _renderWithValidation3.container;
141
+ var _checkSetup3 = checkSetup(container),
142
+ headerContentDiv = _checkSetup3.headerContentDiv;
143
+ expect(headerContentDiv.children.length).toEqual(2);
144
+ var headerBanners = headerContentDiv.children[0];
145
+ expect(headerBanners.tagName).toEqual('DIV');
146
+ expect(headerBanners.classList).toContain(_BannerStrip.DEFAULT_CLASS);
147
+
148
+ // The only two children of the content div should be the banner and
149
+ // the title.
150
+
151
+ var headerTitle = headerContentDiv.children[1];
152
+ expect(headerTitle.tagName).toEqual('DIV');
153
+ expect(headerTitle.classList).toContain(classes('header-content-title'));
154
+ expect(headerTitle.textContent).toEqual(CONFIG.title);
155
+ });
156
+ it('should correctly interpolate the title', function () {
157
+ var CONFIG = {
158
+ // eslint-disable-next-line no-template-curly-in-string
159
+ title: '${titleText} that is interpolated'
160
+ };
161
+ var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
162
+ id: ID,
163
+ entryData: ENTRY,
164
+ config: CONFIG,
165
+ parentCollectionName: "parent",
166
+ pages: [],
167
+ formData: {},
168
+ masterPage: {
169
+ childPages: []
170
+ }
171
+ })),
172
+ container = _renderWithValidation4.container;
173
+ var _checkSetup4 = checkSetup(container),
174
+ headerContentDiv = _checkSetup4.headerContentDiv;
175
+ var headerTitle = headerContentDiv.children[0];
176
+ expect(headerTitle.tagName).toEqual('DIV');
177
+ expect(headerTitle.classList).toContain(classes('header-content-title'));
178
+ expect(headerTitle.textContent).toEqual("".concat(ENTRY.titleText, " that is interpolated"));
179
+ });
180
+ it('should correctly interpolate the details', function () {
181
+ var CONFIG = {
182
+ title: 'Title',
183
+ // eslint-disable-next-line no-template-curly-in-string
184
+ details: '${detailsText} that are interpolated'
185
+ };
186
+ var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
187
+ id: ID,
188
+ entryData: ENTRY,
189
+ config: CONFIG,
190
+ parentCollectionName: "parent",
191
+ pages: [],
192
+ formData: {},
193
+ masterPage: {
194
+ childPages: []
195
+ }
196
+ })),
197
+ container = _renderWithValidation5.container;
198
+ var _checkSetup5 = checkSetup(container),
199
+ headerContentDiv = _checkSetup5.headerContentDiv;
200
+ var headerDetails = headerContentDiv.children[1];
201
+ expect(headerDetails.tagName).toEqual('DIV');
202
+ expect(headerDetails.classList).toContain(classes('header-content-detail'));
203
+ expect(headerDetails.textContent).toEqual("".concat(ENTRY.detailsText, " that are interpolated"));
204
+ });
205
+ describe('Change action button', function () {
206
+ var onChangeArgs = [];
207
+ var onChangeCalls = 0;
208
+ var ON_CHANGE = function ON_CHANGE(page, id) {
209
+ onChangeArgs.push({
210
+ page: page,
211
+ id: id
212
+ });
213
+ onChangeCalls += 1;
214
+ };
215
+ beforeEach(function () {
216
+ onChangeArgs = [];
217
+ onChangeCalls = 0;
218
+ });
219
+ it('should render correctly', function () {
220
+ var CONFIG = {
221
+ changeAction: {
222
+ label: 'Change label',
223
+ page: 'testPage'
224
+ }
225
+ };
226
+ var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
227
+ id: ID,
228
+ entryData: ENTRY,
229
+ config: CONFIG,
230
+ onChange: ON_CHANGE,
231
+ parentCollectionName: "parent",
232
+ pages: [],
233
+ formData: {},
234
+ masterPage: {
235
+ childPages: []
236
+ }
237
+ })),
238
+ container = _renderWithValidation6.container;
239
+ var _checkSetup6 = checkSetup(container),
240
+ headerActionDiv = _checkSetup6.headerActionDiv;
241
+ expect(headerActionDiv.children.length).toEqual(1);
242
+ var changeButton = headerActionDiv.children[0];
243
+ expect(changeButton.tagName).toEqual('BUTTON');
244
+ expect(changeButton.textContent).toEqual(CONFIG.changeAction.label);
245
+ _react.fireEvent.click(changeButton, {});
246
+ expect(onChangeCalls).toEqual(1);
247
+ expect(onChangeArgs[0]).toMatchObject({
248
+ page: CONFIG.changeAction.page,
249
+ id: ENTRY.id
250
+ });
251
+ });
252
+ it('should use the default label when one is not provided', function () {
253
+ var CONFIG = {
254
+ changeAction: {
255
+ page: 'testPage'
256
+ }
257
+ };
258
+ var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
259
+ id: ID,
260
+ entryData: ENTRY,
261
+ config: CONFIG,
262
+ onChange: ON_CHANGE,
263
+ parentCollectionName: "parent",
264
+ pages: [],
265
+ formData: {},
266
+ masterPage: {
267
+ childPages: []
268
+ }
269
+ })),
270
+ container = _renderWithValidation7.container;
271
+ var _checkSetup7 = checkSetup(container),
272
+ headerActionDiv = _checkSetup7.headerActionDiv;
273
+ expect(headerActionDiv.children.length).toEqual(1);
274
+ var changeButton = headerActionDiv.children[0];
275
+ expect(changeButton.tagName).toEqual('BUTTON');
276
+ expect(changeButton.textContent).toEqual(_SummaryCard.DEFAULT_CHANGE_BUTTON_LABEL);
277
+ });
278
+ it('should not render when no config is provided for it', function () {
279
+ var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
280
+ id: ID,
281
+ entryData: ENTRY,
282
+ config: {},
283
+ onChange: ON_CHANGE,
284
+ parentCollectionName: "parent",
285
+ pages: [],
286
+ formData: {},
287
+ masterPage: {
288
+ childPages: []
289
+ }
290
+ })),
291
+ container = _renderWithValidation8.container;
292
+ var _checkSetup8 = checkSetup(container),
293
+ headerActionDiv = _checkSetup8.headerActionDiv;
294
+ expect(headerActionDiv.children.length).toEqual(0);
295
+ });
296
+ it('should not render when onChange is not supplied', function () {
297
+ var CONFIG = {
298
+ changeAction: {
299
+ label: 'Change label',
300
+ page: 'testPage'
301
+ }
302
+ };
303
+ var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
304
+ id: ID,
305
+ entryData: ENTRY,
306
+ config: CONFIG,
307
+ parentCollectionName: "parent",
308
+ pages: [],
309
+ formData: {},
310
+ masterPage: {
311
+ childPages: []
312
+ }
313
+ })),
314
+ container = _renderWithValidation9.container;
315
+ var _checkSetup9 = checkSetup(container),
316
+ headerActionDiv = _checkSetup9.headerActionDiv;
317
+ expect(headerActionDiv.children.length).toEqual(0);
318
+ });
319
+ });
320
+ describe('Delete action button', function () {
321
+ var onDeleteArgs = [];
322
+ var onDeleteCalls = 0;
323
+ var ON_DELETE = function ON_DELETE(entry) {
324
+ onDeleteArgs.push(entry);
325
+ onDeleteCalls += 1;
326
+ };
327
+ beforeEach(function () {
328
+ onDeleteArgs = [];
329
+ onDeleteCalls = 0;
330
+ });
331
+ it('should render correctly', function () {
332
+ var CONFIG = {
333
+ deleteAction: {
334
+ label: 'Delete label'
335
+ }
336
+ };
337
+ var _renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
338
+ id: ID,
339
+ entryData: ENTRY,
340
+ config: CONFIG,
341
+ onDelete: ON_DELETE,
342
+ parentCollectionName: "parent",
343
+ pages: [],
344
+ formData: {},
345
+ masterPage: {
346
+ childPages: []
347
+ }
348
+ })),
349
+ container = _renderWithValidation10.container;
350
+ var _checkSetup10 = checkSetup(container),
351
+ headerActionDiv = _checkSetup10.headerActionDiv;
352
+ expect(headerActionDiv.children.length).toEqual(1);
353
+ var deleteButton = headerActionDiv.children[0];
354
+ expect(deleteButton.tagName).toEqual('BUTTON');
355
+ expect(deleteButton.textContent).toEqual(CONFIG.deleteAction.label);
356
+ _react.fireEvent.click(deleteButton, {});
357
+ expect(onDeleteCalls).toEqual(1);
358
+ expect(onDeleteArgs[0]).toMatchObject(ENTRY);
359
+ });
360
+ it('should use the default label when one is not provided', function () {
361
+ var CONFIG = {
362
+ deleteAction: {}
363
+ };
364
+ var _renderWithValidation11 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
365
+ id: ID,
366
+ entryData: ENTRY,
367
+ config: CONFIG,
368
+ onDelete: ON_DELETE,
369
+ parentCollectionName: "parent",
370
+ pages: [],
371
+ formData: {},
372
+ masterPage: {
373
+ childPages: []
374
+ }
375
+ })),
376
+ container = _renderWithValidation11.container;
377
+ var _checkSetup11 = checkSetup(container),
378
+ headerActionDiv = _checkSetup11.headerActionDiv;
379
+ expect(headerActionDiv.children.length).toEqual(1);
380
+ var deleteButton = headerActionDiv.children[0];
381
+ expect(deleteButton.tagName).toEqual('BUTTON');
382
+ expect(deleteButton.textContent).toEqual(_SummaryCard.DEFAULT_DELETE_BUTTON_LABEL);
383
+ });
384
+ it('should not render when no config is provided for it', function () {
385
+ var _renderWithValidation12 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
386
+ id: ID,
387
+ entryData: ENTRY,
388
+ config: {},
389
+ onDelete: ON_DELETE,
390
+ parentCollectionName: "parent",
391
+ pages: [],
392
+ formData: {},
393
+ masterPage: {
394
+ childPages: []
395
+ }
396
+ })),
397
+ container = _renderWithValidation12.container;
398
+ var _checkSetup12 = checkSetup(container),
399
+ headerActionDiv = _checkSetup12.headerActionDiv;
400
+ expect(headerActionDiv.children.length).toEqual(0);
401
+ });
402
+ it('should not render when onDelete is not supplied', function () {
403
+ var CONFIG = {
404
+ deleteAction: {
405
+ label: 'Delete label'
406
+ }
407
+ };
408
+ var _renderWithValidation13 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
409
+ id: ID,
410
+ entryData: ENTRY,
411
+ config: CONFIG,
412
+ parentCollectionName: "parent",
413
+ pages: [],
414
+ formData: {},
415
+ masterPage: {
416
+ childPages: []
417
+ }
418
+ })),
419
+ container = _renderWithValidation13.container;
420
+ var _checkSetup13 = checkSetup(container),
421
+ headerActionDiv = _checkSetup13.headerActionDiv;
422
+ expect(headerActionDiv.children.length).toEqual(0);
423
+ });
424
+ it('should correctly render the Details section with entry data', function () {
425
+ var CONFIG = {
426
+ deleteAction: {
427
+ label: 'Delete label'
428
+ }
429
+ };
430
+ var _renderWithValidation14 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
431
+ id: ID,
432
+ entryData: ENTRY,
433
+ config: CONFIG,
434
+ parentCollectionName: "parent",
435
+ pages: [],
436
+ formData: {},
437
+ masterPage: {
438
+ childPages: []
439
+ }
440
+ })),
441
+ container = _renderWithValidation14.container;
442
+ var detailsSection = container.querySelector('.details');
443
+ expect(detailsSection).not.toBeNull();
444
+ expect(detailsSection.textContent).toContain(ENTRY.summaryText);
445
+ });
446
+ });
447
+ describe('Duplicate action button', function () {
448
+ var onDuplicateArgs = [];
449
+ var onDuplicateCalls = 0;
450
+ var ON_DUPLICATE = function ON_DUPLICATE(entry) {
451
+ onDuplicateArgs.push(entry);
452
+ onDuplicateCalls += 1;
453
+ };
454
+ beforeEach(function () {
455
+ onDuplicateArgs = [];
456
+ onDuplicateCalls = 0;
457
+ });
458
+ it('should render correctly', function () {
459
+ var CONFIG = {
460
+ duplicateAction: {
461
+ label: 'Duplicate label'
462
+ }
463
+ };
464
+ var _renderWithValidation15 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
465
+ id: ID,
466
+ entryData: ENTRY,
467
+ config: CONFIG,
468
+ onDuplicate: ON_DUPLICATE,
469
+ parentCollectionName: "parent",
470
+ pages: [],
471
+ formData: {},
472
+ masterPage: {
473
+ childPages: []
474
+ }
475
+ })),
476
+ container = _renderWithValidation15.container;
477
+ var _checkSetup14 = checkSetup(container),
478
+ headerActionDiv = _checkSetup14.headerActionDiv;
479
+ expect(headerActionDiv.children.length).toEqual(1);
480
+ var duplicateButton = headerActionDiv.children[0];
481
+ expect(duplicateButton.tagName).toEqual('BUTTON');
482
+ expect(duplicateButton.textContent).toEqual(CONFIG.duplicateAction.label);
483
+ _react.fireEvent.click(duplicateButton, {});
484
+ expect(onDuplicateCalls).toEqual(1);
485
+ expect(onDuplicateArgs[0]).toMatchObject(ENTRY);
486
+ });
487
+ it('should use the default label when one is not provided', function () {
488
+ var CONFIG = {
489
+ duplicateAction: {}
490
+ };
491
+ var _renderWithValidation16 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
492
+ id: ID,
493
+ entryData: ENTRY,
494
+ config: CONFIG,
495
+ onDuplicate: ON_DUPLICATE,
496
+ parentCollectionName: "parent",
497
+ pages: [],
498
+ formData: {},
499
+ masterPage: {
500
+ childPages: []
501
+ }
502
+ })),
503
+ container = _renderWithValidation16.container;
504
+ var _checkSetup15 = checkSetup(container),
505
+ headerActionDiv = _checkSetup15.headerActionDiv;
506
+ expect(headerActionDiv.children.length).toEqual(1);
507
+ var duplicateButton = headerActionDiv.children[0];
508
+ expect(duplicateButton.tagName).toEqual('BUTTON');
509
+ expect(duplicateButton.textContent).toEqual(_SummaryCard.DEFAULT_DUPLICATE_BUTTON_LABEL);
510
+ });
511
+ it('should not render when no config is provided for it', function () {
512
+ var _renderWithValidation17 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
513
+ id: ID,
514
+ entryData: ENTRY,
515
+ config: {},
516
+ onDuplicate: ON_DUPLICATE,
517
+ parentCollectionName: "parent",
518
+ pages: [],
519
+ formData: {},
520
+ masterPage: {
521
+ childPages: []
522
+ }
523
+ })),
524
+ container = _renderWithValidation17.container;
525
+ var _checkSetup16 = checkSetup(container),
526
+ headerActionDiv = _checkSetup16.headerActionDiv;
527
+ expect(headerActionDiv.children.length).toEqual(0);
528
+ });
529
+ it('should not render when onDuplicate is not supplied', function () {
530
+ var CONFIG = {
531
+ duplicateAction: {
532
+ label: 'Duplicate label'
533
+ }
534
+ };
535
+ var _renderWithValidation18 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
536
+ id: ID,
537
+ entryData: ENTRY,
538
+ config: CONFIG,
539
+ parentCollectionName: "parent",
540
+ pages: [],
541
+ formData: {},
542
+ masterPage: {
543
+ childPages: []
544
+ }
545
+ })),
546
+ container = _renderWithValidation18.container;
547
+ var _checkSetup17 = checkSetup(container),
548
+ headerActionDiv = _checkSetup17.headerActionDiv;
549
+ expect(headerActionDiv.children.length).toEqual(0);
550
+ });
551
+ });
552
+ describe('Quick Edit action button', function () {
553
+ var CONFIG = {
554
+ quickEdit: {
555
+ components: [{
556
+ use: 'testText'
557
+ }]
558
+ }
559
+ };
560
+ var PAGES = [{
561
+ id: 'parentPage',
562
+ name: 'parentPage',
563
+ components: [{
564
+ id: 'testText',
565
+ type: 'text',
566
+ label: 'Test text',
567
+ fieldId: 'testText',
568
+ required: true,
569
+ use: 'testText',
570
+ cya_label: 'Test text',
571
+ full_path: 'testText'
572
+ }],
573
+ formData: {
574
+ parents: [{
575
+ id: '1695037579150',
576
+ testText: 'tester',
577
+ testText2: 'test test',
578
+ index: 0
579
+ }]
580
+ }
581
+ }];
582
+ it('should render correctly', function () {
583
+ var _renderWithValidation19 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
584
+ id: ID,
585
+ entryData: ENTRY,
586
+ config: CONFIG,
587
+ pages: PAGES,
588
+ parentCollectionName: "parent",
589
+ formData: {},
590
+ masterPage: {
591
+ childPages: []
592
+ }
593
+ })),
594
+ container = _renderWithValidation19.container;
595
+ var _checkSetup18 = checkSetup(container),
596
+ headerActionDiv = _checkSetup18.headerActionDiv;
597
+ expect(headerActionDiv.children.length).toEqual(1);
598
+
599
+ // Shows edit button but no quick edit
600
+ var editButton = headerActionDiv.children[0];
601
+ expect(editButton.tagName).toEqual('BUTTON');
602
+ expect(editButton.textContent).toEqual('Quick Edit');
603
+ expect(container.childNodes[0].childNodes.length).toEqual(2); // Quick edit hidden
604
+
605
+ // shows quickedit once clicked
606
+ _react.fireEvent.click(editButton, {});
607
+ expect(container.childNodes[0].childNodes.length).toEqual(3); // Quick edit shown
608
+ var quickEdit = container.childNodes[0].childNodes[1];
609
+ expect(quickEdit.textContent).toContain('Test text');
610
+
611
+ // quick edit has proper buttons
612
+ var quickEditButtons = quickEdit.childNodes[2];
613
+ var saveButton = quickEditButtons.childNodes[0];
614
+ var cancelButton = quickEditButtons.childNodes[1];
615
+ expect(saveButton.textContent).toContain('Save');
616
+ expect(cancelButton.textContent).toContain('Cancel');
617
+
618
+ // hides quick edit again adfter clicking cancel
619
+ _react.fireEvent.click(cancelButton, {});
620
+ expect(container.childNodes[0].childNodes.length).toEqual(2); // Quick edit hidden
621
+ });
622
+
623
+ it('should not render when no config is provided for it', function () {
624
+ var _renderWithValidation20 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
625
+ id: ID,
626
+ entryData: ENTRY,
627
+ config: {},
628
+ parentCollectionName: "parent",
629
+ pages: [],
630
+ formData: {},
631
+ masterPage: {
632
+ childPages: []
633
+ }
634
+ })),
635
+ container = _renderWithValidation20.container;
636
+ var _checkSetup19 = checkSetup(container),
637
+ headerActionDiv = _checkSetup19.headerActionDiv;
638
+ expect(headerActionDiv.children.length).toEqual(0);
639
+ });
640
+ });
641
+ describe('Quick Edit save changes', function () {
642
+ var CONFIG = {
643
+ quickEdit: {
644
+ components: [{
645
+ use: 'testText'
646
+ }]
647
+ }
648
+ };
649
+ var PAGES = [{
650
+ id: 'parentPage',
651
+ name: 'parentPage',
652
+ components: [{
653
+ id: 'testText',
654
+ type: 'text',
655
+ label: 'Test text',
656
+ fieldId: 'testText',
657
+ required: true,
658
+ use: 'testText',
659
+ cya_label: 'Test text',
660
+ full_path: 'testText',
661
+ "additionalValidation": [{
662
+ "function": "mustBeLongerThan",
663
+ "value": 3,
664
+ message: 'error'
665
+ }]
666
+ }],
667
+ formData: {
668
+ parents: [{
669
+ id: '1695037579150',
670
+ testText: 'tester',
671
+ testText2: 'test test',
672
+ index: 0
673
+ }]
674
+ }
675
+ }];
676
+ it('should render correctly', function () {
677
+ var _renderWithValidation21 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
678
+ id: ID,
679
+ entryData: ENTRY,
680
+ config: CONFIG,
681
+ pages: PAGES,
682
+ parentCollectionName: "parent",
683
+ formData: {},
684
+ masterPage: {
685
+ childPages: []
686
+ }
687
+ })),
688
+ container = _renderWithValidation21.container;
689
+ var _checkSetup20 = checkSetup(container),
690
+ headerActionDiv = _checkSetup20.headerActionDiv;
691
+ expect(headerActionDiv.children.length).toEqual(1);
692
+
693
+ // Shows edit button but no quick edit
694
+ var editButton = headerActionDiv.children[0];
695
+ expect(editButton.tagName).toEqual('BUTTON');
696
+ expect(editButton.textContent).toEqual('Quick Edit');
697
+ expect(container.childNodes[0].childNodes.length).toEqual(2); // Quick edit hidden
698
+
699
+ // shows quickedit once clicked
700
+ _react.fireEvent.click(editButton, {});
701
+ expect(container.childNodes[0].childNodes.length).toEqual(3); // Quick edit shown
702
+ var quickEdit = container.childNodes[0].childNodes[1];
703
+ expect(quickEdit.textContent).toContain('Test text');
704
+
705
+ // quick edit has proper buttons
706
+ var quickEditButtons = quickEdit.childNodes[2];
707
+ var saveButton = quickEditButtons.childNodes[0];
708
+ var cancelButton = quickEditButtons.childNodes[1];
709
+ expect(saveButton.textContent).toContain('Save');
710
+ expect(cancelButton.textContent).toContain('Cancel');
711
+
712
+ // hides quick edit again adfter clicking cancel
713
+ _react.fireEvent.click(cancelButton, {});
714
+ expect(container.childNodes[0].childNodes.length).toEqual(2); // Quick edit hidden
715
+ });
716
+
717
+ it('should not validate or save if nothing has changed', function () {
718
+ var ON_SUBMIT_CALLS = [];
719
+ var hooks = {
720
+ onSubmit: function onSubmit(type, patch) {
721
+ return ON_SUBMIT_CALLS.push(patch);
722
+ }
723
+ };
724
+ var _renderWithValidation22 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
725
+ id: ID,
726
+ entryData: ENTRY,
727
+ config: CONFIG,
728
+ pages: PAGES,
729
+ parentCollectionName: "parents",
730
+ formData: {},
731
+ masterPage: {
732
+ childPages: []
733
+ }
734
+ }), {
735
+ hooks: hooks
736
+ }),
737
+ container = _renderWithValidation22.container;
738
+ var _checkSetup21 = checkSetup(container),
739
+ headerActionDiv = _checkSetup21.headerActionDiv;
740
+
741
+ // Shows edit button but no quick edit
742
+ var editButton = headerActionDiv.children[0];
743
+
744
+ // shows quickedit once clicked
745
+ _react.fireEvent.click(editButton, {});
746
+ var quickEdit = container.childNodes[0].childNodes[1];
747
+ var quickEditButtons = quickEdit.childNodes[2];
748
+ var saveButton = quickEditButtons.childNodes[0];
749
+ _react.fireEvent.click(saveButton, {});
750
+ expect(ON_SUBMIT_CALLS.length).toEqual(0);
751
+ });
752
+ it('should return after local validation if errors are present', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
753
+ var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT, _renderWithValidation23, container, _checkSetup22, headerActionDiv, editButton, quickEdit, component, componentInput, quickEditButtons, saveButton;
754
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
755
+ while (1) switch (_context3.prev = _context3.next) {
756
+ case 0:
757
+ ON_SUBMIT_CALLS = [];
758
+ hooks = {
759
+ onSubmit: function onSubmit(type, patch) {
760
+ return ON_SUBMIT_CALLS.push(patch);
761
+ }
762
+ };
763
+ ON_QUICK_EDIT_CALLS = [];
764
+ ON_QUICK_EDIT = function ON_QUICK_EDIT(_ref2) {
765
+ var target = _ref2.target;
766
+ ON_QUICK_EDIT_CALLS.push(target);
767
+ };
768
+ _renderWithValidation23 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
769
+ id: ID,
770
+ entryData: _objectSpread(_objectSpread({}, ENTRY), {}, {
771
+ index: 0
772
+ }),
773
+ config: CONFIG,
774
+ pages: PAGES,
775
+ parentCollectionName: "parents",
776
+ onQuickEdit: ON_QUICK_EDIT,
777
+ formData: {
778
+ parents: [{
779
+ testText: 'hello'
780
+ }]
781
+ },
782
+ masterPage: {
783
+ childPages: []
784
+ }
785
+ }), {
786
+ hooks: hooks
787
+ }), container = _renderWithValidation23.container;
788
+ _checkSetup22 = checkSetup(container), headerActionDiv = _checkSetup22.headerActionDiv;
789
+ editButton = headerActionDiv.children[0];
790
+ _react.fireEvent.click(editButton, {});
791
+ quickEdit = container.childNodes[0].childNodes[1];
792
+ component = quickEdit.childNodes[1];
793
+ componentInput = component.childNodes[2];
794
+ quickEditButtons = quickEdit.childNodes[2];
795
+ saveButton = quickEditButtons.childNodes[0]; // Field has validation to force the length of this field to be greater than 2 so this should fail
796
+ _context3.next = 15;
797
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
798
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
799
+ while (1) switch (_context.prev = _context.next) {
800
+ case 0:
801
+ _react.fireEvent.change(componentInput, {
802
+ target: {
803
+ value: 'a'
804
+ }
805
+ });
806
+ case 1:
807
+ case "end":
808
+ return _context.stop();
809
+ }
810
+ }, _callee);
811
+ })));
812
+ case 15:
813
+ _context3.next = 17;
814
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
815
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
816
+ while (1) switch (_context2.prev = _context2.next) {
817
+ case 0:
818
+ _react.fireEvent.click(saveButton, {});
819
+ case 1:
820
+ case "end":
821
+ return _context2.stop();
822
+ }
823
+ }, _callee2);
824
+ })));
825
+ case 17:
826
+ expect(ON_SUBMIT_CALLS.length).toEqual(0);
827
+ expect(ON_QUICK_EDIT_CALLS.length).toEqual(0);
828
+ case 19:
829
+ case "end":
830
+ return _context3.stop();
831
+ }
832
+ }, _callee3);
833
+ })));
834
+ it('should run hook validation when a value changes and local validation is passed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
835
+ var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT, _renderWithValidation24, container, _checkSetup23, headerActionDiv, editButton, quickEdit, component, componentInput, quickEditButtons, saveButton;
836
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
837
+ while (1) switch (_context5.prev = _context5.next) {
838
+ case 0:
839
+ ON_SUBMIT_CALLS = [];
840
+ hooks = {
841
+ onSubmit: function onSubmit(type, patch, notRequired, onError) {
842
+ ON_SUBMIT_CALLS.push(patch);
843
+ onError([{
844
+ error: 'message',
845
+ id: '0'
846
+ }]);
847
+ }
848
+ };
849
+ ON_QUICK_EDIT_CALLS = [];
850
+ ON_QUICK_EDIT = function ON_QUICK_EDIT(_ref6) {
851
+ var target = _ref6.target;
852
+ ON_QUICK_EDIT_CALLS.push(target);
853
+ };
854
+ _renderWithValidation24 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
855
+ id: ID,
856
+ entryData: ENTRY,
857
+ config: CONFIG,
858
+ pages: PAGES,
859
+ parentCollectionName: "parents",
860
+ onQuickEdit: ON_QUICK_EDIT,
861
+ formData: {
862
+ parents: [{
863
+ alreadyProvidedField: 'hello'
864
+ }]
865
+ },
866
+ masterPage: {
867
+ childPages: []
868
+ }
869
+ }), {
870
+ hooks: hooks
871
+ }), container = _renderWithValidation24.container;
872
+ _checkSetup23 = checkSetup(container), headerActionDiv = _checkSetup23.headerActionDiv;
873
+ editButton = headerActionDiv.children[0];
874
+ _react.fireEvent.click(editButton, {});
875
+ quickEdit = container.childNodes[0].childNodes[1]; // Make a change
876
+ component = quickEdit.childNodes[1];
877
+ componentInput = component.childNodes[2];
878
+ _react.fireEvent.change(componentInput, {
879
+ target: {
880
+ value: 'new value'
881
+ }
882
+ });
883
+ quickEditButtons = quickEdit.childNodes[2];
884
+ saveButton = quickEditButtons.childNodes[0];
885
+ _context5.next = 16;
886
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
887
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
888
+ while (1) switch (_context4.prev = _context4.next) {
889
+ case 0:
890
+ _react.fireEvent.click(saveButton, {});
891
+ case 1:
892
+ case "end":
893
+ return _context4.stop();
894
+ }
895
+ }, _callee4);
896
+ })));
897
+ case 16:
898
+ expect(ON_SUBMIT_CALLS[0]).toEqual({
899
+ testText: 'new value'
900
+ });
901
+ expect(ON_QUICK_EDIT_CALLS.length).toEqual(0);
902
+ case 18:
903
+ case "end":
904
+ return _context5.stop();
905
+ }
906
+ }, _callee5);
907
+ })));
908
+ it('should apply changes if no errors are present', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
909
+ var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT, _renderWithValidation25, container, _checkSetup24, headerActionDiv, editButton, quickEdit, component, componentInput, quickEditButtons, saveButton;
910
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
911
+ while (1) switch (_context7.prev = _context7.next) {
912
+ case 0:
913
+ ON_SUBMIT_CALLS = [];
914
+ hooks = {
915
+ onSubmit: function onSubmit(type, patch) {
916
+ return ON_SUBMIT_CALLS.push(patch);
917
+ }
918
+ };
919
+ ON_QUICK_EDIT_CALLS = [];
920
+ ON_QUICK_EDIT = function ON_QUICK_EDIT(_ref9) {
921
+ var target = _ref9.target;
922
+ ON_QUICK_EDIT_CALLS.push(target);
923
+ };
924
+ _renderWithValidation25 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
925
+ id: ID,
926
+ entryData: {
927
+ index: 0,
928
+ id: '0'
929
+ },
930
+ config: CONFIG,
931
+ pages: PAGES,
932
+ parentCollectionName: "parents",
933
+ onQuickEdit: ON_QUICK_EDIT,
934
+ formData: {
935
+ parents: [{
936
+ alreadyProvidedField: 'hello'
937
+ }]
938
+ },
939
+ masterPage: {
940
+ childPages: []
941
+ }
942
+ }), {
943
+ hooks: hooks
944
+ }), container = _renderWithValidation25.container;
945
+ _checkSetup24 = checkSetup(container), headerActionDiv = _checkSetup24.headerActionDiv;
946
+ editButton = headerActionDiv.children[0];
947
+ _react.fireEvent.click(editButton, {});
948
+ quickEdit = container.childNodes[0].childNodes[1]; // Make a change that will be accepted
949
+ component = quickEdit.childNodes[1];
950
+ componentInput = component.childNodes[2];
951
+ _react.fireEvent.change(componentInput, {
952
+ target: {
953
+ value: 'new value'
954
+ }
955
+ });
956
+ quickEditButtons = quickEdit.childNodes[2];
957
+ saveButton = quickEditButtons.childNodes[0];
958
+ _context7.next = 16;
959
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
960
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
961
+ while (1) switch (_context6.prev = _context6.next) {
962
+ case 0:
963
+ _react.fireEvent.click(saveButton, {});
964
+ case 1:
965
+ case "end":
966
+ return _context6.stop();
967
+ }
968
+ }, _callee6);
969
+ })));
970
+ case 16:
971
+ expect(ON_QUICK_EDIT_CALLS.length).toEqual(1);
972
+ expect(ON_QUICK_EDIT_CALLS[0].value[0]).toEqual({
973
+ alreadyProvidedField: 'hello',
974
+ testText: 'new value'
975
+ });
976
+ case 18:
977
+ case "end":
978
+ return _context7.stop();
979
+ }
980
+ }, _callee7);
981
+ })));
982
+ });
983
+ describe('Details prop behavior', function () {
984
+ it('should render the provided details', function () {
985
+ var DETAILS = 'Sample details';
986
+ var CONFIG = {
987
+ title: 'Title',
988
+ details: DETAILS
989
+ };
990
+ var _renderWithValidation26 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
991
+ id: ID,
992
+ entryData: ENTRY,
993
+ config: CONFIG,
994
+ parentCollectionName: "parent",
995
+ pages: [],
996
+ formData: {},
997
+ masterPage: {
998
+ childPages: []
999
+ }
1000
+ })),
1001
+ container = _renderWithValidation26.container;
1002
+ var _checkSetup25 = checkSetup(container),
1003
+ headerContentDiv = _checkSetup25.headerContentDiv;
1004
+ var headerDetails = headerContentDiv.children[1];
1005
+ expect(headerDetails.tagName).toEqual('DIV');
1006
+ expect(headerDetails.classList).toContain(classes('header-content-detail'));
1007
+ expect(headerDetails.textContent).toEqual(DETAILS);
1008
+ });
1009
+ it('should not render details when they are empty', function () {
1010
+ var CONFIG = {
1011
+ title: 'Title',
1012
+ details: ''
1013
+ };
1014
+ var _renderWithValidation27 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1015
+ id: ID,
1016
+ entryData: ENTRY,
1017
+ config: CONFIG,
1018
+ parentCollectionName: "parent",
1019
+ pages: [],
1020
+ formData: {},
1021
+ masterPage: {
1022
+ childPages: []
1023
+ }
1024
+ })),
1025
+ container = _renderWithValidation27.container;
1026
+ var _checkSetup26 = checkSetup(container),
1027
+ headerContentDiv = _checkSetup26.headerContentDiv;
1028
+ // If no details are provided, we expect only the header title to be rendered.
1029
+ expect(headerContentDiv.children.length).toEqual(1);
1030
+ var headerTitle = headerContentDiv.children[0];
1031
+ expect(headerTitle.classList).toContain(classes('header-content-title'));
1032
+ });
1033
+ it('should render the interpolated details', function () {
1034
+ var DETAILS = 'Full {label}';
1035
+ var INTERPOLATED_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
1036
+ label: 'Details'
1037
+ });
1038
+ var CONFIG = {
1039
+ title: 'Title',
1040
+ details: DETAILS
1041
+ };
1042
+ var _renderWithValidation28 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1043
+ id: ID,
1044
+ entryData: INTERPOLATED_ENTRY,
1045
+ config: CONFIG,
1046
+ parentCollectionName: "parent",
1047
+ pages: [],
1048
+ formData: {},
1049
+ masterPage: {
1050
+ childPages: []
1051
+ }
1052
+ })),
1053
+ container = _renderWithValidation28.container;
1054
+ var _checkSetup27 = checkSetup(container),
1055
+ headerContentDiv = _checkSetup27.headerContentDiv;
1056
+ var headerDetails = headerContentDiv.children[1];
1057
+ var expectedInterpolatedString = _copReactComponents.Utils.interpolateString(DETAILS, INTERPOLATED_ENTRY);
1058
+ expect(headerDetails.textContent).toEqual(expectedInterpolatedString);
1059
+ });
1060
+ it('should not render the details div if config.details is not provided', function () {
1061
+ var CONFIG = {
1062
+ title: 'Title'
1063
+ };
1064
+ var _renderWithValidation29 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1065
+ id: ID,
1066
+ entryData: ENTRY,
1067
+ config: CONFIG,
1068
+ parentCollectionName: "parent",
1069
+ pages: [],
1070
+ formData: {},
1071
+ masterPage: {
1072
+ childPages: []
1073
+ }
1074
+ })),
1075
+ container = _renderWithValidation29.container;
1076
+ var _checkSetup28 = checkSetup(container),
1077
+ headerContentDiv = _checkSetup28.headerContentDiv;
1078
+ var headerDetails = headerContentDiv.querySelector("#".concat(ID, ".titleDetail"));
1079
+ expect(headerDetails).toBeNull();
1080
+ });
1081
+ it('should not render the entire details section when hideDetails prop is true', function () {
1082
+ var DETAILS = 'Sample details that should not be displayed';
1083
+ var CONFIG = {
1084
+ title: 'Title',
1085
+ details: DETAILS
1086
+ };
1087
+ var _renderWithValidation30 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1088
+ id: ID,
1089
+ entryData: ENTRY,
1090
+ config: CONFIG,
1091
+ parentCollectionName: "parent",
1092
+ pages: [],
1093
+ formData: {},
1094
+ hideDetails: true,
1095
+ masterPage: {
1096
+ childPages: []
1097
+ }
1098
+ })),
1099
+ container = _renderWithValidation30.container;
1100
+ var detailsComponent = container.querySelector('.details');
1101
+ expect(detailsComponent).toBeNull();
1102
+ });
1103
+ });
1104
+ describe('SummaryLayout config behavior', function () {
1105
+ it('should render sections and fields based on summaryLayout config', function () {
1106
+ var CHILD_PAGE_SAMPLE = [{
1107
+ summaryLayout: {
1108
+ sections: [{
1109
+ title: 'Section 1',
1110
+ columns: 2,
1111
+ fields: ['fieldA', 'fieldB']
1112
+ }, {
1113
+ title: 'Section 2',
1114
+ columns: 1,
1115
+ fields: ['fieldC']
1116
+ }]
1117
+ },
1118
+ components: [{
1119
+ fieldId: 'fieldA'
1120
+ }, {
1121
+ fieldId: 'fieldB'
1122
+ }, {
1123
+ fieldId: 'fieldC'
1124
+ }]
1125
+ }];
1126
+ var CONFIG = {
1127
+ title: 'Title'
1128
+ };
1129
+ var _renderWithValidation31 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1130
+ id: ID,
1131
+ entryData: ENTRY,
1132
+ config: CONFIG,
1133
+ parentCollectionName: "parent",
1134
+ pages: CHILD_PAGE_SAMPLE,
1135
+ formData: {},
1136
+ masterPage: {
1137
+ childPages: []
1138
+ }
1139
+ })),
1140
+ container = _renderWithValidation31.container;
1141
+
1142
+ // Function to find an element by its text content
1143
+ function getByTextContent(parent, text) {
1144
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
1145
+ return el.textContent === text;
1146
+ });
1147
+ }
1148
+
1149
+ // Check for section titles
1150
+ var section1Title = getByTextContent(container, 'Section 1');
1151
+ var section2Title = getByTextContent(container, 'Section 2');
1152
+ expect(section1Title).not.toBeNull();
1153
+ expect(section2Title).not.toBeNull();
1154
+ if (section1Title) {
1155
+ var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
1156
+ expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
1157
+ }
1158
+ if (section2Title) {
1159
+ var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
1160
+ expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
1161
+ }
1162
+ });
1163
+ });
1164
+ });