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