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