jqtree 1.7.5 → 1.8.1
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/.eslintrc +13 -3
- package/.github/workflows/ci.yml +6 -6
- package/.github/workflows/codeql-analysis.yml +4 -4
- package/.github/workflows/size.yml +3 -3
- package/.github/workflows/static.yml +1 -1
- package/bower.json +1 -1
- package/config/babel.config.json +1 -1
- package/config/jest.config.js +4 -0
- package/config/jest.polyfills.js +14 -0
- package/config/production +2 -0
- package/devserver/devserver_scroll.js +8 -0
- package/devserver/test_index.html +9 -0
- package/devserver/test_scroll.html +28 -0
- package/devserver/test_scroll_container.html +39 -0
- package/docs/.ruby-version +1 -1
- package/docs/_config.yml +1 -1
- package/docs/_entries/general/changelog.md +11 -0
- package/docs/_entries/multiple_selection/get-selected-nodes.md +1 -1
- package/docs/_entries/node/getnextnode.md +3 -6
- package/docs/_entries/node/getnextsibling.md +1 -1
- package/docs/_entries/node/getnextvisiblenode.md +8 -5
- package/docs/_entries/node/getpreviousnode.md +12 -0
- package/docs/_entries/node/getprevioussibling.md +1 -1
- package/docs/_entries/node/getpreviousvisiblenode.md +6 -5
- package/package.json +35 -29
- package/src/dataLoader.ts +57 -34
- package/src/dragAndDropHandler/dragElement.ts +54 -0
- package/src/dragAndDropHandler/generateHitAreas.ts +176 -0
- package/src/dragAndDropHandler/index.ts +454 -0
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +91 -0
- package/src/dragAndDropHandler/types.ts +13 -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/mouseHandler.ts +385 -0
- package/src/mouseUtils.ts +23 -0
- package/src/node.ts +1 -29
- package/src/nodeElement/borderDropHint.ts +32 -0
- package/src/nodeElement/folderElement.ts +133 -0
- package/src/nodeElement/ghostDropHint.ts +69 -0
- package/src/nodeElement/index.ts +102 -0
- package/src/playwright/coverage.ts +4 -7
- package/src/playwright/playwright.test.ts +150 -53
- package/src/playwright/testUtils.ts +28 -5
- package/src/position.ts +28 -0
- package/src/saveStateHandler.ts +75 -26
- package/src/scrollHandler/containerScrollParent.ts +13 -23
- package/src/scrollHandler/createScrollParent.ts +22 -22
- package/src/scrollHandler/documentScrollParent.ts +16 -13
- package/src/scrollHandler.ts +13 -15
- package/src/selectNodeHandler.ts +10 -16
- package/src/test/jqTree/events.test.ts +97 -30
- package/src/test/jqTree/keyboard.test.ts +18 -23
- package/src/test/jqTree/loadOnDemand.test.ts +22 -15
- package/src/test/jqTree/methods.test.ts +40 -14
- package/src/test/jqTree/mouse.test.ts +82 -0
- package/src/test/jqTree/options.test.ts +24 -12
- package/src/test/node.test.ts +3 -2
- package/src/test/{nodeUtil.test.ts → position.test.ts} +1 -1
- package/src/tree.jquery.ts +314 -208
- package/src/util.ts +12 -0
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +2594 -3419
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +3 -3
- package/tree.jquery.js.map +1 -1
- package/tsconfig.json +5 -3
- package/docs/_entries/functions/get-selected-nodes.md +0 -10
- 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/mouse.widget.ts +0 -266
- package/src/nodeElement.ts +0 -272
- package/src/types.ts +0 -19
package/lib/test/node.test.js
DELETED
|
@@ -1,1202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _givens = _interopRequireDefault(require("givens"));
|
|
4
|
-
var _node = require("../node");
|
|
5
|
-
var _exampleData = _interopRequireDefault(require("./support/exampleData"));
|
|
6
|
-
require("jest-extended");
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
|
-
var context = describe;
|
|
9
|
-
describe("addAfter", function () {
|
|
10
|
-
var given = (0, _givens["default"])();
|
|
11
|
-
given("node1", function () {
|
|
12
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
13
|
-
});
|
|
14
|
-
given("tree", function () {
|
|
15
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
16
|
-
});
|
|
17
|
-
context("when moving after node1", function () {
|
|
18
|
-
it("returns the new node", function () {
|
|
19
|
-
expect(given.node1.addAfter("new node")).toMatchObject({
|
|
20
|
-
name: "new node"
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
it("adds after the node", function () {
|
|
24
|
-
given.node1.addAfter("new node");
|
|
25
|
-
expect(given.tree).toMatchObject({
|
|
26
|
-
children: [expect.objectContaining({
|
|
27
|
-
name: "node1"
|
|
28
|
-
}), expect.objectContaining({
|
|
29
|
-
name: "new node"
|
|
30
|
-
}), expect.objectContaining({
|
|
31
|
-
name: "node2"
|
|
32
|
-
})]
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
context("when moving after the root node", function () {
|
|
37
|
-
it("returns null", function () {
|
|
38
|
-
expect(given.tree.addAfter("new node")).toBeNull();
|
|
39
|
-
});
|
|
40
|
-
it("doesn't add anything", function () {
|
|
41
|
-
expect(given.tree).toMatchObject({
|
|
42
|
-
children: [expect.objectContaining({
|
|
43
|
-
name: "node1"
|
|
44
|
-
}), expect.objectContaining({
|
|
45
|
-
name: "node2"
|
|
46
|
-
})]
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
context("when adding a node with children", function () {
|
|
51
|
-
it("adds the children", function () {
|
|
52
|
-
given.node1.addAfter({
|
|
53
|
-
name: "new node",
|
|
54
|
-
children: ["newchild1", "newchild2"]
|
|
55
|
-
});
|
|
56
|
-
expect(given.tree).toMatchObject({
|
|
57
|
-
children: [expect.objectContaining({
|
|
58
|
-
name: "node1"
|
|
59
|
-
}), expect.objectContaining({
|
|
60
|
-
name: "new node",
|
|
61
|
-
children: [expect.objectContaining({
|
|
62
|
-
name: "newchild1"
|
|
63
|
-
}), expect.objectContaining({
|
|
64
|
-
name: "newchild2"
|
|
65
|
-
})]
|
|
66
|
-
}), expect.objectContaining({
|
|
67
|
-
name: "node2"
|
|
68
|
-
})]
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe("addBefore", function () {
|
|
74
|
-
var given = (0, _givens["default"])();
|
|
75
|
-
given("node2", function () {
|
|
76
|
-
return given.tree.getNodeByNameMustExist("node2");
|
|
77
|
-
});
|
|
78
|
-
given("tree", function () {
|
|
79
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
80
|
-
});
|
|
81
|
-
it("returns the new node", function () {
|
|
82
|
-
expect(given.node2.addBefore("new node")).toMatchObject({
|
|
83
|
-
name: "new node"
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
it("adds before the node", function () {
|
|
87
|
-
given.node2.addBefore("new node");
|
|
88
|
-
expect(given.tree).toMatchObject({
|
|
89
|
-
children: [expect.objectContaining({
|
|
90
|
-
name: "node1"
|
|
91
|
-
}), expect.objectContaining({
|
|
92
|
-
name: "new node"
|
|
93
|
-
}), expect.objectContaining({
|
|
94
|
-
name: "node2"
|
|
95
|
-
})]
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
context("with a root node", function () {
|
|
99
|
-
it("returns null", function () {
|
|
100
|
-
expect(given.tree.addBefore("new node")).toBeNull();
|
|
101
|
-
});
|
|
102
|
-
it("does nothing", function () {
|
|
103
|
-
given.tree.addBefore("new node");
|
|
104
|
-
expect(given.tree).toMatchObject({
|
|
105
|
-
children: [expect.objectContaining({
|
|
106
|
-
name: "node1"
|
|
107
|
-
}), expect.objectContaining({
|
|
108
|
-
name: "node2"
|
|
109
|
-
})]
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
context("when adding a node with children", function () {
|
|
114
|
-
it("adds the children", function () {
|
|
115
|
-
given.node2.addBefore({
|
|
116
|
-
name: "new node",
|
|
117
|
-
children: ["newchild1", "newchild2"]
|
|
118
|
-
});
|
|
119
|
-
expect(given.tree).toMatchObject({
|
|
120
|
-
children: [expect.objectContaining({
|
|
121
|
-
name: "node1"
|
|
122
|
-
}), expect.objectContaining({
|
|
123
|
-
name: "new node",
|
|
124
|
-
children: [expect.objectContaining({
|
|
125
|
-
name: "newchild1"
|
|
126
|
-
}), expect.objectContaining({
|
|
127
|
-
name: "newchild2"
|
|
128
|
-
})]
|
|
129
|
-
}), expect.objectContaining({
|
|
130
|
-
name: "node2"
|
|
131
|
-
})]
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe("addChild", function () {
|
|
137
|
-
var given = (0, _givens["default"])();
|
|
138
|
-
given("node", function () {
|
|
139
|
-
return new _node.Node();
|
|
140
|
-
});
|
|
141
|
-
beforeEach(function () {
|
|
142
|
-
given.node.addChild(new _node.Node({
|
|
143
|
-
id: 100,
|
|
144
|
-
name: "child1"
|
|
145
|
-
}));
|
|
146
|
-
});
|
|
147
|
-
it("adds the child", function () {
|
|
148
|
-
expect(given.node.children).toEqual(expect.arrayContaining([expect.objectContaining({
|
|
149
|
-
id: 100,
|
|
150
|
-
name: "child1"
|
|
151
|
-
})]));
|
|
152
|
-
});
|
|
153
|
-
it("sets the parent of the child", function () {
|
|
154
|
-
var _given$node$children$;
|
|
155
|
-
expect((_given$node$children$ = given.node.children[0]) === null || _given$node$children$ === void 0 ? void 0 : _given$node$children$.parent).toEqual(given.node);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe("addChildAtPosition", function () {
|
|
159
|
-
var given = (0, _givens["default"])();
|
|
160
|
-
given("child", function () {
|
|
161
|
-
return new _node.Node("new");
|
|
162
|
-
});
|
|
163
|
-
given("node", function () {
|
|
164
|
-
return new _node.Node("new").loadFromData(["child1", "child2"]);
|
|
165
|
-
});
|
|
166
|
-
beforeEach(function () {
|
|
167
|
-
given.node.addChildAtPosition(given.child, given.index);
|
|
168
|
-
});
|
|
169
|
-
context("with index 0", function () {
|
|
170
|
-
given("index", function () {
|
|
171
|
-
return 0;
|
|
172
|
-
});
|
|
173
|
-
it("adds at the start", function () {
|
|
174
|
-
expect(given.node.children).toEqual([expect.objectContaining({
|
|
175
|
-
name: "new"
|
|
176
|
-
}), expect.objectContaining({
|
|
177
|
-
name: "child1"
|
|
178
|
-
}), expect.objectContaining({
|
|
179
|
-
name: "child2"
|
|
180
|
-
})]);
|
|
181
|
-
expect(given.node.children).toEqual([expect.objectContaining({
|
|
182
|
-
name: "new"
|
|
183
|
-
}), expect.objectContaining({
|
|
184
|
-
name: "child1"
|
|
185
|
-
}), expect.objectContaining({
|
|
186
|
-
name: "child2"
|
|
187
|
-
})]);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
context("with index 1", function () {
|
|
191
|
-
given("index", function () {
|
|
192
|
-
return 1;
|
|
193
|
-
});
|
|
194
|
-
it("inserts at index 1", function () {
|
|
195
|
-
expect(given.node.children).toEqual([expect.objectContaining({
|
|
196
|
-
name: "child1"
|
|
197
|
-
}), expect.objectContaining({
|
|
198
|
-
name: "new"
|
|
199
|
-
}), expect.objectContaining({
|
|
200
|
-
name: "child2"
|
|
201
|
-
})]);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
context("with non existing index", function () {
|
|
205
|
-
given("index", function () {
|
|
206
|
-
return 99;
|
|
207
|
-
});
|
|
208
|
-
it("adds add the end", function () {
|
|
209
|
-
expect(given.node.children).toEqual([expect.objectContaining({
|
|
210
|
-
name: "child1"
|
|
211
|
-
}), expect.objectContaining({
|
|
212
|
-
name: "child2"
|
|
213
|
-
}), expect.objectContaining({
|
|
214
|
-
name: "new"
|
|
215
|
-
})]);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
describe("addParent", function () {
|
|
220
|
-
var given = (0, _givens["default"])();
|
|
221
|
-
given("node1", function () {
|
|
222
|
-
return new _node.Node("node1");
|
|
223
|
-
});
|
|
224
|
-
given("tree", function () {
|
|
225
|
-
return new _node.Node({}, true);
|
|
226
|
-
});
|
|
227
|
-
beforeEach(function () {
|
|
228
|
-
given.tree.addChild(given.node1);
|
|
229
|
-
given.node1.append("child1");
|
|
230
|
-
});
|
|
231
|
-
it("adds a parent node", function () {
|
|
232
|
-
given.node1.addParent("parent1");
|
|
233
|
-
expect(given.tree).toMatchObject({
|
|
234
|
-
name: "",
|
|
235
|
-
children: [expect.objectContaining({
|
|
236
|
-
name: "parent1",
|
|
237
|
-
children: [expect.objectContaining({
|
|
238
|
-
name: "node1",
|
|
239
|
-
children: [expect.objectContaining({
|
|
240
|
-
name: "child1"
|
|
241
|
-
})]
|
|
242
|
-
})]
|
|
243
|
-
})]
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
it("returns the new node", function () {
|
|
247
|
-
expect(given.node1.addParent("parent1")).toMatchObject({
|
|
248
|
-
name: "parent1"
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
context("with a root node", function () {
|
|
252
|
-
it("returns null", function () {
|
|
253
|
-
expect(given.tree.addParent("parent1")).toBeNull();
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
describe("append", function () {
|
|
258
|
-
var given = (0, _givens["default"])();
|
|
259
|
-
given("node", function () {
|
|
260
|
-
return new _node.Node("node1");
|
|
261
|
-
});
|
|
262
|
-
it("appends a node", function () {
|
|
263
|
-
given.node.append("child1");
|
|
264
|
-
given.node.append("child2");
|
|
265
|
-
expect(given.node).toMatchObject({
|
|
266
|
-
name: "node1",
|
|
267
|
-
children: [expect.objectContaining({
|
|
268
|
-
name: "child1"
|
|
269
|
-
}), expect.objectContaining({
|
|
270
|
-
name: "child2"
|
|
271
|
-
})]
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
it("returns the new node", function () {
|
|
275
|
-
expect(given.node.append("child1")).toMatchObject({
|
|
276
|
-
name: "child1"
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
context("when adding a node with children", function () {
|
|
280
|
-
it("adds the children", function () {
|
|
281
|
-
given.node.append({
|
|
282
|
-
name: "new node",
|
|
283
|
-
children: ["newchild1", "newchild2"]
|
|
284
|
-
});
|
|
285
|
-
expect(given.node).toMatchObject({
|
|
286
|
-
children: [expect.objectContaining({
|
|
287
|
-
name: "new node",
|
|
288
|
-
children: [expect.objectContaining({
|
|
289
|
-
name: "newchild1"
|
|
290
|
-
}), expect.objectContaining({
|
|
291
|
-
name: "newchild2"
|
|
292
|
-
})]
|
|
293
|
-
})]
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
describe("constructor", function () {
|
|
299
|
-
var given = (0, _givens["default"])();
|
|
300
|
-
given("node", function () {
|
|
301
|
-
return given.params === undefined ? new _node.Node() : new _node.Node(given.params);
|
|
302
|
-
});
|
|
303
|
-
context("without parameters", function () {
|
|
304
|
-
it("creates a node", function () {
|
|
305
|
-
expect(given.node.name).toBe("");
|
|
306
|
-
expect(given.node.id).toBeUndefined();
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
context("with a string", function () {
|
|
310
|
-
given("params", function () {
|
|
311
|
-
return "n1";
|
|
312
|
-
});
|
|
313
|
-
it("creates a node", function () {
|
|
314
|
-
expect(given.node).toMatchObject({
|
|
315
|
-
name: "n1",
|
|
316
|
-
children: [],
|
|
317
|
-
parent: null
|
|
318
|
-
});
|
|
319
|
-
expect(given.node).not.toHaveProperty("id");
|
|
320
|
-
});
|
|
321
|
-
it("sets isEmptyFolder to false", function () {
|
|
322
|
-
expect(given.node.isEmptyFolder).toBe(false);
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
context("with an object with a name property", function () {
|
|
326
|
-
given("params", function () {
|
|
327
|
-
return {
|
|
328
|
-
id: 123,
|
|
329
|
-
name: "n1"
|
|
330
|
-
};
|
|
331
|
-
});
|
|
332
|
-
it("creates a node", function () {
|
|
333
|
-
expect(given.node).toMatchObject({
|
|
334
|
-
id: 123,
|
|
335
|
-
name: "n1"
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
context("when the name property is null", function () {
|
|
340
|
-
given("params", function () {
|
|
341
|
-
return {
|
|
342
|
-
name: null
|
|
343
|
-
};
|
|
344
|
-
});
|
|
345
|
-
it("sets the name to an empty string", function () {
|
|
346
|
-
expect(given.node.name).toBe("");
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
context("with an object with more properties", function () {
|
|
350
|
-
given("params", function () {
|
|
351
|
-
return {
|
|
352
|
-
color: "green",
|
|
353
|
-
id: 123,
|
|
354
|
-
name: "n1",
|
|
355
|
-
url: "/abc"
|
|
356
|
-
};
|
|
357
|
-
});
|
|
358
|
-
it("creates a node", function () {
|
|
359
|
-
expect(given.node).toMatchObject({
|
|
360
|
-
color: "green",
|
|
361
|
-
id: 123,
|
|
362
|
-
name: "n1",
|
|
363
|
-
url: "/abc"
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
context("with an object with a label property", function () {
|
|
368
|
-
given("params", function () {
|
|
369
|
-
return {
|
|
370
|
-
id: 123,
|
|
371
|
-
label: "n1",
|
|
372
|
-
url: "/"
|
|
373
|
-
};
|
|
374
|
-
});
|
|
375
|
-
it("creates a node", function () {
|
|
376
|
-
expect(given.node).toMatchObject({
|
|
377
|
-
id: 123,
|
|
378
|
-
name: "n1",
|
|
379
|
-
url: "/"
|
|
380
|
-
});
|
|
381
|
-
expect(given.node).not.toHaveProperty("label");
|
|
382
|
-
expect(given.node.children).toHaveLength(0);
|
|
383
|
-
expect(given.node.parent).toBeNull();
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
context("with an object with a parent", function () {
|
|
387
|
-
given("params", function () {
|
|
388
|
-
return {
|
|
389
|
-
name: "n1",
|
|
390
|
-
parent: "abc"
|
|
391
|
-
};
|
|
392
|
-
});
|
|
393
|
-
it("doesn't set the parent", function () {
|
|
394
|
-
expect(given.node.name).toBe("n1");
|
|
395
|
-
expect(given.node.parent).toBeNull();
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
context("with an object with children", function () {
|
|
399
|
-
given("params", function () {
|
|
400
|
-
return {
|
|
401
|
-
name: "n1",
|
|
402
|
-
children: ["c"]
|
|
403
|
-
};
|
|
404
|
-
});
|
|
405
|
-
it("doesn't set the children", function () {
|
|
406
|
-
expect(given.node.name).toBe("n1");
|
|
407
|
-
expect(given.node.children).toHaveLength(0);
|
|
408
|
-
});
|
|
409
|
-
it("sets isEmptyFolder to false", function () {
|
|
410
|
-
expect(given.node.isEmptyFolder).toBe(false);
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
context("when the data contains an empty children attribute", function () {
|
|
414
|
-
given("params", function () {
|
|
415
|
-
return {
|
|
416
|
-
name: "n1",
|
|
417
|
-
children: []
|
|
418
|
-
};
|
|
419
|
-
});
|
|
420
|
-
it("sets isEmptyFolder to true", function () {
|
|
421
|
-
expect(given.node.isEmptyFolder).toBe(true);
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
describe("getChildIndex", function () {
|
|
426
|
-
var given = (0, _givens["default"])();
|
|
427
|
-
given("child2", function () {
|
|
428
|
-
return new _node.Node("child2");
|
|
429
|
-
});
|
|
430
|
-
given("node", function () {
|
|
431
|
-
return new _node.Node();
|
|
432
|
-
});
|
|
433
|
-
beforeEach(function () {
|
|
434
|
-
given.node.addChild(new _node.Node("child1"));
|
|
435
|
-
given.node.addChild(given.child2);
|
|
436
|
-
given.node.addChild(new _node.Node("child3"));
|
|
437
|
-
});
|
|
438
|
-
context("when a child exists", function () {
|
|
439
|
-
it("returns the index", function () {
|
|
440
|
-
expect(given.node.getChildIndex(given.child2)).toBe(1);
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
context("when a child doesn't exist", function () {
|
|
444
|
-
it("returns -1", function () {
|
|
445
|
-
var nonExistingChild = new _node.Node("non-existing");
|
|
446
|
-
expect(given.node.getChildIndex(nonExistingChild)).toBe(-1);
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
describe("getData", function () {
|
|
451
|
-
var given = (0, _givens["default"])();
|
|
452
|
-
given("tree", function () {
|
|
453
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
454
|
-
});
|
|
455
|
-
it("returns the tree data", function () {
|
|
456
|
-
expect(given.tree.getData()).toEqual([expect.objectContaining({
|
|
457
|
-
name: "node1",
|
|
458
|
-
children: [expect.objectContaining({
|
|
459
|
-
name: "child1"
|
|
460
|
-
}), expect.objectContaining({
|
|
461
|
-
name: "child2"
|
|
462
|
-
})]
|
|
463
|
-
}), expect.objectContaining({
|
|
464
|
-
name: "node2"
|
|
465
|
-
})]);
|
|
466
|
-
});
|
|
467
|
-
it("doesn't include internal attributes", function () {
|
|
468
|
-
expect(given.tree.getData()[0]).not.toContainAnyKeys(["element", "isEmptyFolder", "parent"]);
|
|
469
|
-
});
|
|
470
|
-
context("with includeParent parameter", function () {
|
|
471
|
-
it("returns the tree data including the node itself", function () {
|
|
472
|
-
expect(given.tree.getData(true)).toEqual([expect.objectContaining({
|
|
473
|
-
children: [expect.objectContaining({
|
|
474
|
-
name: "node1"
|
|
475
|
-
}), expect.objectContaining({
|
|
476
|
-
name: "node2"
|
|
477
|
-
})]
|
|
478
|
-
})]);
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
describe("getLastChild", function () {
|
|
483
|
-
var given = (0, _givens["default"])();
|
|
484
|
-
given("node", function () {
|
|
485
|
-
return new _node.Node();
|
|
486
|
-
});
|
|
487
|
-
context("when a node has no children", function () {
|
|
488
|
-
it("returns null", function () {
|
|
489
|
-
expect(given.node.getLastChild()).toBeNull();
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
context("when a node has children", function () {
|
|
493
|
-
beforeEach(function () {
|
|
494
|
-
given.node.append("child1");
|
|
495
|
-
given.node.append("child2");
|
|
496
|
-
});
|
|
497
|
-
it("returns the last child", function () {
|
|
498
|
-
expect(given.node.getLastChild()).toMatchObject({
|
|
499
|
-
name: "child2"
|
|
500
|
-
});
|
|
501
|
-
});
|
|
502
|
-
context("when its last child is open and has children", function () {
|
|
503
|
-
beforeEach(function () {
|
|
504
|
-
var child2 = given.node.children[1];
|
|
505
|
-
child2 === null || child2 === void 0 || child2.append("child2a");
|
|
506
|
-
child2 === null || child2 === void 0 || child2.append("child2b");
|
|
507
|
-
});
|
|
508
|
-
context("and the last child is open", function () {
|
|
509
|
-
beforeEach(function () {
|
|
510
|
-
var child2 = given.node.children[1];
|
|
511
|
-
if (child2) {
|
|
512
|
-
child2.is_open = true;
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
it("returns the last child of that child", function () {
|
|
516
|
-
expect(given.node.getLastChild()).toMatchObject({
|
|
517
|
-
name: "child2b"
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
});
|
|
521
|
-
context("and the last child is closed", function () {
|
|
522
|
-
it("returns the last child", function () {
|
|
523
|
-
expect(given.node.getLastChild()).toMatchObject({
|
|
524
|
-
name: "child2"
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
});
|
|
531
|
-
describe("getNextNode", function () {
|
|
532
|
-
var given = (0, _givens["default"])();
|
|
533
|
-
given("tree", function () {
|
|
534
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
535
|
-
});
|
|
536
|
-
context("with a parent node", function () {
|
|
537
|
-
given("fromNode", function () {
|
|
538
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
539
|
-
});
|
|
540
|
-
context("when the parent node is closed", function () {
|
|
541
|
-
it("returns the first child", function () {
|
|
542
|
-
expect(given.fromNode.getNextNode()).toMatchObject({
|
|
543
|
-
name: "child1"
|
|
544
|
-
});
|
|
545
|
-
});
|
|
546
|
-
});
|
|
547
|
-
context("when the parent node is open", function () {
|
|
548
|
-
beforeEach(function () {
|
|
549
|
-
given.fromNode.is_open = true;
|
|
550
|
-
});
|
|
551
|
-
it("returns the first child", function () {
|
|
552
|
-
expect(given.fromNode.getNextNode()).toMatchObject({
|
|
553
|
-
name: "child1"
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
context("with the node is the last child", function () {
|
|
559
|
-
given("fromNode", function () {
|
|
560
|
-
return given.tree.getNodeByNameMustExist("child2");
|
|
561
|
-
});
|
|
562
|
-
it("returns the next sibling of the parent", function () {
|
|
563
|
-
expect(given.fromNode.getNextNode()).toMatchObject({
|
|
564
|
-
name: "node2"
|
|
565
|
-
});
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
context("with includeChildren is false", function () {
|
|
569
|
-
context("with an open parent node", function () {
|
|
570
|
-
given("fromNode", function () {
|
|
571
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
572
|
-
});
|
|
573
|
-
beforeEach(function () {
|
|
574
|
-
given.fromNode.is_open = true;
|
|
575
|
-
});
|
|
576
|
-
it("returns the next sibling", function () {
|
|
577
|
-
expect(given.fromNode.getNextNode(false)).toMatchObject({
|
|
578
|
-
name: "node2"
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
});
|
|
583
|
-
});
|
|
584
|
-
describe("getNextVisibleNode", function () {
|
|
585
|
-
var given = (0, _givens["default"])();
|
|
586
|
-
given("tree", function () {
|
|
587
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
588
|
-
});
|
|
589
|
-
context("with a parent node", function () {
|
|
590
|
-
given("fromNode", function () {
|
|
591
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
592
|
-
});
|
|
593
|
-
context("when the parent node is closed", function () {
|
|
594
|
-
it("returns the next sibling", function () {
|
|
595
|
-
expect(given.fromNode.getNextVisibleNode()).toMatchObject({
|
|
596
|
-
name: "node2"
|
|
597
|
-
});
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
context("when the parent node is open", function () {
|
|
601
|
-
beforeEach(function () {
|
|
602
|
-
given.fromNode.is_open = true;
|
|
603
|
-
});
|
|
604
|
-
it("returns the first child", function () {
|
|
605
|
-
expect(given.fromNode.getNextVisibleNode()).toMatchObject({
|
|
606
|
-
name: "child1"
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
context("with the node is the last child", function () {
|
|
612
|
-
given("fromNode", function () {
|
|
613
|
-
return given.tree.getNodeByNameMustExist("child2");
|
|
614
|
-
});
|
|
615
|
-
it("returns the next sibling of the parent", function () {
|
|
616
|
-
expect(given.fromNode.getNextVisibleNode()).toMatchObject({
|
|
617
|
-
name: "node2"
|
|
618
|
-
});
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
context("with the tree node", function () {
|
|
622
|
-
given("fromNode", function () {
|
|
623
|
-
return given.tree;
|
|
624
|
-
});
|
|
625
|
-
it("returns null", function () {
|
|
626
|
-
expect(given.fromNode.getNextVisibleNode()).toBeNull();
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
});
|
|
630
|
-
describe("getNextSibling", function () {
|
|
631
|
-
var given = (0, _givens["default"])();
|
|
632
|
-
given("node1", function () {
|
|
633
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
634
|
-
});
|
|
635
|
-
given("node2", function () {
|
|
636
|
-
return given.tree.getNodeByNameMustExist("node2");
|
|
637
|
-
});
|
|
638
|
-
given("tree", function () {
|
|
639
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
640
|
-
});
|
|
641
|
-
context("with a tree", function () {
|
|
642
|
-
it("returns null", function () {
|
|
643
|
-
expect(given.tree.getNextSibling()).toBeNull();
|
|
644
|
-
});
|
|
645
|
-
});
|
|
646
|
-
context("when the node is the last child", function () {
|
|
647
|
-
it("returns null", function () {
|
|
648
|
-
expect(given.node2.getNextSibling()).toBeNull();
|
|
649
|
-
});
|
|
650
|
-
});
|
|
651
|
-
context("when the node is the first child", function () {
|
|
652
|
-
it("returns the second child", function () {
|
|
653
|
-
expect(given.node1.getNextSibling()).toBe(given.node2);
|
|
654
|
-
});
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
describe("getNodeByCallback", function () {
|
|
658
|
-
var given = (0, _givens["default"])();
|
|
659
|
-
given("tree", function () {
|
|
660
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
661
|
-
});
|
|
662
|
-
context("when a matching node exists", function () {
|
|
663
|
-
it("returns the node", function () {
|
|
664
|
-
expect(given.tree.getNodeByCallback(function (node) {
|
|
665
|
-
return node.name.startsWith("chi");
|
|
666
|
-
})).toMatchObject({
|
|
667
|
-
name: "child1"
|
|
668
|
-
});
|
|
669
|
-
});
|
|
670
|
-
});
|
|
671
|
-
context("when no matching node exists", function () {
|
|
672
|
-
it("returns null", function () {
|
|
673
|
-
expect(given.tree.getNodeByCallback(function () {
|
|
674
|
-
return false;
|
|
675
|
-
})).toBeNull();
|
|
676
|
-
});
|
|
677
|
-
});
|
|
678
|
-
});
|
|
679
|
-
describe("getNodeByName", function () {
|
|
680
|
-
var given = (0, _givens["default"])();
|
|
681
|
-
given("tree", function () {
|
|
682
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
683
|
-
});
|
|
684
|
-
context("when the node exists", function () {
|
|
685
|
-
it("returns the node", function () {
|
|
686
|
-
expect(given.tree.getNodeByName("child1")).toMatchObject({
|
|
687
|
-
id: 125,
|
|
688
|
-
name: "child1"
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
});
|
|
692
|
-
context("when the node doesn't exist", function () {
|
|
693
|
-
it("returns null", function () {
|
|
694
|
-
expect(given.tree.getNodeByName("non-existing")).toBeNull();
|
|
695
|
-
});
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
describe("getNodeByNameMustExist", function () {
|
|
699
|
-
var given = (0, _givens["default"])();
|
|
700
|
-
given("tree", function () {
|
|
701
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
702
|
-
});
|
|
703
|
-
context("when the node exists", function () {
|
|
704
|
-
it("returns the node", function () {
|
|
705
|
-
expect(given.tree.getNodeByNameMustExist("child1")).toMatchObject({
|
|
706
|
-
id: 125,
|
|
707
|
-
name: "child1"
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
});
|
|
711
|
-
context("when the node doesn't exist", function () {
|
|
712
|
-
it("throws an exception", function () {
|
|
713
|
-
expect(function () {
|
|
714
|
-
return given.tree.getNodeByNameMustExist("non-existing");
|
|
715
|
-
}).toThrow("Node with name non-existing not found");
|
|
716
|
-
});
|
|
717
|
-
});
|
|
718
|
-
});
|
|
719
|
-
describe("getParent", function () {
|
|
720
|
-
var given = (0, _givens["default"])();
|
|
721
|
-
given("child1", function () {
|
|
722
|
-
return given.tree.getNodeByNameMustExist("child1");
|
|
723
|
-
});
|
|
724
|
-
given("node1", function () {
|
|
725
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
726
|
-
});
|
|
727
|
-
given("tree", function () {
|
|
728
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
729
|
-
});
|
|
730
|
-
context("with a tree", function () {
|
|
731
|
-
it("returns null", function () {
|
|
732
|
-
expect(given.tree.getParent()).toBeNull();
|
|
733
|
-
});
|
|
734
|
-
});
|
|
735
|
-
context("with a node on the first level", function () {
|
|
736
|
-
it("returns null", function () {
|
|
737
|
-
expect(given.node1.getParent()).toBeNull();
|
|
738
|
-
});
|
|
739
|
-
});
|
|
740
|
-
context("with a node on the second level", function () {
|
|
741
|
-
it("returns the parent", function () {
|
|
742
|
-
expect(given.child1.getParent()).toMatchObject({
|
|
743
|
-
name: "node1"
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
|
-
});
|
|
748
|
-
describe("getPreviousNode", function () {
|
|
749
|
-
var given = (0, _givens["default"])();
|
|
750
|
-
given("tree", function () {
|
|
751
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
752
|
-
});
|
|
753
|
-
it("returns null with a tree node", function () {
|
|
754
|
-
expect(given.tree.getPreviousNode()).toBeNull();
|
|
755
|
-
});
|
|
756
|
-
it("returns the last child of the previous sibling when the previous node is closed and has children", function () {
|
|
757
|
-
given.tree.getNodeByNameMustExist("node2").is_open = false;
|
|
758
|
-
var node2 = given.tree.getNodeByNameMustExist("node2");
|
|
759
|
-
expect(node2.getPreviousNode()).toMatchObject({
|
|
760
|
-
name: "child2"
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
it("returns the last child of the previous sibling when the previous node is open and has children", function () {
|
|
764
|
-
given.tree.getNodeByNameMustExist("node2").is_open = true;
|
|
765
|
-
var node2 = given.tree.getNodeByNameMustExist("node2");
|
|
766
|
-
expect(node2.getPreviousNode()).toMatchObject({
|
|
767
|
-
name: "child2"
|
|
768
|
-
});
|
|
769
|
-
});
|
|
770
|
-
it("returns the first child if a node is the second child", function () {
|
|
771
|
-
var child2 = given.tree.getNodeByNameMustExist("child2");
|
|
772
|
-
expect(child2.getPreviousNode()).toMatchObject({
|
|
773
|
-
name: "child1"
|
|
774
|
-
});
|
|
775
|
-
});
|
|
776
|
-
it("returns the parent with a node that is the first child", function () {
|
|
777
|
-
var node3 = given.tree.getNodeByNameMustExist("node3");
|
|
778
|
-
expect(node3.getPreviousNode()).toMatchObject({
|
|
779
|
-
name: "node2"
|
|
780
|
-
});
|
|
781
|
-
});
|
|
782
|
-
});
|
|
783
|
-
describe("getPreviousVisibleNode", function () {
|
|
784
|
-
var given = (0, _givens["default"])();
|
|
785
|
-
given("tree", function () {
|
|
786
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
787
|
-
});
|
|
788
|
-
it("returns null with a tree node", function () {
|
|
789
|
-
expect(given.tree.getPreviousVisibleNode()).toBeNull();
|
|
790
|
-
});
|
|
791
|
-
it("returns the previous sibling when the previous sibling is closed and has children", function () {
|
|
792
|
-
given.tree.getNodeByNameMustExist("node2").is_open = false;
|
|
793
|
-
var node2 = given.tree.getNodeByNameMustExist("node2");
|
|
794
|
-
expect(node2.getPreviousVisibleNode()).toMatchObject({
|
|
795
|
-
name: "node1"
|
|
796
|
-
});
|
|
797
|
-
});
|
|
798
|
-
it("returns the last child of the previous sibling when the previous sibling is open and has children", function () {
|
|
799
|
-
given.tree.getNodeByNameMustExist("node1").is_open = true;
|
|
800
|
-
var node2 = given.tree.getNodeByNameMustExist("node2");
|
|
801
|
-
expect(node2.getPreviousVisibleNode()).toMatchObject({
|
|
802
|
-
name: "child2"
|
|
803
|
-
});
|
|
804
|
-
});
|
|
805
|
-
it("returns the first child if a node is the second child", function () {
|
|
806
|
-
var child2 = given.tree.getNodeByNameMustExist("child2");
|
|
807
|
-
expect(child2.getPreviousVisibleNode()).toMatchObject({
|
|
808
|
-
name: "child1"
|
|
809
|
-
});
|
|
810
|
-
});
|
|
811
|
-
it("returns the parent when a node is the first child", function () {
|
|
812
|
-
var node3 = given.tree.getNodeByNameMustExist("node3");
|
|
813
|
-
expect(node3.getPreviousVisibleNode()).toMatchObject({
|
|
814
|
-
name: "node2"
|
|
815
|
-
});
|
|
816
|
-
});
|
|
817
|
-
});
|
|
818
|
-
describe("getPreviousSibling", function () {
|
|
819
|
-
var given = (0, _givens["default"])();
|
|
820
|
-
given("node1", function () {
|
|
821
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
822
|
-
});
|
|
823
|
-
given("node2", function () {
|
|
824
|
-
return given.tree.getNodeByNameMustExist("node2");
|
|
825
|
-
});
|
|
826
|
-
given("tree", function () {
|
|
827
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
828
|
-
});
|
|
829
|
-
context("with a tree", function () {
|
|
830
|
-
it("returns null", function () {
|
|
831
|
-
expect(given.tree.getPreviousSibling()).toBeNull();
|
|
832
|
-
});
|
|
833
|
-
});
|
|
834
|
-
context("when the node is the first child", function () {
|
|
835
|
-
it("returns null", function () {
|
|
836
|
-
expect(given.node1.getPreviousSibling()).toBeNull();
|
|
837
|
-
});
|
|
838
|
-
});
|
|
839
|
-
context("when the node is the second child", function () {
|
|
840
|
-
it("returns the first child", function () {
|
|
841
|
-
expect(given.node2.getPreviousSibling()).toBe(given.node1);
|
|
842
|
-
});
|
|
843
|
-
});
|
|
844
|
-
});
|
|
845
|
-
describe("hasChildren", function () {
|
|
846
|
-
var given = (0, _givens["default"])();
|
|
847
|
-
given("node", function () {
|
|
848
|
-
return new _node.Node();
|
|
849
|
-
});
|
|
850
|
-
context("when a node has children", function () {
|
|
851
|
-
beforeEach(function () {
|
|
852
|
-
given.node.addChild(new _node.Node("child1"));
|
|
853
|
-
});
|
|
854
|
-
it("returns true", function () {
|
|
855
|
-
expect(given.node.hasChildren()).toBe(true);
|
|
856
|
-
});
|
|
857
|
-
});
|
|
858
|
-
context("when a node doesn't have children", function () {
|
|
859
|
-
it("returns false", function () {
|
|
860
|
-
expect(given.node.hasChildren()).toBe(false);
|
|
861
|
-
});
|
|
862
|
-
});
|
|
863
|
-
});
|
|
864
|
-
describe("initFromData", function () {
|
|
865
|
-
var given = (0, _givens["default"])();
|
|
866
|
-
given("tree", function () {
|
|
867
|
-
return new _node.Node();
|
|
868
|
-
});
|
|
869
|
-
beforeEach(function () {
|
|
870
|
-
given.tree.initFromData({
|
|
871
|
-
name: "node1",
|
|
872
|
-
id: 1,
|
|
873
|
-
children: [{
|
|
874
|
-
name: "child1",
|
|
875
|
-
id: 2
|
|
876
|
-
}, {
|
|
877
|
-
name: "child2",
|
|
878
|
-
id: 3
|
|
879
|
-
}]
|
|
880
|
-
});
|
|
881
|
-
});
|
|
882
|
-
it("loads the data", function () {
|
|
883
|
-
expect(given.tree).toMatchObject({
|
|
884
|
-
id: 1,
|
|
885
|
-
name: "node1",
|
|
886
|
-
children: [expect.objectContaining({
|
|
887
|
-
id: 2,
|
|
888
|
-
name: "child1"
|
|
889
|
-
}), expect.objectContaining({
|
|
890
|
-
id: 3,
|
|
891
|
-
name: "child2"
|
|
892
|
-
})]
|
|
893
|
-
});
|
|
894
|
-
});
|
|
895
|
-
});
|
|
896
|
-
describe("isFolder", function () {
|
|
897
|
-
var given = (0, _givens["default"])();
|
|
898
|
-
given("node", function () {
|
|
899
|
-
return new _node.Node();
|
|
900
|
-
});
|
|
901
|
-
context("when the node has no children", function () {
|
|
902
|
-
it("returns false", function () {
|
|
903
|
-
expect(given.node.isFolder()).toBe(false);
|
|
904
|
-
});
|
|
905
|
-
context("when the node is loaded on demand", function () {
|
|
906
|
-
beforeEach(function () {
|
|
907
|
-
given.node.load_on_demand = true;
|
|
908
|
-
});
|
|
909
|
-
it("returns false", function () {
|
|
910
|
-
expect(given.node.isFolder()).toBe(true);
|
|
911
|
-
});
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
context("when the node has a child", function () {
|
|
915
|
-
beforeEach(function () {
|
|
916
|
-
given.node.append("child1");
|
|
917
|
-
});
|
|
918
|
-
it("returns false", function () {
|
|
919
|
-
expect(given.node.isFolder()).toBe(true);
|
|
920
|
-
});
|
|
921
|
-
});
|
|
922
|
-
});
|
|
923
|
-
describe("iterate", function () {
|
|
924
|
-
var given = (0, _givens["default"])();
|
|
925
|
-
given("tree", function () {
|
|
926
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
927
|
-
});
|
|
928
|
-
given("visited", function () {
|
|
929
|
-
return [];
|
|
930
|
-
});
|
|
931
|
-
beforeEach(function () {
|
|
932
|
-
given.tree.iterate(given.visitor);
|
|
933
|
-
});
|
|
934
|
-
context("when the visitor function returns true", function () {
|
|
935
|
-
var visitAllNodes = function visitAllNodes(node, level) {
|
|
936
|
-
given.visited.push([node.name, level]);
|
|
937
|
-
return true;
|
|
938
|
-
};
|
|
939
|
-
given("visitor", function () {
|
|
940
|
-
return visitAllNodes;
|
|
941
|
-
});
|
|
942
|
-
it("visits all nodes", function () {
|
|
943
|
-
expect(given.visited).toEqual([["node1", 0], ["child1", 1], ["child2", 1], ["node2", 0], ["node3", 1], ["child3", 2]]);
|
|
944
|
-
});
|
|
945
|
-
});
|
|
946
|
-
context("when the visitor function returns false", function () {
|
|
947
|
-
var visitNodes = function visitNodes(node, level) {
|
|
948
|
-
given.visited.push([node.name, level]);
|
|
949
|
-
return false;
|
|
950
|
-
};
|
|
951
|
-
given("visitor", function () {
|
|
952
|
-
return visitNodes;
|
|
953
|
-
});
|
|
954
|
-
it("stops the iteration for the current node", function () {
|
|
955
|
-
expect(given.visited).toEqual([["node1", 0], ["node2", 0]]);
|
|
956
|
-
});
|
|
957
|
-
});
|
|
958
|
-
});
|
|
959
|
-
describe("loadFromData", function () {
|
|
960
|
-
it("creates a tree", function () {
|
|
961
|
-
var tree = new _node.Node().loadFromData(_exampleData["default"]);
|
|
962
|
-
expect(tree.children).toEqual([expect.objectContaining({
|
|
963
|
-
id: 123,
|
|
964
|
-
intProperty: 1,
|
|
965
|
-
name: "node1",
|
|
966
|
-
strProperty: "1",
|
|
967
|
-
children: [expect.objectContaining({
|
|
968
|
-
id: 125,
|
|
969
|
-
name: "child1"
|
|
970
|
-
}), expect.objectContaining({
|
|
971
|
-
id: 126,
|
|
972
|
-
name: "child2"
|
|
973
|
-
})]
|
|
974
|
-
}), expect.objectContaining({
|
|
975
|
-
id: 124,
|
|
976
|
-
intProperty: 3,
|
|
977
|
-
name: "node2",
|
|
978
|
-
strProperty: "3",
|
|
979
|
-
children: [expect.objectContaining({
|
|
980
|
-
id: 127,
|
|
981
|
-
name: "node3"
|
|
982
|
-
})]
|
|
983
|
-
})]);
|
|
984
|
-
});
|
|
985
|
-
it("sets isEmptyFolder to true for a node when it is has an empty children attribute", function () {
|
|
986
|
-
var data = [{
|
|
987
|
-
name: "test1",
|
|
988
|
-
children: []
|
|
989
|
-
}];
|
|
990
|
-
var tree = new _node.Node().loadFromData(data);
|
|
991
|
-
expect(tree.children[0].isEmptyFolder).toBe(true);
|
|
992
|
-
});
|
|
993
|
-
it("sets isEmptyFolder to false for a node when it doesn't have a children attribute", function () {
|
|
994
|
-
var data = [{
|
|
995
|
-
name: "test1"
|
|
996
|
-
}];
|
|
997
|
-
var tree = new _node.Node().loadFromData(data);
|
|
998
|
-
expect(tree.children[0].isEmptyFolder).toBe(false);
|
|
999
|
-
});
|
|
1000
|
-
it("sets isEmptyFolder to false for a node when it has a children attribute that is not empty", function () {
|
|
1001
|
-
var data = [{
|
|
1002
|
-
name: "test1",
|
|
1003
|
-
children: ["child1"]
|
|
1004
|
-
}];
|
|
1005
|
-
var tree = new _node.Node().loadFromData(data);
|
|
1006
|
-
expect(tree.children[0].isEmptyFolder).toBe(false);
|
|
1007
|
-
});
|
|
1008
|
-
});
|
|
1009
|
-
describe("moveNode", function () {
|
|
1010
|
-
var given = (0, _givens["default"])();
|
|
1011
|
-
given("child1", function () {
|
|
1012
|
-
return given.tree.getNodeByNameMustExist("child1");
|
|
1013
|
-
});
|
|
1014
|
-
given("child2", function () {
|
|
1015
|
-
return given.tree.getNodeByNameMustExist("child2");
|
|
1016
|
-
});
|
|
1017
|
-
given("node1", function () {
|
|
1018
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
1019
|
-
});
|
|
1020
|
-
given("node2", function () {
|
|
1021
|
-
return given.tree.getNodeByNameMustExist("node2");
|
|
1022
|
-
});
|
|
1023
|
-
given("tree", function () {
|
|
1024
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
1025
|
-
});
|
|
1026
|
-
context("when moving after a node", function () {
|
|
1027
|
-
it("moves the node", function () {
|
|
1028
|
-
expect(given.tree.moveNode(given.child2, given.node2, _node.Position.After)).toBe(true);
|
|
1029
|
-
expect(given.tree).toMatchObject({
|
|
1030
|
-
name: "",
|
|
1031
|
-
children: [expect.objectContaining({
|
|
1032
|
-
name: "node1",
|
|
1033
|
-
children: [expect.objectContaining({
|
|
1034
|
-
name: "child1"
|
|
1035
|
-
})]
|
|
1036
|
-
}), expect.objectContaining({
|
|
1037
|
-
name: "node2"
|
|
1038
|
-
}), expect.objectContaining({
|
|
1039
|
-
name: "child2"
|
|
1040
|
-
})]
|
|
1041
|
-
});
|
|
1042
|
-
});
|
|
1043
|
-
context("when the target is the root node", function () {
|
|
1044
|
-
it("returns false", function () {
|
|
1045
|
-
expect(given.tree.moveNode(given.child2, given.tree, _node.Position.After)).toBe(false);
|
|
1046
|
-
});
|
|
1047
|
-
});
|
|
1048
|
-
});
|
|
1049
|
-
context("when moving inside a node", function () {
|
|
1050
|
-
it("moves the node", function () {
|
|
1051
|
-
expect(given.tree.moveNode(given.child1, given.node2, _node.Position.Inside)).toBe(true);
|
|
1052
|
-
expect(given.tree).toMatchObject({
|
|
1053
|
-
name: "",
|
|
1054
|
-
children: [expect.objectContaining({
|
|
1055
|
-
name: "node1",
|
|
1056
|
-
children: [expect.objectContaining({
|
|
1057
|
-
name: "child2"
|
|
1058
|
-
})]
|
|
1059
|
-
}), expect.objectContaining({
|
|
1060
|
-
name: "node2",
|
|
1061
|
-
children: [expect.objectContaining({
|
|
1062
|
-
name: "child1"
|
|
1063
|
-
}), expect.objectContaining({
|
|
1064
|
-
name: "node3"
|
|
1065
|
-
})]
|
|
1066
|
-
})]
|
|
1067
|
-
});
|
|
1068
|
-
});
|
|
1069
|
-
});
|
|
1070
|
-
context("when moving before a node", function () {
|
|
1071
|
-
it("moves the node", function () {
|
|
1072
|
-
expect(given.tree.moveNode(given.child2, given.child1, _node.Position.Before)).toBe(true);
|
|
1073
|
-
expect(given.tree).toMatchObject({
|
|
1074
|
-
name: "",
|
|
1075
|
-
children: [expect.objectContaining({
|
|
1076
|
-
name: "node1",
|
|
1077
|
-
children: [expect.objectContaining({
|
|
1078
|
-
name: "child2"
|
|
1079
|
-
}), expect.objectContaining({
|
|
1080
|
-
name: "child1"
|
|
1081
|
-
})]
|
|
1082
|
-
}), expect.objectContaining({
|
|
1083
|
-
name: "node2"
|
|
1084
|
-
})]
|
|
1085
|
-
});
|
|
1086
|
-
});
|
|
1087
|
-
context("when the target is the root node", function () {
|
|
1088
|
-
it("returns false", function () {
|
|
1089
|
-
expect(given.tree.moveNode(given.child2, given.tree, _node.Position.Before)).toBe(false);
|
|
1090
|
-
});
|
|
1091
|
-
});
|
|
1092
|
-
});
|
|
1093
|
-
context("when the moved node is a parent of the target node", function () {
|
|
1094
|
-
it("doesn't move the node", function () {
|
|
1095
|
-
expect(given.tree.moveNode(given.node1, given.child1, _node.Position.Before)).toBe(false);
|
|
1096
|
-
expect(given.tree).toMatchObject({
|
|
1097
|
-
children: [expect.objectContaining({
|
|
1098
|
-
name: "node1",
|
|
1099
|
-
children: [expect.objectContaining({
|
|
1100
|
-
name: "child1"
|
|
1101
|
-
}), expect.objectContaining({
|
|
1102
|
-
name: "child2"
|
|
1103
|
-
})]
|
|
1104
|
-
}), expect.objectContaining({
|
|
1105
|
-
name: "node2"
|
|
1106
|
-
})]
|
|
1107
|
-
});
|
|
1108
|
-
});
|
|
1109
|
-
});
|
|
1110
|
-
context("with position None", function () {
|
|
1111
|
-
it("returns false", function () {
|
|
1112
|
-
expect(given.tree.moveNode(given.child2, given.node2, _node.Position.None)).toBe(false);
|
|
1113
|
-
});
|
|
1114
|
-
});
|
|
1115
|
-
});
|
|
1116
|
-
describe("prepend", function () {
|
|
1117
|
-
var given = (0, _givens["default"])();
|
|
1118
|
-
given("node", function () {
|
|
1119
|
-
return new _node.Node("node1");
|
|
1120
|
-
});
|
|
1121
|
-
it("prepends a node", function () {
|
|
1122
|
-
given.node.prepend("child2");
|
|
1123
|
-
given.node.prepend("child1");
|
|
1124
|
-
expect(given.node).toMatchObject({
|
|
1125
|
-
name: "node1",
|
|
1126
|
-
children: [expect.objectContaining({
|
|
1127
|
-
name: "child1"
|
|
1128
|
-
}), expect.objectContaining({
|
|
1129
|
-
name: "child2"
|
|
1130
|
-
})]
|
|
1131
|
-
});
|
|
1132
|
-
});
|
|
1133
|
-
context("when prepending a node with children", function () {
|
|
1134
|
-
it("adds the children", function () {
|
|
1135
|
-
given.node.prepend({
|
|
1136
|
-
name: "new node",
|
|
1137
|
-
children: ["newchild1", "newchild2"]
|
|
1138
|
-
});
|
|
1139
|
-
expect(given.node).toMatchObject({
|
|
1140
|
-
children: [expect.objectContaining({
|
|
1141
|
-
name: "new node",
|
|
1142
|
-
children: [expect.objectContaining({
|
|
1143
|
-
name: "newchild1"
|
|
1144
|
-
}), expect.objectContaining({
|
|
1145
|
-
name: "newchild2"
|
|
1146
|
-
})]
|
|
1147
|
-
})]
|
|
1148
|
-
});
|
|
1149
|
-
});
|
|
1150
|
-
});
|
|
1151
|
-
it("sets the isEmptyFolder attribute to true when the node data has empty children", function () {
|
|
1152
|
-
given.node.prepend({
|
|
1153
|
-
name: "test1",
|
|
1154
|
-
children: []
|
|
1155
|
-
});
|
|
1156
|
-
expect(given.node.children[0].isEmptyFolder).toBe(true);
|
|
1157
|
-
});
|
|
1158
|
-
});
|
|
1159
|
-
describe("remove", function () {
|
|
1160
|
-
var given = (0, _givens["default"])();
|
|
1161
|
-
given("child1", function () {
|
|
1162
|
-
return given.tree.getNodeByNameMustExist("child1");
|
|
1163
|
-
});
|
|
1164
|
-
given("tree", function () {
|
|
1165
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
1166
|
-
});
|
|
1167
|
-
beforeEach(function () {
|
|
1168
|
-
given.child1.remove();
|
|
1169
|
-
});
|
|
1170
|
-
it("removes the node", function () {
|
|
1171
|
-
expect(given.tree).toMatchObject({
|
|
1172
|
-
children: [expect.objectContaining({
|
|
1173
|
-
name: "node1",
|
|
1174
|
-
children: [expect.objectContaining({
|
|
1175
|
-
name: "child2"
|
|
1176
|
-
})]
|
|
1177
|
-
}), expect.objectContaining({
|
|
1178
|
-
name: "node2"
|
|
1179
|
-
})]
|
|
1180
|
-
});
|
|
1181
|
-
});
|
|
1182
|
-
});
|
|
1183
|
-
describe("removeChild", function () {
|
|
1184
|
-
var given = (0, _givens["default"])();
|
|
1185
|
-
given("child1", function () {
|
|
1186
|
-
return given.tree.getNodeByNameMustExist("child1");
|
|
1187
|
-
});
|
|
1188
|
-
given("node1", function () {
|
|
1189
|
-
return given.tree.getNodeByNameMustExist("node1");
|
|
1190
|
-
});
|
|
1191
|
-
given("tree", function () {
|
|
1192
|
-
return new _node.Node().loadFromData(_exampleData["default"]);
|
|
1193
|
-
});
|
|
1194
|
-
beforeEach(function () {
|
|
1195
|
-
given.node1.removeChild(given.child1);
|
|
1196
|
-
});
|
|
1197
|
-
it("removes the child", function () {
|
|
1198
|
-
expect(given.node1.children).toEqual([expect.objectContaining({
|
|
1199
|
-
name: "child2"
|
|
1200
|
-
})]);
|
|
1201
|
-
});
|
|
1202
|
-
});
|