jqtree 1.7.5 → 1.8.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.
- package/bower.json +1 -1
- package/config/babel.config.json +1 -1
- package/config/production +2 -0
- package/devserver/devserver_scroll.js +8 -0
- package/devserver/test_scroll.html +28 -0
- package/devserver/test_scroll_container.html +39 -0
- package/docs/_config.yml +1 -1
- package/docs/_entries/general/changelog.md +7 -0
- package/package.json +5 -1
- package/src/dataLoader.ts +44 -19
- package/src/dragAndDropHandler/dragElement.ts +42 -0
- package/src/dragAndDropHandler/hitAreasGenerator.ts +175 -0
- package/src/dragAndDropHandler/index.ts +470 -0
- package/src/dragAndDropHandler/types.ts +12 -0
- package/src/dragAndDropHandler/visibleNodeIterator.ts +97 -0
- package/src/elementsRenderer.ts +75 -40
- package/src/jqtreeMethodTypes.ts +40 -0
- package/src/jqtreeOptions.ts +43 -25
- package/src/keyHandler.ts +59 -30
- package/src/mouse.widget.ts +3 -3
- package/src/mouseWidgetTypes.ts +6 -0
- package/src/nodeElement/borderDropHint.ts +32 -0
- package/src/nodeElement/folderElement.ts +133 -0
- package/src/nodeElement/ghostDropHint.ts +68 -0
- package/src/nodeElement/index.ts +101 -0
- package/src/playwright/coverage.ts +1 -4
- package/src/playwright/playwright.test.ts +0 -4
- package/src/saveStateHandler.ts +75 -26
- package/src/scrollHandler.ts +13 -7
- package/src/selectNodeHandler.ts +10 -16
- package/src/test/jqTree/keyboard.test.ts +18 -23
- package/src/test/jqTree/methods.test.ts +32 -3
- package/src/test/jqTree/options.test.ts +15 -4
- package/src/test/node.test.ts +1 -1
- package/src/tree.jquery.ts +239 -57
- package/src/util.ts +3 -0
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +1728 -2576
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +2 -2
- package/tree.jquery.js.map +1 -1
- package/lib/dataLoader.js +0 -123
- package/lib/dragAndDropHandler.js +0 -588
- package/lib/elementsRenderer.js +0 -267
- package/lib/jqtreeOptions.js +0 -1
- package/lib/keyHandler.js +0 -111
- package/lib/mouse.widget.js +0 -255
- package/lib/node.js +0 -708
- package/lib/nodeElement.js +0 -274
- package/lib/nodeUtils.js +0 -10
- package/lib/playwright/coverage.js +0 -99
- package/lib/playwright/playwright.test.js +0 -606
- package/lib/playwright/testUtils.js +0 -210
- package/lib/saveStateHandler.js +0 -277
- package/lib/scrollHandler/containerScrollParent.js +0 -160
- package/lib/scrollHandler/createScrollParent.js +0 -57
- package/lib/scrollHandler/documentScrollParent.js +0 -169
- package/lib/scrollHandler/scrollParent.js +0 -58
- package/lib/scrollHandler/types.js +0 -1
- package/lib/scrollHandler.js +0 -71
- package/lib/selectNodeHandler.js +0 -128
- package/lib/simple.widget.js +0 -158
- package/lib/test/global.d.js +0 -3
- package/lib/test/jqTree/accessibility.test.js +0 -37
- package/lib/test/jqTree/create.test.js +0 -48
- package/lib/test/jqTree/events.test.js +0 -210
- package/lib/test/jqTree/keyboard.test.js +0 -225
- package/lib/test/jqTree/loadOnDemand.test.js +0 -218
- package/lib/test/jqTree/methods.test.js +0 -1348
- package/lib/test/jqTree/options.test.js +0 -548
- package/lib/test/jqTree/scrollHandler/containerScrollParent.test.js +0 -94
- package/lib/test/node.test.js +0 -1202
- package/lib/test/nodeUtil.test.js +0 -27
- package/lib/test/nodeUtils.test.js +0 -20
- package/lib/test/support/exampleData.js +0 -35
- package/lib/test/support/jqTreeMatchers.js +0 -70
- package/lib/test/support/matchers.d.js +0 -1
- package/lib/test/support/setupTests.js +0 -7
- package/lib/test/support/testUtil.js +0 -29
- package/lib/test/support/treeStructure.js +0 -38
- package/lib/test/util.test.js +0 -26
- package/lib/tree.jquery.d.js +0 -1
- package/lib/tree.jquery.js +0 -1105
- package/lib/types.js +0 -1
- package/lib/typings.d.js +0 -2
- package/lib/util.js +0 -15
- package/lib/version.js +0 -8
- package/src/dragAndDropHandler.ts +0 -713
- package/src/nodeElement.ts +0 -272
- package/src/types.ts +0 -19
|
@@ -1,1348 +0,0 @@
|
|
|
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 _givens = _interopRequireDefault(require("givens"));
|
|
5
|
-
var _dom = require("@testing-library/dom");
|
|
6
|
-
var _msw = require("msw");
|
|
7
|
-
var _node = require("msw/node");
|
|
8
|
-
require("../../tree.jquery");
|
|
9
|
-
var _exampleData = _interopRequireDefault(require("../support/exampleData"));
|
|
10
|
-
var _testUtil = require("../support/testUtil");
|
|
11
|
-
var _version = _interopRequireDefault(require("../../version"));
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
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; }
|
|
14
|
-
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); } }
|
|
15
|
-
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); }); }; }
|
|
16
|
-
var context = describe;
|
|
17
|
-
var server = (0, _node.setupServer)();
|
|
18
|
-
beforeAll(function () {
|
|
19
|
-
return server.listen();
|
|
20
|
-
});
|
|
21
|
-
beforeEach(function () {
|
|
22
|
-
$("body").append('<div id="tree1"></div>');
|
|
23
|
-
});
|
|
24
|
-
afterEach(function () {
|
|
25
|
-
server.resetHandlers();
|
|
26
|
-
var $tree = $("#tree1");
|
|
27
|
-
$tree.tree("destroy");
|
|
28
|
-
$tree.remove();
|
|
29
|
-
localStorage.clear();
|
|
30
|
-
});
|
|
31
|
-
afterAll(function () {
|
|
32
|
-
return server.close();
|
|
33
|
-
});
|
|
34
|
-
describe("addNodeAfter", function () {
|
|
35
|
-
var given = (0, _givens["default"])();
|
|
36
|
-
given("$tree", function () {
|
|
37
|
-
return $("#tree1");
|
|
38
|
-
});
|
|
39
|
-
given("node", function () {
|
|
40
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
41
|
-
});
|
|
42
|
-
beforeEach(function () {
|
|
43
|
-
given.$tree.tree({
|
|
44
|
-
autoOpen: true,
|
|
45
|
-
data: _exampleData["default"]
|
|
46
|
-
});
|
|
47
|
-
given.$tree.tree("addNodeAfter", "added-node", given.node);
|
|
48
|
-
});
|
|
49
|
-
it("adds the node", function () {
|
|
50
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
51
|
-
name: "node1"
|
|
52
|
-
}), expect.objectContaining({
|
|
53
|
-
name: "added-node"
|
|
54
|
-
}), expect.objectContaining({
|
|
55
|
-
name: "node2"
|
|
56
|
-
})]);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe("addNodeBefore", function () {
|
|
60
|
-
var given = (0, _givens["default"])();
|
|
61
|
-
given("$tree", function () {
|
|
62
|
-
return $("#tree1");
|
|
63
|
-
});
|
|
64
|
-
given("node", function () {
|
|
65
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
66
|
-
});
|
|
67
|
-
beforeEach(function () {
|
|
68
|
-
given.$tree.tree({
|
|
69
|
-
autoOpen: true,
|
|
70
|
-
data: _exampleData["default"]
|
|
71
|
-
});
|
|
72
|
-
given.$tree.tree("addNodeBefore", "added-node", given.node);
|
|
73
|
-
});
|
|
74
|
-
it("adds the node", function () {
|
|
75
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
76
|
-
name: "added-node"
|
|
77
|
-
}), expect.objectContaining({
|
|
78
|
-
name: "node1"
|
|
79
|
-
}), expect.objectContaining({
|
|
80
|
-
name: "node2"
|
|
81
|
-
})]);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
describe("addParentNode", function () {
|
|
85
|
-
var given = (0, _givens["default"])();
|
|
86
|
-
given("$tree", function () {
|
|
87
|
-
return $("#tree1");
|
|
88
|
-
});
|
|
89
|
-
given("child1", function () {
|
|
90
|
-
return given.$tree.tree("getNodeByNameMustExist", "child1");
|
|
91
|
-
});
|
|
92
|
-
beforeEach(function () {
|
|
93
|
-
given.$tree.tree({
|
|
94
|
-
autoOpen: true,
|
|
95
|
-
data: _exampleData["default"]
|
|
96
|
-
});
|
|
97
|
-
given.$tree.tree("addParentNode", "new-parent-node", given.child1);
|
|
98
|
-
});
|
|
99
|
-
it("adds the parent node", function () {
|
|
100
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
101
|
-
name: "node1",
|
|
102
|
-
children: [expect.objectContaining({
|
|
103
|
-
name: "new-parent-node",
|
|
104
|
-
children: [expect.objectContaining({
|
|
105
|
-
name: "child1"
|
|
106
|
-
}), expect.objectContaining({
|
|
107
|
-
name: "child2"
|
|
108
|
-
})]
|
|
109
|
-
})]
|
|
110
|
-
}), expect.objectContaining({
|
|
111
|
-
name: "node2"
|
|
112
|
-
})]);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe("addToSelection", function () {
|
|
116
|
-
var given = (0, _givens["default"])();
|
|
117
|
-
given("$tree", function () {
|
|
118
|
-
return $("#tree1");
|
|
119
|
-
});
|
|
120
|
-
given("child1", function () {
|
|
121
|
-
return given.$tree.tree("getNodeByNameMustExist", "child1");
|
|
122
|
-
});
|
|
123
|
-
given("child2", function () {
|
|
124
|
-
return given.$tree.tree("getNodeByNameMustExist", "child2");
|
|
125
|
-
});
|
|
126
|
-
beforeEach(function () {
|
|
127
|
-
given.$tree.tree({
|
|
128
|
-
autoOpen: true,
|
|
129
|
-
data: _exampleData["default"]
|
|
130
|
-
});
|
|
131
|
-
given.$tree.tree("addToSelection", given.child1);
|
|
132
|
-
given.$tree.tree("addToSelection", given.child2);
|
|
133
|
-
});
|
|
134
|
-
it("selects the nodes", function () {
|
|
135
|
-
expect(given.$tree.tree("getSelectedNodes")).toEqual(expect.arrayContaining([given.child1, given.child2]));
|
|
136
|
-
});
|
|
137
|
-
it("renders the nodes correctly", function () {
|
|
138
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
139
|
-
name: "node1",
|
|
140
|
-
selected: false,
|
|
141
|
-
children: [expect.objectContaining({
|
|
142
|
-
name: "child1",
|
|
143
|
-
selected: true
|
|
144
|
-
}), expect.objectContaining({
|
|
145
|
-
name: "child2",
|
|
146
|
-
selected: true
|
|
147
|
-
})]
|
|
148
|
-
}), expect.objectContaining({
|
|
149
|
-
name: "node2",
|
|
150
|
-
selected: false,
|
|
151
|
-
children: [expect.objectContaining({
|
|
152
|
-
name: "node3",
|
|
153
|
-
selected: false
|
|
154
|
-
})]
|
|
155
|
-
})]);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe("appendNode", function () {
|
|
159
|
-
var given = (0, _givens["default"])();
|
|
160
|
-
given("$tree", function () {
|
|
161
|
-
return $("#tree1");
|
|
162
|
-
});
|
|
163
|
-
given("parent", function () {
|
|
164
|
-
return undefined;
|
|
165
|
-
});
|
|
166
|
-
given("nodeData", function () {
|
|
167
|
-
return "appended-node";
|
|
168
|
-
});
|
|
169
|
-
beforeEach(function () {
|
|
170
|
-
given.$tree.tree({
|
|
171
|
-
autoOpen: true,
|
|
172
|
-
data: _exampleData["default"]
|
|
173
|
-
});
|
|
174
|
-
given.$tree.tree("appendNode", given.nodeData, given.parent);
|
|
175
|
-
});
|
|
176
|
-
context("with an empty parent parameter", function () {
|
|
177
|
-
it("appends the node to the tree", function () {
|
|
178
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
179
|
-
name: "node1"
|
|
180
|
-
}), expect.objectContaining({
|
|
181
|
-
name: "node2"
|
|
182
|
-
}), expect.objectContaining({
|
|
183
|
-
name: "appended-node"
|
|
184
|
-
})]);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
context("when appending to a parent node", function () {
|
|
188
|
-
given("parent", function () {
|
|
189
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
190
|
-
});
|
|
191
|
-
it("appends the node to parent node", function () {
|
|
192
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
193
|
-
name: "node1",
|
|
194
|
-
children: [expect.objectContaining({
|
|
195
|
-
name: "child1"
|
|
196
|
-
}), expect.objectContaining({
|
|
197
|
-
name: "child2"
|
|
198
|
-
}), expect.objectContaining({
|
|
199
|
-
name: "appended-node"
|
|
200
|
-
})]
|
|
201
|
-
}), expect.objectContaining({
|
|
202
|
-
name: "node2"
|
|
203
|
-
})]);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
context("when appending a node using an object", function () {
|
|
207
|
-
given("nodeData", function () {
|
|
208
|
-
return {
|
|
209
|
-
color: "green",
|
|
210
|
-
id: 99,
|
|
211
|
-
name: "appended-using-object"
|
|
212
|
-
};
|
|
213
|
-
});
|
|
214
|
-
it("appends the node to the tree", function () {
|
|
215
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
216
|
-
name: "node1"
|
|
217
|
-
}), expect.objectContaining({
|
|
218
|
-
name: "node2"
|
|
219
|
-
}), expect.objectContaining({
|
|
220
|
-
name: "appended-using-object"
|
|
221
|
-
})]);
|
|
222
|
-
});
|
|
223
|
-
it("sets the properties of the object", function () {
|
|
224
|
-
expect(given.$tree.tree("getNodeById", 99)).toMatchObject(given.nodeData);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe("closeNode", function () {
|
|
229
|
-
var given = (0, _givens["default"])();
|
|
230
|
-
given("node1", function () {
|
|
231
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
232
|
-
});
|
|
233
|
-
given("$tree", function () {
|
|
234
|
-
return $("#tree1");
|
|
235
|
-
});
|
|
236
|
-
beforeEach(function () {
|
|
237
|
-
given.$tree.tree({
|
|
238
|
-
autoOpen: true,
|
|
239
|
-
data: _exampleData["default"]
|
|
240
|
-
});
|
|
241
|
-
given.$tree.tree("closeNode", given.node1, false);
|
|
242
|
-
});
|
|
243
|
-
it("closes the node", function () {
|
|
244
|
-
expect(given.node1.element).toBeClosed();
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
describe("getNodeByCallback", function () {
|
|
248
|
-
var given = (0, _givens["default"])();
|
|
249
|
-
given("$tree", function () {
|
|
250
|
-
return $("#tree1");
|
|
251
|
-
});
|
|
252
|
-
beforeEach(function () {
|
|
253
|
-
given.$tree.tree({
|
|
254
|
-
data: _exampleData["default"]
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
it("returns the node", function () {
|
|
258
|
-
var callback = function callback(node) {
|
|
259
|
-
return node.name.startsWith("chi");
|
|
260
|
-
};
|
|
261
|
-
expect(given.$tree.tree("getNodeByCallback", callback)).toMatchObject({
|
|
262
|
-
name: "child1"
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
describe("getNodeByHtmlElement", function () {
|
|
267
|
-
var given = (0, _givens["default"])();
|
|
268
|
-
given("htmlElement", function () {
|
|
269
|
-
return _dom.screen.getByText("node1", {
|
|
270
|
-
selector: ".jqtree-title"
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
given("$tree", function () {
|
|
274
|
-
return $("#tree1");
|
|
275
|
-
});
|
|
276
|
-
beforeEach(function () {
|
|
277
|
-
given.$tree.tree({
|
|
278
|
-
data: _exampleData["default"]
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
it("returns the node", function () {
|
|
282
|
-
expect(given.$tree.tree("getNodeByHtmlElement", given.htmlElement)).toEqual(expect.objectContaining({
|
|
283
|
-
name: "node1"
|
|
284
|
-
}));
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
describe("getNodeById", function () {
|
|
288
|
-
var given = (0, _givens["default"])();
|
|
289
|
-
given("data", function () {
|
|
290
|
-
return _exampleData["default"];
|
|
291
|
-
});
|
|
292
|
-
given("$tree", function () {
|
|
293
|
-
return $("#tree1");
|
|
294
|
-
});
|
|
295
|
-
beforeEach(function () {
|
|
296
|
-
given.$tree.tree({
|
|
297
|
-
data: given.data
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
it("returns the node", function () {
|
|
301
|
-
expect(given.$tree.tree("getNodeById", 127)).toMatchObject({
|
|
302
|
-
name: "node3"
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
context("with a string parameter", function () {
|
|
306
|
-
it("doesn't return the node", function () {
|
|
307
|
-
expect(given.$tree.tree("getNodeById", "127")).toBeNull();
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
context("when the node doesn't exist", function () {
|
|
311
|
-
it("returns null", function () {
|
|
312
|
-
expect(given.$tree.tree("getNodeById", 99999)).toBeNull();
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
context("when the data has string ids", function () {
|
|
316
|
-
given("data", function () {
|
|
317
|
-
return [{
|
|
318
|
-
id: "123",
|
|
319
|
-
name: "node1"
|
|
320
|
-
}];
|
|
321
|
-
});
|
|
322
|
-
context("with a string parameter", function () {
|
|
323
|
-
it("returns the node", function () {
|
|
324
|
-
expect(given.$tree.tree("getNodeById", "123")).toMatchObject({
|
|
325
|
-
name: "node1"
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
context("with a number parameter", function () {
|
|
330
|
-
it("doesn't return the node", function () {
|
|
331
|
-
expect(given.$tree.tree("getNodeById", 123)).toBeNull();
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
context("when the node doesn't exist", function () {
|
|
335
|
-
it("returns null", function () {
|
|
336
|
-
expect(given.$tree.tree("getNodeById", "abc")).toBeNull();
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
describe("getNodesByProperty", function () {
|
|
342
|
-
var given = (0, _givens["default"])();
|
|
343
|
-
given("node1", function () {
|
|
344
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
345
|
-
});
|
|
346
|
-
given("$tree", function () {
|
|
347
|
-
return $("#tree1");
|
|
348
|
-
});
|
|
349
|
-
beforeEach(function () {
|
|
350
|
-
given.$tree.tree({
|
|
351
|
-
data: _exampleData["default"]
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
it("gets nodes by property", function () {
|
|
355
|
-
expect(given.$tree.tree("getNodesByProperty", "intProperty", 1)).toEqual([given.node1]);
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
describe("getSelectedNode", function () {
|
|
359
|
-
var given = (0, _givens["default"])();
|
|
360
|
-
given("$tree", function () {
|
|
361
|
-
return $("#tree1");
|
|
362
|
-
});
|
|
363
|
-
beforeEach(function () {
|
|
364
|
-
given.$tree.tree({
|
|
365
|
-
data: given.treeData
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
context("when nodes have ids", function () {
|
|
369
|
-
given("node", function () {
|
|
370
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
371
|
-
});
|
|
372
|
-
given("treeData", function () {
|
|
373
|
-
return _exampleData["default"];
|
|
374
|
-
});
|
|
375
|
-
context("when no node is selected", function () {
|
|
376
|
-
it("returns false", function () {
|
|
377
|
-
expect(given.$tree.tree("getSelectedNode")).toBe(false);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
context("when a node is selected", function () {
|
|
381
|
-
beforeEach(function () {
|
|
382
|
-
given.$tree.tree("selectNode", given.node);
|
|
383
|
-
});
|
|
384
|
-
it("returns the selected node", function () {
|
|
385
|
-
expect(given.$tree.tree("getSelectedNode")).toBe(given.node);
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
context("when nodes don't have ids", function () {
|
|
390
|
-
given("node", function () {
|
|
391
|
-
return given.$tree.tree("getNodeByNameMustExist", "without-id1");
|
|
392
|
-
});
|
|
393
|
-
given("treeData", function () {
|
|
394
|
-
return ["without-id1", "without-id2"];
|
|
395
|
-
});
|
|
396
|
-
context("when no node is selected", function () {
|
|
397
|
-
it("returns false", function () {
|
|
398
|
-
expect(given.$tree.tree("getSelectedNode")).toBe(false);
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
context("when a node is selected", function () {
|
|
402
|
-
beforeEach(function () {
|
|
403
|
-
given.$tree.tree("selectNode", given.node);
|
|
404
|
-
});
|
|
405
|
-
it("returns the selected node", function () {
|
|
406
|
-
expect(given.$tree.tree("getSelectedNode")).toBe(given.node);
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
describe("getSelectedNodes", function () {
|
|
412
|
-
var given = (0, _givens["default"])();
|
|
413
|
-
given("child1", function () {
|
|
414
|
-
return given.$tree.tree("getNodeByNameMustExist", "child1");
|
|
415
|
-
});
|
|
416
|
-
given("child2", function () {
|
|
417
|
-
return given.$tree.tree("getNodeByNameMustExist", "child2");
|
|
418
|
-
});
|
|
419
|
-
given("$tree", function () {
|
|
420
|
-
return $("#tree1");
|
|
421
|
-
});
|
|
422
|
-
beforeEach(function () {
|
|
423
|
-
given.$tree.tree({
|
|
424
|
-
data: _exampleData["default"]
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
context("when no node is selected", function () {
|
|
428
|
-
it("returns an empty array", function () {
|
|
429
|
-
expect(given.$tree.tree("getSelectedNodes")).toHaveLength(0);
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
context("when nodes are selected", function () {
|
|
433
|
-
beforeEach(function () {
|
|
434
|
-
given.$tree.tree("addToSelection", given.child1);
|
|
435
|
-
given.$tree.tree("addToSelection", given.child2);
|
|
436
|
-
});
|
|
437
|
-
it("returns the selected nodes", function () {
|
|
438
|
-
expect(given.$tree.tree("getSelectedNodes")).toEqual(expect.arrayContaining([given.child1, given.child2]));
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
describe("getState", function () {
|
|
443
|
-
var given = (0, _givens["default"])();
|
|
444
|
-
given("node1", function () {
|
|
445
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
446
|
-
});
|
|
447
|
-
given("$tree", function () {
|
|
448
|
-
return $("#tree1");
|
|
449
|
-
});
|
|
450
|
-
beforeEach(function () {
|
|
451
|
-
given.$tree.tree({
|
|
452
|
-
data: _exampleData["default"]
|
|
453
|
-
});
|
|
454
|
-
given.$tree.tree("openNode", given.node1, false);
|
|
455
|
-
});
|
|
456
|
-
it("returns the state", function () {
|
|
457
|
-
expect(given.$tree.tree("getState")).toEqual({
|
|
458
|
-
open_nodes: [123],
|
|
459
|
-
selected_node: []
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
});
|
|
463
|
-
describe("getStateFromStorage", function () {
|
|
464
|
-
var given = (0, _givens["default"])();
|
|
465
|
-
given("node1", function () {
|
|
466
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
467
|
-
});
|
|
468
|
-
given("$tree", function () {
|
|
469
|
-
return $("#tree1");
|
|
470
|
-
});
|
|
471
|
-
beforeEach(function () {
|
|
472
|
-
given.$tree.tree({
|
|
473
|
-
data: _exampleData["default"],
|
|
474
|
-
saveState: true
|
|
475
|
-
});
|
|
476
|
-
given.$tree.tree("openNode", given.node1, false);
|
|
477
|
-
});
|
|
478
|
-
it("returns the state", function () {
|
|
479
|
-
expect(given.$tree.tree("getStateFromStorage")).toEqual({
|
|
480
|
-
open_nodes: [123],
|
|
481
|
-
selected_node: []
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
describe("getTree", function () {
|
|
486
|
-
var given = (0, _givens["default"])();
|
|
487
|
-
given("$tree", function () {
|
|
488
|
-
return $("#tree1");
|
|
489
|
-
});
|
|
490
|
-
beforeEach(function () {
|
|
491
|
-
given.$tree.tree({
|
|
492
|
-
data: _exampleData["default"]
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
it("returns the tree", function () {
|
|
496
|
-
expect(given.$tree.tree("getTree")).toMatchObject({
|
|
497
|
-
children: [expect.objectContaining({
|
|
498
|
-
name: "node1"
|
|
499
|
-
}), expect.objectContaining({
|
|
500
|
-
name: "node2"
|
|
501
|
-
})]
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
});
|
|
505
|
-
describe("getVersion", function () {
|
|
506
|
-
var given = (0, _givens["default"])();
|
|
507
|
-
given("$tree", function () {
|
|
508
|
-
return $("#tree1");
|
|
509
|
-
});
|
|
510
|
-
beforeEach(function () {
|
|
511
|
-
given.$tree.tree();
|
|
512
|
-
});
|
|
513
|
-
it("returns the version", function () {
|
|
514
|
-
expect(given.$tree.tree("getVersion")).toBe(_version["default"]);
|
|
515
|
-
});
|
|
516
|
-
});
|
|
517
|
-
describe("isNodeSelected", function () {
|
|
518
|
-
var given = (0, _givens["default"])();
|
|
519
|
-
given("node1", function () {
|
|
520
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
521
|
-
});
|
|
522
|
-
given("$tree", function () {
|
|
523
|
-
return $("#tree1");
|
|
524
|
-
});
|
|
525
|
-
beforeEach(function () {
|
|
526
|
-
given.$tree.tree({
|
|
527
|
-
data: _exampleData["default"]
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
context("when the node is selected", function () {
|
|
531
|
-
beforeEach(function () {
|
|
532
|
-
given.$tree.tree("selectNode", given.node1);
|
|
533
|
-
});
|
|
534
|
-
it("returns true", function () {
|
|
535
|
-
expect(given.$tree.tree("isNodeSelected", given.node1)).toBeTrue();
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
context("when the node is not selected", function () {
|
|
539
|
-
it("returns false", function () {
|
|
540
|
-
expect(given.$tree.tree("isNodeSelected", given.node1)).toBeFalse();
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
});
|
|
544
|
-
describe("loadData", function () {
|
|
545
|
-
var given = (0, _givens["default"])();
|
|
546
|
-
given("initialData", function () {
|
|
547
|
-
return ["initial1"];
|
|
548
|
-
});
|
|
549
|
-
given("$tree", function () {
|
|
550
|
-
return $("#tree1");
|
|
551
|
-
});
|
|
552
|
-
beforeEach(function () {
|
|
553
|
-
given.$tree.tree({
|
|
554
|
-
data: given.initialData
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
context("when the node parameter is empty", function () {
|
|
558
|
-
beforeEach(function () {
|
|
559
|
-
given.$tree.tree("loadData", _exampleData["default"]);
|
|
560
|
-
});
|
|
561
|
-
it("replaces the whole tree", function () {
|
|
562
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
563
|
-
name: "node1",
|
|
564
|
-
children: [expect.objectContaining({
|
|
565
|
-
name: "child1"
|
|
566
|
-
}), expect.objectContaining({
|
|
567
|
-
name: "child2"
|
|
568
|
-
})]
|
|
569
|
-
}), expect.objectContaining({
|
|
570
|
-
name: "node2",
|
|
571
|
-
children: [expect.objectContaining({
|
|
572
|
-
name: "node3"
|
|
573
|
-
})]
|
|
574
|
-
})]);
|
|
575
|
-
});
|
|
576
|
-
});
|
|
577
|
-
context("with a node parameter", function () {
|
|
578
|
-
beforeEach(function () {
|
|
579
|
-
given.$tree.tree("loadData", _exampleData["default"], given.$tree.tree("getNodeByNameMustExist", "initial1"));
|
|
580
|
-
});
|
|
581
|
-
it("loads the data under the node", function () {
|
|
582
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
583
|
-
name: "initial1",
|
|
584
|
-
children: [expect.objectContaining({
|
|
585
|
-
name: "node1",
|
|
586
|
-
children: [expect.objectContaining({
|
|
587
|
-
name: "child1"
|
|
588
|
-
}), expect.objectContaining({
|
|
589
|
-
name: "child2"
|
|
590
|
-
})]
|
|
591
|
-
}), expect.objectContaining({
|
|
592
|
-
name: "node2"
|
|
593
|
-
})]
|
|
594
|
-
})]);
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
context("with a node parameter which has a selected child", function () {
|
|
598
|
-
given("initialData", function () {
|
|
599
|
-
return _exampleData["default"];
|
|
600
|
-
});
|
|
601
|
-
beforeEach(function () {
|
|
602
|
-
given.$tree.tree("selectNode", given.$tree.tree("getNodeByNameMustExist", "child1"));
|
|
603
|
-
});
|
|
604
|
-
it("deselects the node", function () {
|
|
605
|
-
given.$tree.tree("loadData", ["new-child1"], given.$tree.tree("getNodeByNameMustExist", "node1"));
|
|
606
|
-
expect(given.$tree.tree("getSelectedNode")).toBeFalse();
|
|
607
|
-
});
|
|
608
|
-
context("when the selected node doesn't have an id", function () {
|
|
609
|
-
given("initialData", function () {
|
|
610
|
-
return [{
|
|
611
|
-
name: "node1",
|
|
612
|
-
children: ["child1", "child2"]
|
|
613
|
-
}, "node2"];
|
|
614
|
-
});
|
|
615
|
-
it("deselects the node", function () {
|
|
616
|
-
given.$tree.tree("loadData", ["new-child1"], given.$tree.tree("getNodeByNameMustExist", "node1"));
|
|
617
|
-
expect(given.$tree.tree("getSelectedNode")).toBeFalse();
|
|
618
|
-
});
|
|
619
|
-
context("when the selected child is under another node", function () {
|
|
620
|
-
it("doesn't deselect the node", function () {
|
|
621
|
-
given.$tree.tree("loadData", ["new-child1"], given.$tree.tree("getNodeByNameMustExist", "node2"));
|
|
622
|
-
expect(given.$tree.tree("getSelectedNode")).toMatchObject({
|
|
623
|
-
name: "child1"
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
});
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
});
|
|
630
|
-
describe("loadDataFromUrl", function () {
|
|
631
|
-
var given = (0, _givens["default"])();
|
|
632
|
-
given("initialData", function () {
|
|
633
|
-
return [];
|
|
634
|
-
});
|
|
635
|
-
given("serverData", function () {
|
|
636
|
-
return _exampleData["default"];
|
|
637
|
-
});
|
|
638
|
-
given("$tree", function () {
|
|
639
|
-
return $("#tree1");
|
|
640
|
-
});
|
|
641
|
-
beforeEach(function () {
|
|
642
|
-
server.use(_msw.rest.get("/tree/", function (_request, response, ctx) {
|
|
643
|
-
return response(ctx.status(200), ctx.json(given.serverData));
|
|
644
|
-
}));
|
|
645
|
-
given.$tree.tree({
|
|
646
|
-
data: given.initialData
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
context("with url parameter", function () {
|
|
650
|
-
it("loads the tree", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
651
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
652
|
-
while (1) switch (_context.prev = _context.next) {
|
|
653
|
-
case 0:
|
|
654
|
-
given.$tree.tree("loadDataFromUrl", "/tree/");
|
|
655
|
-
_context.next = 3;
|
|
656
|
-
return _dom.screen.findByText("node1");
|
|
657
|
-
case 3:
|
|
658
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
659
|
-
name: "node1"
|
|
660
|
-
}), expect.objectContaining({
|
|
661
|
-
name: "node2"
|
|
662
|
-
})]);
|
|
663
|
-
case 4:
|
|
664
|
-
case "end":
|
|
665
|
-
return _context.stop();
|
|
666
|
-
}
|
|
667
|
-
}, _callee);
|
|
668
|
-
})));
|
|
669
|
-
context("with parent node", function () {
|
|
670
|
-
given("initialData", function () {
|
|
671
|
-
return ["initial1", "initial2"];
|
|
672
|
-
});
|
|
673
|
-
given("serverData", function () {
|
|
674
|
-
return ["new1", "new2"];
|
|
675
|
-
});
|
|
676
|
-
it("loads a subtree", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
677
|
-
var parentNode;
|
|
678
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
679
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
680
|
-
case 0:
|
|
681
|
-
parentNode = given.$tree.tree("getNodeByNameMustExist", "initial1");
|
|
682
|
-
given.$tree.tree("loadDataFromUrl", "/tree/", parentNode);
|
|
683
|
-
_context2.next = 4;
|
|
684
|
-
return _dom.screen.findByText("new1");
|
|
685
|
-
case 4:
|
|
686
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
687
|
-
name: "initial1",
|
|
688
|
-
children: [expect.objectContaining({
|
|
689
|
-
name: "new1"
|
|
690
|
-
}), expect.objectContaining({
|
|
691
|
-
name: "new2"
|
|
692
|
-
})]
|
|
693
|
-
}), expect.objectContaining({
|
|
694
|
-
name: "initial2"
|
|
695
|
-
})]);
|
|
696
|
-
case 5:
|
|
697
|
-
case "end":
|
|
698
|
-
return _context2.stop();
|
|
699
|
-
}
|
|
700
|
-
}, _callee2);
|
|
701
|
-
})));
|
|
702
|
-
});
|
|
703
|
-
});
|
|
704
|
-
context("without url parameter", function () {
|
|
705
|
-
it("loads the data from dataUrl", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
706
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
707
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
708
|
-
case 0:
|
|
709
|
-
given.$tree.tree("setOption", "dataUrl", "/tree/");
|
|
710
|
-
given.$tree.tree("loadDataFromUrl");
|
|
711
|
-
_context3.next = 4;
|
|
712
|
-
return _dom.screen.findByText("node1");
|
|
713
|
-
case 4:
|
|
714
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
715
|
-
name: "node1"
|
|
716
|
-
}), expect.objectContaining({
|
|
717
|
-
name: "node2"
|
|
718
|
-
})]);
|
|
719
|
-
case 5:
|
|
720
|
-
case "end":
|
|
721
|
-
return _context3.stop();
|
|
722
|
-
}
|
|
723
|
-
}, _callee3);
|
|
724
|
-
})));
|
|
725
|
-
});
|
|
726
|
-
});
|
|
727
|
-
describe("moveDown", function () {
|
|
728
|
-
var given = (0, _givens["default"])();
|
|
729
|
-
given("node1", function () {
|
|
730
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
731
|
-
});
|
|
732
|
-
given("$tree", function () {
|
|
733
|
-
return $("#tree1");
|
|
734
|
-
});
|
|
735
|
-
beforeEach(function () {
|
|
736
|
-
given.$tree.tree({
|
|
737
|
-
data: _exampleData["default"]
|
|
738
|
-
});
|
|
739
|
-
given.$tree.tree("selectNode", given.node1);
|
|
740
|
-
});
|
|
741
|
-
it("selects the next node", function () {
|
|
742
|
-
given.$tree.tree("moveDown");
|
|
743
|
-
expect(given.$tree.tree("getSelectedNode")).toMatchObject({
|
|
744
|
-
name: "node2"
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
|
-
});
|
|
748
|
-
describe("moveNode", function () {
|
|
749
|
-
var given = (0, _givens["default"])();
|
|
750
|
-
given("child1", function () {
|
|
751
|
-
return given.$tree.tree("getNodeByNameMustExist", "child1");
|
|
752
|
-
});
|
|
753
|
-
given("node2", function () {
|
|
754
|
-
return given.$tree.tree("getNodeByNameMustExist", "node2");
|
|
755
|
-
});
|
|
756
|
-
given("$tree", function () {
|
|
757
|
-
return $("#tree1");
|
|
758
|
-
});
|
|
759
|
-
beforeEach(function () {
|
|
760
|
-
given.$tree.tree({
|
|
761
|
-
autoOpen: true,
|
|
762
|
-
data: _exampleData["default"]
|
|
763
|
-
});
|
|
764
|
-
given.$tree.tree("moveNode", given.child1, given.node2, "after");
|
|
765
|
-
});
|
|
766
|
-
it("moves node", function () {
|
|
767
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
768
|
-
name: "node1",
|
|
769
|
-
children: [expect.objectContaining({
|
|
770
|
-
name: "child2"
|
|
771
|
-
})]
|
|
772
|
-
}), expect.objectContaining({
|
|
773
|
-
name: "node2"
|
|
774
|
-
}), expect.objectContaining({
|
|
775
|
-
name: "child1"
|
|
776
|
-
})]);
|
|
777
|
-
});
|
|
778
|
-
});
|
|
779
|
-
describe("moveUp", function () {
|
|
780
|
-
var given = (0, _givens["default"])();
|
|
781
|
-
given("node2", function () {
|
|
782
|
-
return given.$tree.tree("getNodeByNameMustExist", "node2");
|
|
783
|
-
});
|
|
784
|
-
given("$tree", function () {
|
|
785
|
-
return $("#tree1");
|
|
786
|
-
});
|
|
787
|
-
beforeEach(function () {
|
|
788
|
-
given.$tree.tree({
|
|
789
|
-
data: _exampleData["default"]
|
|
790
|
-
});
|
|
791
|
-
given.$tree.tree("selectNode", given.node2);
|
|
792
|
-
});
|
|
793
|
-
it("selects the next node", function () {
|
|
794
|
-
given.$tree.tree("moveUp");
|
|
795
|
-
expect(given.$tree.tree("getSelectedNode")).toMatchObject({
|
|
796
|
-
name: "node1"
|
|
797
|
-
});
|
|
798
|
-
});
|
|
799
|
-
});
|
|
800
|
-
describe("openNode", function () {
|
|
801
|
-
var given = (0, _givens["default"])();
|
|
802
|
-
given("node1", function () {
|
|
803
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
804
|
-
});
|
|
805
|
-
given("$tree", function () {
|
|
806
|
-
return $("#tree1");
|
|
807
|
-
});
|
|
808
|
-
beforeEach(function () {
|
|
809
|
-
given.$tree.tree({
|
|
810
|
-
autoOpen: false,
|
|
811
|
-
data: _exampleData["default"]
|
|
812
|
-
});
|
|
813
|
-
});
|
|
814
|
-
it("opens the node", function () {
|
|
815
|
-
given.$tree.tree("openNode", given.node1, false);
|
|
816
|
-
expect(given.node1.element).toBeOpen();
|
|
817
|
-
});
|
|
818
|
-
context("with onFinished parameter", function () {
|
|
819
|
-
it("calls the function", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
820
|
-
var onFinished;
|
|
821
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
822
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
823
|
-
case 0:
|
|
824
|
-
onFinished = jest.fn();
|
|
825
|
-
given.$tree.tree("openNode", given.node1, onFinished);
|
|
826
|
-
_context4.next = 4;
|
|
827
|
-
return (0, _dom.waitFor)(function () {
|
|
828
|
-
expect(onFinished).toHaveBeenCalledWith(given.node1);
|
|
829
|
-
});
|
|
830
|
-
case 4:
|
|
831
|
-
case "end":
|
|
832
|
-
return _context4.stop();
|
|
833
|
-
}
|
|
834
|
-
}, _callee4);
|
|
835
|
-
})));
|
|
836
|
-
});
|
|
837
|
-
});
|
|
838
|
-
describe("prependNode", function () {
|
|
839
|
-
var given = (0, _givens["default"])();
|
|
840
|
-
given("$tree", function () {
|
|
841
|
-
return $("#tree1");
|
|
842
|
-
});
|
|
843
|
-
given("parent", function () {
|
|
844
|
-
return undefined;
|
|
845
|
-
});
|
|
846
|
-
beforeEach(function () {
|
|
847
|
-
given.$tree.tree({
|
|
848
|
-
data: _exampleData["default"]
|
|
849
|
-
});
|
|
850
|
-
given.$tree.tree("prependNode", "prepended-node", given.parent);
|
|
851
|
-
});
|
|
852
|
-
context("with an empty parent parameter", function () {
|
|
853
|
-
it("prepends the node to the tree", function () {
|
|
854
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
855
|
-
name: "prepended-node"
|
|
856
|
-
}), expect.objectContaining({
|
|
857
|
-
name: "node1"
|
|
858
|
-
}), expect.objectContaining({
|
|
859
|
-
name: "node2"
|
|
860
|
-
})]);
|
|
861
|
-
});
|
|
862
|
-
});
|
|
863
|
-
context("with a parent node", function () {
|
|
864
|
-
given("parent", function () {
|
|
865
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
866
|
-
});
|
|
867
|
-
it("prepends the node to the parent", function () {
|
|
868
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
869
|
-
name: "node1",
|
|
870
|
-
children: [expect.objectContaining({
|
|
871
|
-
name: "prepended-node"
|
|
872
|
-
}), expect.objectContaining({
|
|
873
|
-
name: "child1"
|
|
874
|
-
}), expect.objectContaining({
|
|
875
|
-
name: "child2"
|
|
876
|
-
})]
|
|
877
|
-
}), expect.objectContaining({
|
|
878
|
-
name: "node2"
|
|
879
|
-
})]);
|
|
880
|
-
});
|
|
881
|
-
});
|
|
882
|
-
});
|
|
883
|
-
describe("refresh", function () {
|
|
884
|
-
var given = (0, _givens["default"])();
|
|
885
|
-
given("$tree", function () {
|
|
886
|
-
return $("#tree1");
|
|
887
|
-
});
|
|
888
|
-
beforeEach(function () {
|
|
889
|
-
given.$tree.tree({
|
|
890
|
-
data: _exampleData["default"]
|
|
891
|
-
});
|
|
892
|
-
});
|
|
893
|
-
it("rerenders the tree", function () {
|
|
894
|
-
var tree = given.$tree.tree("getTree");
|
|
895
|
-
tree.children[0].name = "node1a"; // eslint-disable-line testing-library/no-node-access
|
|
896
|
-
|
|
897
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
898
|
-
name: "node1"
|
|
899
|
-
}), expect.objectContaining({
|
|
900
|
-
name: "node2"
|
|
901
|
-
})]);
|
|
902
|
-
given.$tree.tree("refresh");
|
|
903
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
904
|
-
name: "node1a"
|
|
905
|
-
}), expect.objectContaining({
|
|
906
|
-
name: "node2"
|
|
907
|
-
})]);
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
describe("reload", function () {
|
|
911
|
-
var given = (0, _givens["default"])();
|
|
912
|
-
given("node1", function () {
|
|
913
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
914
|
-
});
|
|
915
|
-
given("$tree", function () {
|
|
916
|
-
return $("#tree1");
|
|
917
|
-
});
|
|
918
|
-
beforeEach( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
919
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
920
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
921
|
-
case 0:
|
|
922
|
-
server.use(_msw.rest.get("/tree2/", function (_request, response, ctx) {
|
|
923
|
-
return response(ctx.status(200), ctx.json(_exampleData["default"]));
|
|
924
|
-
}));
|
|
925
|
-
given.$tree.tree({
|
|
926
|
-
dataUrl: "/tree2/"
|
|
927
|
-
});
|
|
928
|
-
_context5.next = 4;
|
|
929
|
-
return _dom.screen.findByText("node1");
|
|
930
|
-
case 4:
|
|
931
|
-
given.$tree.tree("removeNode", given.node1);
|
|
932
|
-
case 5:
|
|
933
|
-
case "end":
|
|
934
|
-
return _context5.stop();
|
|
935
|
-
}
|
|
936
|
-
}, _callee5);
|
|
937
|
-
})));
|
|
938
|
-
it("reloads the data from the server", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
939
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
940
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
941
|
-
case 0:
|
|
942
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
943
|
-
name: "node2"
|
|
944
|
-
})]);
|
|
945
|
-
given.$tree.tree("reload");
|
|
946
|
-
_context6.next = 4;
|
|
947
|
-
return _dom.screen.findByText("node1");
|
|
948
|
-
case 4:
|
|
949
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
950
|
-
name: "node1"
|
|
951
|
-
}), expect.objectContaining({
|
|
952
|
-
name: "node2"
|
|
953
|
-
})]);
|
|
954
|
-
case 5:
|
|
955
|
-
case "end":
|
|
956
|
-
return _context6.stop();
|
|
957
|
-
}
|
|
958
|
-
}, _callee6);
|
|
959
|
-
})));
|
|
960
|
-
context("with a onFinished parameter", function () {
|
|
961
|
-
it("calls onFinished", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
962
|
-
var handleFinished;
|
|
963
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
964
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
965
|
-
case 0:
|
|
966
|
-
handleFinished = jest.fn();
|
|
967
|
-
given.$tree.tree("reload", handleFinished);
|
|
968
|
-
_context7.next = 4;
|
|
969
|
-
return (0, _dom.waitFor)(function () {
|
|
970
|
-
return expect(handleFinished).toHaveBeenCalledWith();
|
|
971
|
-
});
|
|
972
|
-
case 4:
|
|
973
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
974
|
-
name: "node1"
|
|
975
|
-
}), expect.objectContaining({
|
|
976
|
-
name: "node2"
|
|
977
|
-
})]);
|
|
978
|
-
case 5:
|
|
979
|
-
case "end":
|
|
980
|
-
return _context7.stop();
|
|
981
|
-
}
|
|
982
|
-
}, _callee7);
|
|
983
|
-
})));
|
|
984
|
-
});
|
|
985
|
-
});
|
|
986
|
-
describe("removeNode", function () {
|
|
987
|
-
var given = (0, _givens["default"])();
|
|
988
|
-
given("$tree", function () {
|
|
989
|
-
return $("#tree1");
|
|
990
|
-
});
|
|
991
|
-
beforeEach(function () {
|
|
992
|
-
given.$tree.tree({
|
|
993
|
-
data: _exampleData["default"]
|
|
994
|
-
});
|
|
995
|
-
});
|
|
996
|
-
context("with a child node", function () {
|
|
997
|
-
given("node", function () {
|
|
998
|
-
return given.$tree.tree("getNodeByNameMustExist", "child1");
|
|
999
|
-
});
|
|
1000
|
-
it("removes the node", function () {
|
|
1001
|
-
given.$tree.tree("removeNode", given.node);
|
|
1002
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1003
|
-
name: "node1",
|
|
1004
|
-
children: [expect.objectContaining({
|
|
1005
|
-
name: "child2"
|
|
1006
|
-
})]
|
|
1007
|
-
}), expect.objectContaining({
|
|
1008
|
-
name: "node2",
|
|
1009
|
-
children: [expect.objectContaining({
|
|
1010
|
-
name: "node3"
|
|
1011
|
-
})]
|
|
1012
|
-
})]);
|
|
1013
|
-
});
|
|
1014
|
-
context("when the node is selected", function () {
|
|
1015
|
-
beforeEach(function () {
|
|
1016
|
-
given.$tree.tree("selectNode", given.node);
|
|
1017
|
-
});
|
|
1018
|
-
it("removes and deselects the node", function () {
|
|
1019
|
-
given.$tree.tree("removeNode", given.node);
|
|
1020
|
-
expect(given.$tree.tree("getSelectedNode")).toBe(false);
|
|
1021
|
-
});
|
|
1022
|
-
});
|
|
1023
|
-
});
|
|
1024
|
-
context("with a parent node and its children", function () {
|
|
1025
|
-
given("node", function () {
|
|
1026
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
1027
|
-
});
|
|
1028
|
-
it("removes the node", function () {
|
|
1029
|
-
given.$tree.tree("removeNode", given.node);
|
|
1030
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1031
|
-
name: "node2",
|
|
1032
|
-
children: [expect.objectContaining({
|
|
1033
|
-
name: "node3"
|
|
1034
|
-
})]
|
|
1035
|
-
})]);
|
|
1036
|
-
});
|
|
1037
|
-
context("when a child node is selected", function () {
|
|
1038
|
-
beforeEach(function () {
|
|
1039
|
-
var child1 = given.$tree.tree("getNodeByNameMustExist", "child1");
|
|
1040
|
-
given.$tree.tree("selectNode", child1);
|
|
1041
|
-
});
|
|
1042
|
-
it("removes the node and deselects the child", function () {
|
|
1043
|
-
given.$tree.tree("removeNode", given.node);
|
|
1044
|
-
expect(given.$tree.tree("getSelectedNode")).toBe(false);
|
|
1045
|
-
});
|
|
1046
|
-
});
|
|
1047
|
-
});
|
|
1048
|
-
context("with a root node", function () {
|
|
1049
|
-
given("node", function () {
|
|
1050
|
-
return given.$tree.tree("getTree");
|
|
1051
|
-
});
|
|
1052
|
-
it("raises an exception", function () {
|
|
1053
|
-
expect(function () {
|
|
1054
|
-
return given.$tree.tree("removeNode", given.node);
|
|
1055
|
-
}).toThrow("Node has no parent");
|
|
1056
|
-
});
|
|
1057
|
-
});
|
|
1058
|
-
});
|
|
1059
|
-
describe("selectNode", function () {
|
|
1060
|
-
var given = (0, _givens["default"])();
|
|
1061
|
-
given("node1", function () {
|
|
1062
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
1063
|
-
});
|
|
1064
|
-
given("node2", function () {
|
|
1065
|
-
return given.$tree.tree("getNodeByNameMustExist", "node2");
|
|
1066
|
-
});
|
|
1067
|
-
given("$tree", function () {
|
|
1068
|
-
return $("#tree1");
|
|
1069
|
-
});
|
|
1070
|
-
beforeEach(function () {
|
|
1071
|
-
given.$tree.tree({
|
|
1072
|
-
data: _exampleData["default"],
|
|
1073
|
-
selectable: true
|
|
1074
|
-
});
|
|
1075
|
-
});
|
|
1076
|
-
context("when another node is selected", function () {
|
|
1077
|
-
beforeEach(function () {
|
|
1078
|
-
given.$tree.tree("selectNode", given.node2);
|
|
1079
|
-
given.$tree.tree("selectNode", given.node1);
|
|
1080
|
-
});
|
|
1081
|
-
it("selects the node and deselects the previous node", function () {
|
|
1082
|
-
expect(given.node1.element).toBeSelected();
|
|
1083
|
-
expect(given.node2.element).not.toBeSelected();
|
|
1084
|
-
});
|
|
1085
|
-
});
|
|
1086
|
-
context("when the node is not selected", function () {
|
|
1087
|
-
beforeEach(function () {
|
|
1088
|
-
given.$tree.tree("selectNode", given.node1);
|
|
1089
|
-
});
|
|
1090
|
-
it("selects the node", function () {
|
|
1091
|
-
expect(given.node1.element).toBeSelected();
|
|
1092
|
-
});
|
|
1093
|
-
});
|
|
1094
|
-
context("when the node is selected", function () {
|
|
1095
|
-
beforeEach(function () {
|
|
1096
|
-
given.$tree.tree("selectNode", given.node1);
|
|
1097
|
-
});
|
|
1098
|
-
it("deselects the node", function () {
|
|
1099
|
-
given.$tree.tree("selectNode", given.node1);
|
|
1100
|
-
expect(given.node1.element).not.toBeSelected();
|
|
1101
|
-
});
|
|
1102
|
-
});
|
|
1103
|
-
context("with a null parameter", function () {
|
|
1104
|
-
beforeEach(function () {
|
|
1105
|
-
given.$tree.tree("selectNode", given.node1);
|
|
1106
|
-
});
|
|
1107
|
-
it("deselects the current node", function () {
|
|
1108
|
-
given.$tree.tree("selectNode", null);
|
|
1109
|
-
expect(given.$tree.tree("getSelectedNode")).toBeFalse();
|
|
1110
|
-
});
|
|
1111
|
-
});
|
|
1112
|
-
});
|
|
1113
|
-
describe("setOption", function () {
|
|
1114
|
-
var given = (0, _givens["default"])();
|
|
1115
|
-
beforeEach(function () {
|
|
1116
|
-
given.$tree.tree({
|
|
1117
|
-
animationSpeed: 0,
|
|
1118
|
-
data: _exampleData["default"],
|
|
1119
|
-
selectable: false
|
|
1120
|
-
});
|
|
1121
|
-
});
|
|
1122
|
-
given("node1", function () {
|
|
1123
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
1124
|
-
});
|
|
1125
|
-
given("$tree", function () {
|
|
1126
|
-
return $("#tree1");
|
|
1127
|
-
});
|
|
1128
|
-
it("sets an option", function () {
|
|
1129
|
-
given.$tree.tree("setOption", "selectable", true);
|
|
1130
|
-
(0, _testUtil.titleSpan)(given.node1.element).trigger("click");
|
|
1131
|
-
expect(given.$tree.tree("getSelectedNode")).toMatchObject({
|
|
1132
|
-
name: "node1"
|
|
1133
|
-
});
|
|
1134
|
-
});
|
|
1135
|
-
});
|
|
1136
|
-
describe("setState", function () {
|
|
1137
|
-
var given = (0, _givens["default"])();
|
|
1138
|
-
beforeEach(function () {
|
|
1139
|
-
given.$tree.tree({
|
|
1140
|
-
autoOpen: false,
|
|
1141
|
-
data: _exampleData["default"],
|
|
1142
|
-
selectable: true
|
|
1143
|
-
});
|
|
1144
|
-
});
|
|
1145
|
-
given("$tree", function () {
|
|
1146
|
-
return $("#tree1");
|
|
1147
|
-
});
|
|
1148
|
-
it("sets the state", function () {
|
|
1149
|
-
given.$tree.tree("setState", {
|
|
1150
|
-
open_nodes: [123],
|
|
1151
|
-
selected_node: [123]
|
|
1152
|
-
});
|
|
1153
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1154
|
-
name: "node1",
|
|
1155
|
-
open: true,
|
|
1156
|
-
selected: true
|
|
1157
|
-
}), expect.objectContaining({
|
|
1158
|
-
name: "node2",
|
|
1159
|
-
open: false,
|
|
1160
|
-
selected: false
|
|
1161
|
-
})]);
|
|
1162
|
-
});
|
|
1163
|
-
});
|
|
1164
|
-
describe("toggle", function () {
|
|
1165
|
-
var given = (0, _givens["default"])();
|
|
1166
|
-
given("autoOpen", function () {
|
|
1167
|
-
return false;
|
|
1168
|
-
});
|
|
1169
|
-
given("node1", function () {
|
|
1170
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
1171
|
-
});
|
|
1172
|
-
given("$tree", function () {
|
|
1173
|
-
return $("#tree1");
|
|
1174
|
-
});
|
|
1175
|
-
beforeEach(function () {
|
|
1176
|
-
given.$tree.tree({
|
|
1177
|
-
autoOpen: given.autoOpen,
|
|
1178
|
-
data: _exampleData["default"]
|
|
1179
|
-
});
|
|
1180
|
-
given.$tree.tree("toggle", given.node1, false);
|
|
1181
|
-
});
|
|
1182
|
-
context("when the node is closed", function () {
|
|
1183
|
-
it("opens the node", function () {
|
|
1184
|
-
expect(given.node1.element).toBeOpen();
|
|
1185
|
-
});
|
|
1186
|
-
});
|
|
1187
|
-
context("when the node is open", function () {
|
|
1188
|
-
given("autoOpen", function () {
|
|
1189
|
-
return true;
|
|
1190
|
-
});
|
|
1191
|
-
it("closes the node", function () {
|
|
1192
|
-
expect(given.node1.element).toBeClosed();
|
|
1193
|
-
});
|
|
1194
|
-
});
|
|
1195
|
-
});
|
|
1196
|
-
describe("toJson", function () {
|
|
1197
|
-
var given = (0, _givens["default"])();
|
|
1198
|
-
given("$tree", function () {
|
|
1199
|
-
return $("#tree1");
|
|
1200
|
-
});
|
|
1201
|
-
beforeEach(function () {
|
|
1202
|
-
given.$tree.tree({
|
|
1203
|
-
data: _exampleData["default"]
|
|
1204
|
-
});
|
|
1205
|
-
});
|
|
1206
|
-
it("returns nodes as json", function () {
|
|
1207
|
-
expect(JSON.parse(given.$tree.tree("toJson"))).toEqual(_exampleData["default"]);
|
|
1208
|
-
});
|
|
1209
|
-
});
|
|
1210
|
-
describe("updateNode", function () {
|
|
1211
|
-
var given = (0, _givens["default"])();
|
|
1212
|
-
given("isSelected", function () {
|
|
1213
|
-
return false;
|
|
1214
|
-
});
|
|
1215
|
-
given("node", function () {
|
|
1216
|
-
return given.$tree.tree("getNodeByNameMustExist", "node1");
|
|
1217
|
-
});
|
|
1218
|
-
given("$tree", function () {
|
|
1219
|
-
return $("#tree1");
|
|
1220
|
-
});
|
|
1221
|
-
beforeEach(function () {
|
|
1222
|
-
given.$tree.tree({
|
|
1223
|
-
autoOpen: true,
|
|
1224
|
-
data: _exampleData["default"]
|
|
1225
|
-
});
|
|
1226
|
-
if (given.isSelected) {
|
|
1227
|
-
given.$tree.tree("selectNode", given.node);
|
|
1228
|
-
}
|
|
1229
|
-
given.$tree.tree("updateNode", given.node, given.nodeData);
|
|
1230
|
-
});
|
|
1231
|
-
context("with a string", function () {
|
|
1232
|
-
given("nodeData", function () {
|
|
1233
|
-
return "updated-node";
|
|
1234
|
-
});
|
|
1235
|
-
it("updates the name", function () {
|
|
1236
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1237
|
-
name: "updated-node"
|
|
1238
|
-
}), expect.objectContaining({
|
|
1239
|
-
name: "node2"
|
|
1240
|
-
})]);
|
|
1241
|
-
});
|
|
1242
|
-
});
|
|
1243
|
-
context("with an object containing a name", function () {
|
|
1244
|
-
given("nodeData", function () {
|
|
1245
|
-
return {
|
|
1246
|
-
name: "updated-node"
|
|
1247
|
-
};
|
|
1248
|
-
});
|
|
1249
|
-
it("updates the name", function () {
|
|
1250
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1251
|
-
name: "updated-node"
|
|
1252
|
-
}), expect.objectContaining({
|
|
1253
|
-
name: "node2"
|
|
1254
|
-
})]);
|
|
1255
|
-
});
|
|
1256
|
-
});
|
|
1257
|
-
context("with an object containing an id", function () {
|
|
1258
|
-
given("nodeData", function () {
|
|
1259
|
-
return {
|
|
1260
|
-
id: 999
|
|
1261
|
-
};
|
|
1262
|
-
});
|
|
1263
|
-
it("updates the id", function () {
|
|
1264
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1265
|
-
name: "node1"
|
|
1266
|
-
}), expect.objectContaining({
|
|
1267
|
-
name: "node2"
|
|
1268
|
-
})]);
|
|
1269
|
-
expect(given.$tree.tree("getNodeById", 999)).toMatchObject(given.nodeData);
|
|
1270
|
-
});
|
|
1271
|
-
});
|
|
1272
|
-
context("with an object containing a property", function () {
|
|
1273
|
-
given("nodeData", function () {
|
|
1274
|
-
return {
|
|
1275
|
-
color: "green"
|
|
1276
|
-
};
|
|
1277
|
-
});
|
|
1278
|
-
it("updates the node", function () {
|
|
1279
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1280
|
-
name: "node1"
|
|
1281
|
-
}), expect.objectContaining({
|
|
1282
|
-
name: "node2"
|
|
1283
|
-
})]);
|
|
1284
|
-
expect(given.$tree.tree("getNodeById", 123)).toMatchObject({
|
|
1285
|
-
color: "green",
|
|
1286
|
-
name: "node1"
|
|
1287
|
-
});
|
|
1288
|
-
});
|
|
1289
|
-
});
|
|
1290
|
-
context("with an object containing children", function () {
|
|
1291
|
-
context("when adding a child to a child node", function () {
|
|
1292
|
-
given("nodeData", function () {
|
|
1293
|
-
return {
|
|
1294
|
-
children: ["new-child"]
|
|
1295
|
-
};
|
|
1296
|
-
});
|
|
1297
|
-
given("node", function () {
|
|
1298
|
-
return given.$tree.tree("getNodeByNameMustExist", "child1");
|
|
1299
|
-
});
|
|
1300
|
-
it("adds the child node", function () {
|
|
1301
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1302
|
-
name: "node1",
|
|
1303
|
-
children: [expect.objectContaining({
|
|
1304
|
-
name: "child1",
|
|
1305
|
-
children: [expect.objectContaining({
|
|
1306
|
-
name: "new-child"
|
|
1307
|
-
})]
|
|
1308
|
-
}), expect.objectContaining({
|
|
1309
|
-
name: "child2"
|
|
1310
|
-
})]
|
|
1311
|
-
}), expect.objectContaining({
|
|
1312
|
-
name: "node2"
|
|
1313
|
-
})]);
|
|
1314
|
-
});
|
|
1315
|
-
});
|
|
1316
|
-
context("when removing the children", function () {
|
|
1317
|
-
given("nodeData", function () {
|
|
1318
|
-
return {
|
|
1319
|
-
children: []
|
|
1320
|
-
};
|
|
1321
|
-
});
|
|
1322
|
-
it("removes the children", function () {
|
|
1323
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1324
|
-
nodeType: "child",
|
|
1325
|
-
name: "node1"
|
|
1326
|
-
}), expect.objectContaining({
|
|
1327
|
-
nodeType: "folder",
|
|
1328
|
-
name: "node2"
|
|
1329
|
-
})]);
|
|
1330
|
-
});
|
|
1331
|
-
});
|
|
1332
|
-
});
|
|
1333
|
-
context("when the node was selected", function () {
|
|
1334
|
-
given("isSelected", function () {
|
|
1335
|
-
return true;
|
|
1336
|
-
});
|
|
1337
|
-
it("keeps the node selected", function () {
|
|
1338
|
-
expect(given.$tree).toHaveTreeStructure([expect.objectContaining({
|
|
1339
|
-
name: "node1"
|
|
1340
|
-
}), expect.objectContaining({
|
|
1341
|
-
name: "node2"
|
|
1342
|
-
})]);
|
|
1343
|
-
});
|
|
1344
|
-
it("keeps the focus on the node", function () {
|
|
1345
|
-
expect(given.node.element).toBeFocused();
|
|
1346
|
-
});
|
|
1347
|
-
});
|
|
1348
|
-
});
|