@jahia/data-helper 1.0.5 → 1.0.7
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.
- package/esm/fragments/PredefinedFragments.js +21 -221
- package/esm/fragments/fragments.utils.js +17 -43
- package/esm/fragments/getIsNodeTypeFragment.js +2 -15
- package/esm/fragments/getPermissionFragment.js +3 -28
- package/esm/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -12
- package/esm/hooks/useContentPreview/useContentPreview.js +7 -7
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -2
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -1
- package/esm/hooks/useNodeChecks/useNodeChecks.js +13 -28
- package/esm/hooks/useNodeChecks/useNodeChecks.spec.js +156 -67
- package/esm/hooks/useNodeInfo/useMemoRequest.js +49 -0
- package/esm/hooks/useNodeInfo/useNodeInfo.gql-queries.js +23 -104
- package/esm/hooks/useNodeInfo/useNodeInfo.js +139 -57
- package/esm/hooks/useNodeInfo/useNodeInfo.spec.js +429 -233
- package/esm/hooks/useNodeInfo/useNodeInfo.utils.js +52 -0
- package/esm/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.js +2 -9
- package/esm/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -12
- package/esm/hooks/useTreeEntries/useTreeEntries.js +18 -40
- package/esm/legacy/Picker.gql-fragments.js +4 -34
- package/esm/legacy/Picker.js +31 -113
- package/js/fragments/PredefinedFragments.js +21 -224
- package/js/fragments/encodeName.js +0 -2
- package/js/fragments/fragments.utils.js +17 -44
- package/js/fragments/getIsNodeTypeFragment.js +2 -23
- package/js/fragments/getPermissionFragment.js +3 -38
- package/js/fragments/index.js +0 -4
- package/js/hooks/index.js +0 -10
- package/js/hooks/useContentPreview/index.js +0 -2
- package/js/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -16
- package/js/hooks/useContentPreview/useContentPreview.js +7 -11
- package/js/hooks/useContentPreview/useContentPreview.spec.js +0 -2
- package/js/hooks/useDeepCompareMemo/index.js +0 -2
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -7
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -2
- package/js/hooks/useNodeChecks/index.js +0 -2
- package/js/hooks/useNodeChecks/useNodeChecks.js +13 -30
- package/js/hooks/useNodeChecks/useNodeChecks.spec.js +157 -69
- package/js/hooks/useNodeInfo/index.js +0 -2
- package/js/hooks/useNodeInfo/useMemoRequest.js +56 -0
- package/js/hooks/useNodeInfo/useNodeInfo.gql-queries.js +25 -111
- package/js/hooks/useNodeInfo/useNodeInfo.js +139 -65
- package/js/hooks/useNodeInfo/useNodeInfo.spec.js +430 -236
- package/js/hooks/useNodeInfo/useNodeInfo.utils.js +60 -0
- package/js/hooks/useSchemaFields/index.js +0 -2
- package/js/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -15
- package/js/hooks/useSchemaFields/useSchemaFields.jsx +0 -4
- package/js/hooks/useSiteInfo/index.js +0 -2
- package/js/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -16
- package/js/hooks/useSiteInfo/useSiteInfo.js +2 -12
- package/js/hooks/useSiteInfo/useSiteInfo.spec.js +0 -4
- package/js/hooks/useTreeEntries/index.js +0 -2
- package/js/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -16
- package/js/hooks/useTreeEntries/useTreeEntries.js +18 -46
- package/js/hooks/useTreeEntries/useTreeEntries.spec.js +0 -3
- package/js/index.js +0 -6
- package/js/legacy/Picker.gql-fragments.js +4 -37
- package/js/legacy/Picker.js +31 -134
- package/js/legacy/index.js +0 -4
- package/package.json +1 -1
|
@@ -1,22 +1,54 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
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 method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return 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; }
|
|
3
|
+
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); } }
|
|
4
|
+
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); }); }; }
|
|
1
5
|
import { useNodeInfo } from './index.js';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
6
|
+
import { getQuery } from './useNodeInfo.gql-queries';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
var wait = function wait() {
|
|
9
|
+
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
|
|
10
|
+
return new Promise(function (resolve) {
|
|
11
|
+
setTimeout(resolve, time);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
4
14
|
jest.mock('react-apollo', function () {
|
|
15
|
+
var data = {
|
|
16
|
+
data: {
|
|
17
|
+
jcr: {
|
|
18
|
+
nodeByPath: {
|
|
19
|
+
resourceChildren: {
|
|
20
|
+
nodes: []
|
|
21
|
+
},
|
|
22
|
+
site: {}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
loading: false,
|
|
27
|
+
error: null
|
|
28
|
+
};
|
|
5
29
|
return {
|
|
6
30
|
useQuery: jest.fn(function () {
|
|
31
|
+
return data;
|
|
32
|
+
}),
|
|
33
|
+
useApolloClient: jest.fn(function () {
|
|
7
34
|
return {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
nodes: []
|
|
13
|
-
},
|
|
14
|
-
site: {}
|
|
35
|
+
query: function query() {
|
|
36
|
+
return {
|
|
37
|
+
then: function then(inputFcn) {
|
|
38
|
+
return inputFcn(data);
|
|
15
39
|
}
|
|
16
|
-
}
|
|
40
|
+
};
|
|
17
41
|
},
|
|
18
|
-
|
|
19
|
-
|
|
42
|
+
watchQuery: function watchQuery() {
|
|
43
|
+
return {
|
|
44
|
+
subscribe: function subscribe(inputFcn) {
|
|
45
|
+
inputFcn(data);
|
|
46
|
+
return {
|
|
47
|
+
unsubscribe: function unsubscribe() {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
20
52
|
};
|
|
21
53
|
})
|
|
22
54
|
};
|
|
@@ -28,89 +60,150 @@ jest.mock('react', function () {
|
|
|
28
60
|
if (!current) {
|
|
29
61
|
current = v;
|
|
30
62
|
}
|
|
31
|
-
|
|
32
63
|
return {
|
|
33
64
|
current: current
|
|
34
65
|
};
|
|
35
66
|
},
|
|
36
67
|
useMemo: function useMemo(v) {
|
|
37
68
|
return v();
|
|
69
|
+
},
|
|
70
|
+
useState: function useState(v) {
|
|
71
|
+
return v;
|
|
72
|
+
},
|
|
73
|
+
useEffect: function useEffect(v) {
|
|
74
|
+
return v();
|
|
38
75
|
}
|
|
39
76
|
};
|
|
40
77
|
});
|
|
78
|
+
jest.mock('./useNodeInfo.gql-queries', function () {
|
|
79
|
+
var original = jest.requireActual('./useNodeInfo.gql-queries');
|
|
80
|
+
return {
|
|
81
|
+
getQuery: jest.fn(original.getQuery),
|
|
82
|
+
validOptions: original.validOptions
|
|
83
|
+
};
|
|
84
|
+
});
|
|
41
85
|
describe('useNodeInfo', function () {
|
|
42
86
|
beforeEach(function () {
|
|
43
87
|
jest.restoreAllMocks();
|
|
44
88
|
});
|
|
45
|
-
it('should
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})
|
|
113
|
-
});
|
|
89
|
+
it('should not do a query with invalid parameters', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
90
|
+
var setStateMock, useStateMock, mock, result;
|
|
91
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
92
|
+
while (1) {
|
|
93
|
+
switch (_context.prev = _context.next) {
|
|
94
|
+
case 0:
|
|
95
|
+
setStateMock = jest.fn();
|
|
96
|
+
useStateMock = function useStateMock(useState) {
|
|
97
|
+
return [useState, setStateMock];
|
|
98
|
+
};
|
|
99
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
100
|
+
useNodeInfo({
|
|
101
|
+
invalidProp: 'xx',
|
|
102
|
+
language: 'en'
|
|
103
|
+
});
|
|
104
|
+
_context.next = 6;
|
|
105
|
+
return wait();
|
|
106
|
+
case 6:
|
|
107
|
+
expect(getQuery).toHaveBeenCalled();
|
|
108
|
+
mock = getQuery.mock;
|
|
109
|
+
result = mock.results[mock.results.length - 1];
|
|
110
|
+
expect(result.value.skip).toBeTruthy();
|
|
111
|
+
case 10:
|
|
112
|
+
case "end":
|
|
113
|
+
return _context.stop();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, _callee);
|
|
117
|
+
})));
|
|
118
|
+
it('should request a primaryNodeType', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
119
|
+
var setStateMock, useStateMock, mock, result, variables;
|
|
120
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
121
|
+
while (1) {
|
|
122
|
+
switch (_context2.prev = _context2.next) {
|
|
123
|
+
case 0:
|
|
124
|
+
setStateMock = jest.fn();
|
|
125
|
+
useStateMock = function useStateMock(useState) {
|
|
126
|
+
return [useState, setStateMock];
|
|
127
|
+
};
|
|
128
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
129
|
+
useNodeInfo({
|
|
130
|
+
path: '/test',
|
|
131
|
+
language: 'en',
|
|
132
|
+
displayLanguage: 'en'
|
|
133
|
+
}, {
|
|
134
|
+
getPrimaryNodeType: true
|
|
135
|
+
});
|
|
136
|
+
_context2.next = 6;
|
|
137
|
+
return wait();
|
|
138
|
+
case 6:
|
|
139
|
+
expect(getQuery).toHaveBeenCalled();
|
|
140
|
+
mock = getQuery.mock;
|
|
141
|
+
result = mock.results[mock.results.length - 1];
|
|
142
|
+
variables = result.value.generatedVariables;
|
|
143
|
+
result.value.query.definitions[0].variableDefinitions.map(function (v) {
|
|
144
|
+
return v.variable.name.value;
|
|
145
|
+
}).forEach(function (v) {
|
|
146
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
147
|
+
});
|
|
148
|
+
expect(result.value.query.definitions.map(function (d) {
|
|
149
|
+
return d.name.value;
|
|
150
|
+
})).toContain('NodeInfoPrimaryNodeType');
|
|
151
|
+
case 12:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context2.stop();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, _callee2);
|
|
157
|
+
})));
|
|
158
|
+
it('should request permissions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
159
|
+
var setStateMock, useStateMock, mock, result, variables;
|
|
160
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
161
|
+
while (1) {
|
|
162
|
+
switch (_context3.prev = _context3.next) {
|
|
163
|
+
case 0:
|
|
164
|
+
setStateMock = jest.fn();
|
|
165
|
+
useStateMock = function useStateMock(useState) {
|
|
166
|
+
return [useState, setStateMock];
|
|
167
|
+
};
|
|
168
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
169
|
+
useNodeInfo({
|
|
170
|
+
path: '/test',
|
|
171
|
+
language: 'en'
|
|
172
|
+
}, {
|
|
173
|
+
getPermissions: ['canRead', 'canWrite']
|
|
174
|
+
});
|
|
175
|
+
_context3.next = 6;
|
|
176
|
+
return wait();
|
|
177
|
+
case 6:
|
|
178
|
+
expect(getQuery).toHaveBeenCalled();
|
|
179
|
+
mock = getQuery.mock;
|
|
180
|
+
result = mock.results[mock.results.length - 1];
|
|
181
|
+
variables = result.value.generatedVariables;
|
|
182
|
+
result.value.query.definitions[0].variableDefinitions.map(function (v) {
|
|
183
|
+
return v.variable.name.value;
|
|
184
|
+
}).forEach(function (v) {
|
|
185
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
186
|
+
});
|
|
187
|
+
expect(result.value.query.definitions.map(function (d) {
|
|
188
|
+
return d.name.value;
|
|
189
|
+
})).toContain('NodePermission_permission_encoded_Y2FuUmVhZA');
|
|
190
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
191
|
+
return d.name.value === 'NodePermission_permission_encoded_Y2FuUmVhZA';
|
|
192
|
+
}).selectionSet.selections.map(function (m) {
|
|
193
|
+
return m.alias.value;
|
|
194
|
+
})).toContain('permission_encoded_Y2FuUmVhZA');
|
|
195
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
196
|
+
return d.name.value === 'NodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
197
|
+
}).selectionSet.selections.map(function (m) {
|
|
198
|
+
return m.alias.value;
|
|
199
|
+
})).toContain('permission_encoded_Y2FuV3JpdGU');
|
|
200
|
+
case 14:
|
|
201
|
+
case "end":
|
|
202
|
+
return _context3.stop();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}, _callee3);
|
|
206
|
+
})));
|
|
114
207
|
it('should throw an error if a variable is missing', function () {
|
|
115
208
|
expect(function () {
|
|
116
209
|
return useNodeInfo({
|
|
@@ -120,155 +213,258 @@ describe('useNodeInfo', function () {
|
|
|
120
213
|
});
|
|
121
214
|
}).toThrow();
|
|
122
215
|
});
|
|
123
|
-
it('should request permissions', function () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
216
|
+
it('should request site permissions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
217
|
+
var setStateMock, useStateMock, mock, result, variables;
|
|
218
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
219
|
+
while (1) {
|
|
220
|
+
switch (_context4.prev = _context4.next) {
|
|
221
|
+
case 0:
|
|
222
|
+
setStateMock = jest.fn();
|
|
223
|
+
useStateMock = function useStateMock(useState) {
|
|
224
|
+
return [useState, setStateMock];
|
|
225
|
+
};
|
|
226
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
227
|
+
useNodeInfo({
|
|
228
|
+
path: '/test',
|
|
229
|
+
language: 'en'
|
|
230
|
+
}, {
|
|
231
|
+
getSitePermissions: ['canRead', 'canWrite']
|
|
232
|
+
});
|
|
233
|
+
_context4.next = 6;
|
|
234
|
+
return wait();
|
|
235
|
+
case 6:
|
|
236
|
+
expect(getQuery).toHaveBeenCalled();
|
|
237
|
+
mock = getQuery.mock;
|
|
238
|
+
result = mock.results[mock.results.length - 1];
|
|
239
|
+
variables = result.value.generatedVariables;
|
|
240
|
+
result.value.query.definitions[0].variableDefinitions.map(function (v) {
|
|
241
|
+
return v.variable.name.value;
|
|
242
|
+
}).forEach(function (v) {
|
|
243
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
244
|
+
});
|
|
245
|
+
expect(result.value.query.definitions.map(function (d) {
|
|
246
|
+
return d.name.value;
|
|
247
|
+
})).toContain('SiteNodePermission_permission_encoded_Y2FuUmVhZA');
|
|
248
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
249
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuUmVhZA';
|
|
250
|
+
}).selectionSet.selections[0].name.value).toBe('site');
|
|
251
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
252
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuUmVhZA';
|
|
253
|
+
}).selectionSet.selections[0].selectionSet.selections[1].alias.value).toBe('permission_encoded_Y2FuUmVhZA');
|
|
254
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
255
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
256
|
+
}).selectionSet.selections[0].name.value).toBe('site');
|
|
257
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
258
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
259
|
+
}).selectionSet.selections[0].selectionSet.selections[1].alias.value).toBe('permission_encoded_Y2FuV3JpdGU');
|
|
260
|
+
case 16:
|
|
261
|
+
case "end":
|
|
262
|
+
return _context4.stop();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}, _callee4);
|
|
266
|
+
})));
|
|
267
|
+
it('should request isNodeTypes', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
268
|
+
var setStateMock, useStateMock, mock, result, variables;
|
|
269
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
270
|
+
while (1) {
|
|
271
|
+
switch (_context5.prev = _context5.next) {
|
|
272
|
+
case 0:
|
|
273
|
+
setStateMock = jest.fn();
|
|
274
|
+
useStateMock = function useStateMock(useState) {
|
|
275
|
+
return [useState, setStateMock];
|
|
276
|
+
};
|
|
277
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
278
|
+
useNodeInfo({
|
|
279
|
+
path: '/test',
|
|
280
|
+
language: 'en'
|
|
281
|
+
}, {
|
|
282
|
+
getIsNodeTypes: ['jnt:typeA', 'jnt:typeB']
|
|
283
|
+
});
|
|
284
|
+
_context5.next = 6;
|
|
285
|
+
return wait();
|
|
286
|
+
case 6:
|
|
287
|
+
expect(getQuery).toHaveBeenCalled();
|
|
288
|
+
mock = getQuery.mock;
|
|
289
|
+
result = mock.results[mock.results.length - 1];
|
|
290
|
+
variables = result.value.generatedVariables;
|
|
291
|
+
result.value.query.definitions[0].variableDefinitions.map(function (v) {
|
|
292
|
+
return v.variable.name.value;
|
|
293
|
+
}).forEach(function (v) {
|
|
294
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
295
|
+
});
|
|
296
|
+
expect(result.value.query.definitions.map(function (d) {
|
|
297
|
+
return d.name.value;
|
|
298
|
+
})).toContain('NodeType_nodeType_encoded_am50OnR5cGVB');
|
|
299
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
300
|
+
return d.name.value === 'NodeType_nodeType_encoded_am50OnR5cGVB';
|
|
301
|
+
}).selectionSet.selections.map(function (m) {
|
|
302
|
+
return m.alias.value;
|
|
303
|
+
})).toContain('nodeType_encoded_am50OnR5cGVB');
|
|
304
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
305
|
+
return d.name.value === 'NodeType_nodeType_encoded_am50OnR5cGVC';
|
|
306
|
+
}).selectionSet.selections.map(function (m) {
|
|
307
|
+
return m.alias.value;
|
|
308
|
+
})).toContain('nodeType_encoded_am50OnR5cGVC');
|
|
309
|
+
case 14:
|
|
310
|
+
case "end":
|
|
311
|
+
return _context5.stop();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}, _callee5);
|
|
315
|
+
})));
|
|
316
|
+
it('should request properties', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
317
|
+
var setStateMock, useStateMock, mock, result, variables;
|
|
318
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
319
|
+
while (1) {
|
|
320
|
+
switch (_context6.prev = _context6.next) {
|
|
321
|
+
case 0:
|
|
322
|
+
setStateMock = jest.fn();
|
|
323
|
+
useStateMock = function useStateMock(useState) {
|
|
324
|
+
return [useState, setStateMock];
|
|
325
|
+
};
|
|
326
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
327
|
+
useNodeInfo({
|
|
328
|
+
path: '/test',
|
|
329
|
+
language: 'en'
|
|
330
|
+
}, {
|
|
331
|
+
getProperties: ['propA', 'propB']
|
|
332
|
+
});
|
|
333
|
+
_context6.next = 6;
|
|
334
|
+
return wait();
|
|
335
|
+
case 6:
|
|
336
|
+
expect(getQuery).toHaveBeenCalled();
|
|
337
|
+
mock = getQuery.mock;
|
|
338
|
+
result = mock.results[mock.results.length - 1];
|
|
339
|
+
variables = result.value.generatedVariables;
|
|
340
|
+
result.value.query.definitions[0].variableDefinitions.map(function (v) {
|
|
341
|
+
return v.variable.name.value;
|
|
342
|
+
}).forEach(function (v) {
|
|
343
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
344
|
+
});
|
|
345
|
+
expect(result.value.query.definitions.map(function (d) {
|
|
346
|
+
return d.name.value;
|
|
347
|
+
})).toContain('NodeProperties');
|
|
348
|
+
expect(result.value.query.definitions.find(function (d) {
|
|
349
|
+
return d.name.value === 'NodeProperties';
|
|
350
|
+
}).selectionSet.selections.map(function (m) {
|
|
351
|
+
return m.name.value;
|
|
352
|
+
})).toContain('properties');
|
|
353
|
+
case 13:
|
|
354
|
+
case "end":
|
|
355
|
+
return _context6.stop();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}, _callee6);
|
|
359
|
+
})));
|
|
360
|
+
it('should request all data', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
361
|
+
var setStateMock, useStateMock, mock, result, variables;
|
|
362
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
363
|
+
while (1) {
|
|
364
|
+
switch (_context7.prev = _context7.next) {
|
|
365
|
+
case 0:
|
|
366
|
+
setStateMock = jest.fn();
|
|
367
|
+
useStateMock = function useStateMock(useState) {
|
|
368
|
+
return [useState, setStateMock];
|
|
369
|
+
};
|
|
370
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
371
|
+
useNodeInfo({
|
|
372
|
+
path: '/test',
|
|
373
|
+
language: 'en',
|
|
374
|
+
displayLanguage: 'en'
|
|
375
|
+
}, {
|
|
376
|
+
getDisplayName: true,
|
|
377
|
+
getPrimaryNodeType: true,
|
|
378
|
+
getParent: true,
|
|
379
|
+
getAggregatedPublicationInfo: true,
|
|
380
|
+
getOperationSupport: true,
|
|
381
|
+
getPermissions: ['canRead', 'canWrite'],
|
|
382
|
+
getIsNodeTypes: ['jnt:typeA', 'jnt:typeB'],
|
|
383
|
+
getProperties: ['propA', 'propB'],
|
|
384
|
+
getSiteInstalledModules: true,
|
|
385
|
+
getSiteLanguages: true,
|
|
386
|
+
getDisplayableNodePath: true,
|
|
387
|
+
getLockInfo: true,
|
|
388
|
+
getContributeTypesRestrictions: true,
|
|
389
|
+
getSubNodesCount: {
|
|
390
|
+
types: ['jnt:file']
|
|
391
|
+
},
|
|
392
|
+
getMimeType: true
|
|
393
|
+
});
|
|
394
|
+
_context7.next = 6;
|
|
395
|
+
return wait();
|
|
396
|
+
case 6:
|
|
397
|
+
expect(getQuery).toHaveBeenCalled();
|
|
398
|
+
mock = getQuery.mock;
|
|
399
|
+
result = mock.results[mock.results.length - 1];
|
|
400
|
+
variables = result.value.generatedVariables;
|
|
401
|
+
result.value.query.definitions[0].variableDefinitions.map(function (v) {
|
|
402
|
+
return v.variable.name.value;
|
|
403
|
+
}).forEach(function (v) {
|
|
404
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
405
|
+
});
|
|
406
|
+
case 11:
|
|
407
|
+
case "end":
|
|
408
|
+
return _context7.stop();
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}, _callee7);
|
|
412
|
+
})));
|
|
413
|
+
it('should trigger a graphql request with path', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
414
|
+
var setStateMock, useStateMock;
|
|
415
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
416
|
+
while (1) {
|
|
417
|
+
switch (_context8.prev = _context8.next) {
|
|
418
|
+
case 0:
|
|
419
|
+
setStateMock = jest.fn();
|
|
420
|
+
useStateMock = function useStateMock(useState) {
|
|
421
|
+
return [useState, setStateMock];
|
|
422
|
+
};
|
|
423
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
424
|
+
useNodeInfo({
|
|
425
|
+
path: '/test',
|
|
426
|
+
language: 'en'
|
|
427
|
+
});
|
|
428
|
+
_context8.next = 6;
|
|
429
|
+
return wait();
|
|
430
|
+
case 6:
|
|
431
|
+
expect(setStateMock.mock.calls[0][0].node).toBeDefined();
|
|
432
|
+
expect(setStateMock.mock.calls[0][0].variables).toBeDefined();
|
|
433
|
+
expect(setStateMock.mock.calls[0][0].variables.path).toBe('/test');
|
|
434
|
+
case 9:
|
|
435
|
+
case "end":
|
|
436
|
+
return _context8.stop();
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}, _callee8);
|
|
440
|
+
})));
|
|
441
|
+
it('should trigger a graphql request with multiple paths', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
442
|
+
var setStateMock, useStateMock, paths;
|
|
443
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
444
|
+
while (1) {
|
|
445
|
+
switch (_context9.prev = _context9.next) {
|
|
446
|
+
case 0:
|
|
447
|
+
setStateMock = jest.fn();
|
|
448
|
+
useStateMock = function useStateMock(useState) {
|
|
449
|
+
return [useState, setStateMock];
|
|
450
|
+
};
|
|
451
|
+
jest.spyOn(React, 'useState').mockImplementation(useStateMock);
|
|
452
|
+
paths = ['/test', '/test2'];
|
|
453
|
+
useNodeInfo({
|
|
454
|
+
paths: paths,
|
|
455
|
+
language: 'en'
|
|
456
|
+
});
|
|
457
|
+
_context9.next = 7;
|
|
458
|
+
return wait();
|
|
459
|
+
case 7:
|
|
460
|
+
expect(setStateMock.mock.calls[0][0].node).toBeDefined();
|
|
461
|
+
expect(setStateMock.mock.calls[0][0].variables).toBeDefined();
|
|
462
|
+
expect(setStateMock.mock.calls[0][0].variables.paths).toBe(paths);
|
|
463
|
+
case 10:
|
|
464
|
+
case "end":
|
|
465
|
+
return _context9.stop();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}, _callee9);
|
|
469
|
+
})));
|
|
274
470
|
});
|