jqtree 1.5.2 → 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 (174) hide show
  1. package/.eslintrc +1 -0
  2. package/.github/workflows/ci.yml +54 -0
  3. package/.github/workflows/codeql-analysis.yml +28 -0
  4. package/README.md +1 -1
  5. package/_config.yml +1 -1
  6. package/_entries/10_changelog.md +20 -0
  7. package/_entries/{36_showemptynode.md → 36_showemptyfolder.md} +5 -5
  8. package/_entries/38_start_dnd_delay.md +13 -0
  9. package/_entries/{38_tabindex.md → 39_tabindex.md} +0 -0
  10. package/_entries/{39_usecontextmenu.md → 40_usecontextmenu.md} +0 -0
  11. package/_entries/{40_functions.md → 41_functions.md} +0 -0
  12. package/_entries/{41_addparentnode.md → 42_addparentnode.md} +0 -0
  13. package/_entries/{42_addnodeafter.md → 43_addnodeafter.md} +0 -0
  14. package/_entries/{43_addnodebefore.md → 44_addnodebefore.md} +0 -0
  15. package/_entries/{44_appendnode.md → 45_appendnode.md} +0 -0
  16. package/_entries/{45_closenode.md → 46_closenode.md} +0 -0
  17. package/_entries/{46_destroy.md → 47_destroy.md} +0 -0
  18. package/_entries/{47_getnodebycallback.md → 48_getnodebycallback.md} +0 -0
  19. package/_entries/{48_getnodebyid.md → 49_getnodebyid.md} +0 -0
  20. package/_entries/{49_getnodebyhtmlelement.md → 50_getnodebyhtmlelement.md} +0 -0
  21. package/_entries/{50_getselectednode.md → 51_getselectednode.md} +0 -0
  22. package/_entries/{51_getstate.md → 52_getstate.md} +0 -0
  23. package/_entries/{52_gettree.md → 53_gettree.md} +0 -0
  24. package/_entries/{53_isdragging.md → 54_isdragging.md} +0 -0
  25. package/_entries/{54_loaddata.md → 55_loaddata.md} +0 -0
  26. package/_entries/{55_loaddatafromurl.md → 56_loaddatafromurl.md} +0 -0
  27. package/_entries/{56_movedown.md → 57_movedown.md} +0 -0
  28. package/_entries/{57_movenode.md → 58_movenode.md} +0 -0
  29. package/_entries/{58_moveup.md → 59_moveup.md} +0 -0
  30. package/_entries/{59_opennode.md → 60_opennode.md} +0 -0
  31. package/_entries/{60_prependnode.md → 61_prependnode.md} +0 -0
  32. package/_entries/62_refresh.md +12 -0
  33. package/_entries/{61_reload.md → 63_reload.md} +0 -0
  34. package/_entries/{62_removenode.md → 64_removenode.md} +0 -0
  35. package/_entries/{63_selectnode.md → 65_selectnode.md} +0 -0
  36. package/_entries/{64_scrolltonode.md → 66_scrolltonode.md} +0 -0
  37. package/_entries/{65_setoption.md → 67_setoption.md} +0 -0
  38. package/_entries/{66_setstate.md → 68_setstate.md} +0 -0
  39. package/_entries/{67_toggle.md → 69_toggle.md} +0 -0
  40. package/_entries/{68_tojson.md → 70_tojson.md} +0 -0
  41. package/_entries/{69_updatenode.md → 71_updatenode.md} +0 -0
  42. package/_entries/{70_events.md → 72_events.md} +0 -0
  43. package/_entries/{71_tree-click.md → 73_tree-click.md} +0 -0
  44. package/_entries/{72_tree-close.md → 74_tree-close.md} +0 -0
  45. package/_entries/{73_tree-contextmenu.md → 75_tree-contextmenu.md} +0 -0
  46. package/_entries/{74_tree-dblclick.md → 76_tree-dblclick.md} +0 -0
  47. package/_entries/{75_tree-init.md → 77_tree-init.md} +0 -0
  48. package/_entries/{76_tree-load-data.md → 78_tree-load-data.md} +0 -0
  49. package/_entries/{77_tree-loading-data.md → 79_tree-loading-data.md} +0 -0
  50. package/_entries/{78_tree-move.md → 80_tree-move.md} +0 -0
  51. package/_entries/{79_tree-refresh.md → 81_tree-refresh.md} +0 -0
  52. package/_entries/{80_tree-open.md → 82_tree-open.md} +0 -0
  53. package/_entries/{81_tree-select.md → 83_tree-select.md} +0 -0
  54. package/_entries/{82_multiple-selection.md → 84_multiple-selection.md} +0 -0
  55. package/_entries/{83_add-to-selection.md → 85_add-to-selection.md} +0 -0
  56. package/_entries/{84_get-selected-nodes.md → 86_get-selected-nodes.md} +0 -0
  57. package/_entries/{85_is-node-selected.md → 87_is-node-selected.md} +0 -0
  58. package/_entries/{86_remove-from-selection.md → 88_remove-from-selection.md} +0 -0
  59. package/_entries/{87_node-functions.md → 89_node-functions.md} +0 -0
  60. package/_entries/{88_children.md → 90_children.md} +0 -0
  61. package/_entries/{89_getdata.md → 91_getdata.md} +0 -0
  62. package/_entries/{90_getlevel.md → 92_getlevel.md} +0 -0
  63. package/_entries/{91_getnextnode.md → 93_getnextnode.md} +0 -0
  64. package/_entries/{92_getnextsibling.md → 94_getnextsibling.md} +0 -0
  65. package/_entries/{93_getpreviousnode.md → 95_getpreviousnode.md} +0 -0
  66. package/_entries/{94_getprevioussibling.md → 96_getprevioussibling.md} +0 -0
  67. package/_entries/{95_parent.md → 97_parent.md} +0 -0
  68. package/_examples/13_drag_outside.html +2 -1
  69. package/_examples/14_filter.html +113 -0
  70. package/_layouts/base.html +1 -23
  71. package/babel.config.json +11 -0
  72. package/babel.coverage.config.json +4 -0
  73. package/bower.json +1 -1
  74. package/jest-browser.config.js +0 -3
  75. package/jest-jsdom.config.js +1 -2
  76. package/jqtree.css +4 -1
  77. package/jqtree.postcss +3 -0
  78. package/lib/dataLoader.js +146 -98
  79. package/lib/dragAndDropHandler.js +668 -470
  80. package/lib/elementsRenderer.js +282 -197
  81. package/lib/jqtreeOptions.js +1 -2
  82. package/lib/keyHandler.js +134 -87
  83. package/lib/mouse.widget.js +288 -165
  84. package/lib/node.js +693 -505
  85. package/lib/nodeElement.js +329 -205
  86. package/lib/playwright/playwright.test.js +216 -189
  87. package/lib/playwright/testUtil.js +437 -192
  88. package/lib/playwright/visualRegression.js +183 -117
  89. package/lib/saveStateHandler.js +311 -204
  90. package/lib/scrollHandler.js +293 -199
  91. package/lib/selectNodeHandler.js +140 -105
  92. package/lib/simple.widget.js +184 -109
  93. package/lib/test/global.d.js +3 -0
  94. package/lib/test/jqTree/create.test.js +44 -40
  95. package/lib/test/jqTree/events.test.js +185 -138
  96. package/lib/test/jqTree/keyboard.test.js +216 -199
  97. package/lib/test/jqTree/loadOnDemand.test.js +233 -157
  98. package/lib/test/jqTree/methods.test.js +1269 -1000
  99. package/lib/test/jqTree/options.test.js +467 -398
  100. package/lib/test/node.test.js +1036 -873
  101. package/lib/test/nodeUtil.test.js +21 -20
  102. package/lib/test/support/exampleData.js +35 -23
  103. package/lib/test/support/jqTreeMatchers.js +72 -54
  104. package/lib/test/support/matchers.d.js +1 -0
  105. package/lib/test/support/setupTests.js +9 -3
  106. package/lib/test/support/testUtil.js +38 -15
  107. package/lib/test/support/treeStructure.js +41 -32
  108. package/lib/test/util.test.js +21 -20
  109. package/lib/tree.jquery.d.js +1 -0
  110. package/lib/tree.jquery.js +1264 -883
  111. package/lib/types.js +1 -2
  112. package/lib/typings.d.js +2 -0
  113. package/lib/util.js +21 -7
  114. package/lib/version.js +8 -3
  115. package/package.json +43 -36
  116. package/production +4 -4
  117. package/rollup.config.js +16 -11
  118. package/src/dataLoader.ts +6 -6
  119. package/src/dragAndDropHandler.ts +0 -4
  120. package/src/elementsRenderer.ts +4 -0
  121. package/src/jqtreeOptions.ts +33 -32
  122. package/src/mouse.widget.ts +58 -29
  123. package/src/node.ts +32 -46
  124. package/src/nodeElement.ts +17 -9
  125. package/src/playwright/.eslintrc +5 -0
  126. package/src/playwright/playwright.test.ts +30 -30
  127. package/src/playwright/testUtil.ts +36 -37
  128. package/src/saveStateHandler.ts +11 -6
  129. package/src/selectNodeHandler.ts +14 -21
  130. package/src/simple.widget.ts +1 -1
  131. package/src/test/.eslintrc +4 -0
  132. package/src/test/jqTree/create.test.ts +0 -1
  133. package/src/test/jqTree/events.test.ts +12 -13
  134. package/src/test/jqTree/keyboard.test.ts +0 -1
  135. package/src/test/jqTree/loadOnDemand.test.ts +46 -1
  136. package/src/test/jqTree/methods.test.ts +67 -18
  137. package/src/test/jqTree/options.test.ts +5 -6
  138. package/src/test/node.test.ts +2 -2
  139. package/src/test/support/jqTreeMatchers.ts +8 -9
  140. package/src/test/support/matchers.d.ts +2 -4
  141. package/src/test/support/setupTests.ts +2 -1
  142. package/src/tree.jquery.d.ts +19 -13
  143. package/src/tree.jquery.ts +63 -57
  144. package/src/version.ts +1 -1
  145. package/static/bower.json +3 -3
  146. package/static/bower_components/fontawesome/css/all.min.css +2 -2
  147. package/static/bower_components/fontawesome/webfonts/fa-brands-400.eot +0 -0
  148. package/static/bower_components/fontawesome/webfonts/fa-brands-400.svg +774 -627
  149. package/static/bower_components/fontawesome/webfonts/fa-brands-400.ttf +0 -0
  150. package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff +0 -0
  151. package/static/bower_components/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
  152. package/static/bower_components/fontawesome/webfonts/fa-regular-400.eot +0 -0
  153. package/static/bower_components/fontawesome/webfonts/fa-regular-400.svg +93 -95
  154. package/static/bower_components/fontawesome/webfonts/fa-regular-400.ttf +0 -0
  155. package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff +0 -0
  156. package/static/bower_components/fontawesome/webfonts/fa-regular-400.woff2 +0 -0
  157. package/static/bower_components/fontawesome/webfonts/fa-solid-900.eot +0 -0
  158. package/static/bower_components/fontawesome/webfonts/fa-solid-900.svg +1164 -1074
  159. package/static/bower_components/fontawesome/webfonts/fa-solid-900.ttf +0 -0
  160. package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff +0 -0
  161. package/static/bower_components/fontawesome/webfonts/fa-solid-900.woff2 +0 -0
  162. package/static/bower_components/jquery/dist/jquery.js +118 -109
  163. package/static/bower_components/jquery/dist/jquery.min.js +2 -2
  164. package/static/bower_components/jquery-mockjax/dist/jquery.mockjax.js +15 -9
  165. package/static/example.css +13 -0
  166. package/static/example.postcss +13 -0
  167. package/static/example_data.js +33 -36
  168. package/static/examples/filter.js +63 -0
  169. package/tree.jquery.debug.js +4809 -3305
  170. package/tree.jquery.debug.js.map +1 -1
  171. package/tree.jquery.js +3 -3
  172. package/tree.jquery.js.map +1 -1
  173. package/tsconfig.json +1 -0
  174. package/.travis.yml +0 -18
@@ -1,939 +1,1102 @@
1
1
  "use strict";
2
- exports.__esModule = true;
3
- var givens_1 = require("givens");
4
- var node_1 = require("../node");
5
- var exampleData_1 = require("./support/exampleData");
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
- var given = givens_1["default"]();
10
- given("node1", function () { return given.tree.getNodeByNameMustExist("node1"); });
11
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
12
- context("when moving after node1", function () {
13
- it("returns the new node", function () {
14
- expect(given.node1.addAfter("new node")).toMatchObject({
15
- name: "new node"
16
- });
17
- });
18
- it("adds after the node", function () {
19
- given.node1.addAfter("new node");
20
- expect(given.tree).toMatchObject({
21
- children: [
22
- expect.objectContaining({ name: "node1" }),
23
- expect.objectContaining({ name: "new node" }),
24
- expect.objectContaining({ name: "node2" }),
25
- ]
26
- });
27
- });
28
- });
29
- context("when moving after the root node", function () {
30
- it("returns null", function () {
31
- expect(given.tree.addAfter("new node")).toBeNull();
32
- });
33
- it("doesn't add anything", function () {
34
- expect(given.tree).toMatchObject({
35
- children: [
36
- expect.objectContaining({ name: "node1" }),
37
- expect.objectContaining({ name: "node2" }),
38
- ]
39
- });
40
- });
41
- });
42
- context("when adding a node with children", function () {
43
- it("adds the children", function () {
44
- given.node1.addAfter({
45
- name: "new node",
46
- children: ["newchild1", "newchild2"]
47
- });
48
- expect(given.tree).toMatchObject({
49
- children: [
50
- expect.objectContaining({ name: "node1" }),
51
- expect.objectContaining({
52
- name: "new node",
53
- children: [
54
- expect.objectContaining({ name: "newchild1" }),
55
- expect.objectContaining({ name: "newchild2" }),
56
- ]
57
- }),
58
- expect.objectContaining({ name: "node2" }),
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
- var given = givens_1["default"]();
66
- given("node2", function () { return given.tree.getNodeByNameMustExist("node2"); });
67
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
68
- it("returns the new node", function () {
69
- expect(given.node2.addBefore("new node")).toMatchObject({
70
- name: "new node"
71
- });
72
- });
73
- it("adds before the node", function () {
74
- given.node2.addBefore("new node");
75
- expect(given.tree).toMatchObject({
76
- children: [
77
- expect.objectContaining({ name: "node1" }),
78
- expect.objectContaining({ name: "new node" }),
79
- expect.objectContaining({ name: "node2" }),
80
- ]
81
- });
82
- });
83
- context("with a root node", function () {
84
- it("returns null", function () {
85
- expect(given.tree.addBefore("new node")).toBeNull();
86
- });
87
- it("does nothing", function () {
88
- given.tree.addBefore("new node");
89
- expect(given.tree).toMatchObject({
90
- children: [
91
- expect.objectContaining({ name: "node1" }),
92
- expect.objectContaining({ name: "node2" }),
93
- ]
94
- });
95
- });
96
- });
97
- context("when adding a node with children", function () {
98
- it("adds the children", function () {
99
- given.node2.addBefore({
100
- name: "new node",
101
- children: ["newchild1", "newchild2"]
102
- });
103
- expect(given.tree).toMatchObject({
104
- children: [
105
- expect.objectContaining({ name: "node1" }),
106
- expect.objectContaining({
107
- name: "new node",
108
- children: [
109
- expect.objectContaining({ name: "newchild1" }),
110
- expect.objectContaining({ name: "newchild2" }),
111
- ]
112
- }),
113
- expect.objectContaining({ name: "node2" }),
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
- var given = givens_1["default"]();
121
- given("node", function () { return new node_1.Node(); });
122
- beforeEach(function () {
123
- given.node.addChild(new node_1.Node({ id: 100, name: "child1" }));
124
- });
125
- it("adds the child", function () {
126
- expect(given.node.children).toEqual(expect.arrayContaining([
127
- expect.objectContaining({ id: 100, name: "child1" }),
128
- ]));
129
- });
130
- it("sets the parent of the child", function () {
131
- expect(given.node.children[0].parent).toEqual(given.node);
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
- var given = givens_1["default"]();
136
- given("child", function () { return new node_1.Node("new"); });
137
- given("node", function () { return new node_1.Node("new").loadFromData(["child1", "child2"]); });
138
- beforeEach(function () {
139
- given.node.addChildAtPosition(given.child, given.index);
140
- });
141
- context("with index 0", function () {
142
- given("index", function () { return 0; });
143
- it("adds at the start", function () {
144
- expect(given.node.children).toEqual([
145
- expect.objectContaining({ name: "new" }),
146
- expect.objectContaining({ name: "child1" }),
147
- expect.objectContaining({ name: "child2" }),
148
- ]);
149
- expect(given.node.children).toEqual([
150
- expect.objectContaining({ name: "new" }),
151
- expect.objectContaining({ name: "child1" }),
152
- expect.objectContaining({ name: "child2" }),
153
- ]);
154
- });
155
- });
156
- context("with index 1", function () {
157
- given("index", function () { return 1; });
158
- it("inserts at index 1", function () {
159
- expect(given.node.children).toEqual([
160
- expect.objectContaining({ name: "child1" }),
161
- expect.objectContaining({ name: "new" }),
162
- expect.objectContaining({ name: "child2" }),
163
- ]);
164
- });
165
- });
166
- context("with non existing index", function () {
167
- given("index", function () { return 99; });
168
- it("adds add the end", function () {
169
- expect(given.node.children).toEqual([
170
- expect.objectContaining({ name: "child1" }),
171
- expect.objectContaining({ name: "child2" }),
172
- expect.objectContaining({ name: "new" }),
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
- var given = givens_1["default"]();
179
- given("node1", function () { return new node_1.Node("node1"); });
180
- given("tree", function () { return new node_1.Node({}, true); });
181
- beforeEach(function () {
182
- given.tree.addChild(given.node1);
183
- given.node1.append("child1");
184
- });
185
- it("adds a parent node", function () {
186
- given.node1.addParent("parent1");
187
- expect(given.tree).toMatchObject({
188
- name: "",
189
- children: [
190
- expect.objectContaining({
191
- name: "parent1",
192
- children: [
193
- expect.objectContaining({
194
- name: "node1",
195
- children: [
196
- expect.objectContaining({ name: "child1" }),
197
- ]
198
- }),
199
- ]
200
- }),
201
- ]
202
- });
203
- });
204
- it("returns the new node", function () {
205
- expect(given.node1.addParent("parent1")).toMatchObject({
206
- name: "parent1"
207
- });
208
- });
209
- context("with a root node", function () {
210
- it("returns null", function () {
211
- expect(given.tree.addParent("parent1")).toBeNull();
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
- var given = givens_1["default"]();
217
- given("node", function () { return new node_1.Node("node1"); });
218
- it("appends a node", function () {
219
- given.node.append("child1");
220
- given.node.append("child2");
221
- expect(given.node).toMatchObject({
222
- name: "node1",
223
- children: [
224
- expect.objectContaining({ name: "child1" }),
225
- expect.objectContaining({ name: "child2" }),
226
- ]
227
- });
228
- });
229
- it("returns the new node", function () {
230
- expect(given.node.append("child1")).toMatchObject({ name: "child1" });
231
- });
232
- context("when adding a node with children", function () {
233
- it("adds the children", function () {
234
- given.node.append({
235
- name: "new node",
236
- children: ["newchild1", "newchild2"]
237
- });
238
- expect(given.node).toMatchObject({
239
- children: [
240
- expect.objectContaining({
241
- name: "new node",
242
- children: [
243
- expect.objectContaining({ name: "newchild1" }),
244
- expect.objectContaining({ name: "newchild2" }),
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
- var given = givens_1["default"]();
254
- given("node", function () {
255
- return given.params === undefined ? new node_1.Node() : new node_1.Node(given.params);
256
- });
257
- context("without parameters", function () {
258
- it("creates a node", function () {
259
- expect(given.node.name).toBe("");
260
- expect(given.node.id).toBeUndefined();
261
- });
262
- });
263
- context("with a string", function () {
264
- given("params", function () { return "n1"; });
265
- it("creates a node", function () {
266
- expect(given.node).toMatchObject({
267
- name: "n1",
268
- children: [],
269
- parent: null
270
- });
271
- expect(given.node).not.toHaveProperty("id");
272
- });
273
- });
274
- context("with an object with a name property", function () {
275
- given("params", function () { return ({
276
- id: 123,
277
- name: "n1"
278
- }); });
279
- it("creates a node", function () {
280
- expect(given.node).toMatchObject({
281
- id: 123,
282
- name: "n1"
283
- });
284
- });
285
- });
286
- context("when the name property is null", function () {
287
- given("params", function () { return ({
288
- name: null
289
- }); });
290
- it("sets the name to an empty string", function () {
291
- expect(given.node.name).toBe("");
292
- });
293
- });
294
- context("with an object with more properties", function () {
295
- given("params", function () { return ({
296
- color: "green",
297
- id: 123,
298
- name: "n1",
299
- url: "/abc"
300
- }); });
301
- it("creates a node", function () {
302
- expect(given.node).toMatchObject({
303
- color: "green",
304
- id: 123,
305
- name: "n1",
306
- url: "/abc"
307
- });
308
- });
309
- });
310
- context("with an object with a label property", function () {
311
- given("params", function () { return ({
312
- id: 123,
313
- label: "n1",
314
- url: "/"
315
- }); });
316
- it("creates a node", function () {
317
- expect(given.node).toMatchObject({
318
- id: 123,
319
- name: "n1",
320
- url: "/"
321
- });
322
- // todo: match object?
323
- expect(given.node).not.toHaveProperty("label");
324
- expect(given.node.children).toHaveLength(0);
325
- expect(given.node.parent).toBeNull();
326
- });
327
- });
328
- context("with an object with a parent", function () {
329
- given("params", function () { return ({
330
- name: "n1",
331
- parent: "abc"
332
- }); });
333
- it("doesn't set the parent", function () {
334
- expect(given.node.name).toBe("n1");
335
- expect(given.node.parent).toBeNull();
336
- });
337
- });
338
- context("with an object with children", function () {
339
- given("params", function () { return ({
340
- name: "n1",
341
- children: ["c"]
342
- }); });
343
- it("doesn't set the children", function () {
344
- // todo: match object?
345
- expect(given.node.name).toBe("n1");
346
- expect(given.node.children).toHaveLength(0);
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
- var given = givens_1["default"]();
352
- given("child2", function () { return new node_1.Node("child2"); });
353
- given("node", function () { return new node_1.Node(); });
354
- beforeEach(function () {
355
- given.node.addChild(new node_1.Node("child1"));
356
- given.node.addChild(given.child2);
357
- given.node.addChild(new node_1.Node("child3"));
358
- });
359
- context("when a child exists", function () {
360
- it("returns the index", function () {
361
- expect(given.node.getChildIndex(given.child2)).toBe(1);
362
- });
363
- });
364
- context("when a child doesn't exist", function () {
365
- it("returns -1", function () {
366
- var nonExistingChild = new node_1.Node("non-existing");
367
- expect(given.node.getChildIndex(nonExistingChild)).toBe(-1);
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
- var given = givens_1["default"]();
373
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
374
- it("returns the tree data", function () {
375
- expect(given.tree.getData()).toEqual([
376
- expect.objectContaining({
377
- name: "node1",
378
- children: [
379
- expect.objectContaining({ name: "child1" }),
380
- expect.objectContaining({ name: "child2" }),
381
- ]
382
- }),
383
- expect.objectContaining({ name: "node2" }),
384
- ]);
385
- });
386
- it("doesn't include internal attributes", function () {
387
- expect(given.tree.getData()[0]).not.toContainAnyKeys([
388
- "element",
389
- "isEmptyFolder",
390
- "parent",
391
- ]);
392
- });
393
- context("with includeParent parameter", function () {
394
- it("returns the tree data including the node itself", function () {
395
- expect(given.tree.getData(true)).toEqual([
396
- expect.objectContaining({
397
- children: [
398
- expect.objectContaining({ name: "node1" }),
399
- expect.objectContaining({ name: "node2" }),
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
- var given = givens_1["default"]();
408
- given("node", function () { return new node_1.Node(); });
409
- context("when a node has no children", function () {
410
- it("returns null", function () {
411
- expect(given.node.getLastChild()).toBeNull();
412
- });
413
- });
414
- context("when a node has children", function () {
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
- given.node.append("child1");
417
- given.node.append("child2");
499
+ var child2 = given.node.children[1];
500
+ child2.is_open = true;
418
501
  });
419
- it("returns the last child", function () {
420
- expect(given.node.getLastChild()).toMatchObject({ name: "child2" });
502
+ it("returns the last child of that child", function () {
503
+ expect(given.node.getLastChild()).toMatchObject({
504
+ name: "child2b"
505
+ });
421
506
  });
422
- context("when its last child is open and has children", function () {
423
- beforeEach(function () {
424
- var child2 = given.node.children[1];
425
- child2.append("child2a");
426
- child2.append("child2b");
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
- var given = givens_1["default"]();
451
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
452
- given("nextNode", function () { return given.fromNode.getNextNode(given.includeChildren); });
453
- context("with includeChildren is true", function () {
454
- given("includeChildren", function () { return true; });
455
- context("with a parent node", function () {
456
- given("fromNode", function () { return given.tree.getNodeByNameMustExist("node1"); });
457
- context("when the parent node is closed", function () {
458
- it("returns the next sibling", function () {
459
- expect(given.nextNode).toMatchObject({ name: "node2" });
460
- });
461
- });
462
- context("when the parent node is open", function () {
463
- beforeEach(function () {
464
- given.fromNode.is_open = true;
465
- });
466
- it("returns the first child", function () {
467
- expect(given.nextNode).toMatchObject({ name: "child1" });
468
- });
469
- });
470
- });
471
- context("with the node is the last child", function () {
472
- given("fromNode", function () {
473
- return given.tree.getNodeByNameMustExist("child2");
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
- var given = givens_1["default"]();
495
- given("node1", function () { return given.tree.getNodeByNameMustExist("node1"); });
496
- given("node2", function () { return given.tree.getNodeByNameMustExist("node2"); });
497
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
498
- context("with a tree", function () {
499
- it("returns null", function () {
500
- expect(given.tree.getNextSibling()).toBeNull();
501
- });
502
- });
503
- context("when the node is the last child", function () {
504
- it("returns null", function () {
505
- expect(given.node2.getNextSibling()).toBeNull();
506
- });
507
- });
508
- context("when the node is the first child", function () {
509
- it("returns the second child", function () {
510
- expect(given.node1.getNextSibling()).toBe(given.node2);
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
- var given = givens_1["default"]();
516
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
517
- context("when a matching node exists", function () {
518
- it("returns the node", function () {
519
- expect(given.tree.getNodeByCallback(function (node) {
520
- return node.name.startsWith("chi");
521
- })).toMatchObject({
522
- name: "child1"
523
- });
524
- });
525
- });
526
- context("when no matching node exists", function () {
527
- it("returns null", function () {
528
- expect(given.tree.getNodeByCallback(function () { return false; })).toBeNull();
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
- var given = givens_1["default"]();
534
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
535
- context("when the node exists", function () {
536
- it("returns the node", function () {
537
- expect(given.tree.getNodeByName("child1")).toMatchObject({
538
- id: 125,
539
- name: "child1"
540
- });
541
- });
542
- });
543
- context("when the node doesn't exist", function () {
544
- it("returns null", function () {
545
- expect(given.tree.getNodeByName("non-existing")).toBeNull();
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
- var given = givens_1["default"]();
551
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
552
- context("when the node exists", function () {
553
- it("returns the node", function () {
554
- expect(given.tree.getNodeByNameMustExist("child1")).toMatchObject({
555
- id: 125,
556
- name: "child1"
557
- });
558
- });
559
- });
560
- context("when the node doesn't exist", function () {
561
- it("throws an exception", function () {
562
- expect(function () {
563
- return given.tree.getNodeByNameMustExist("non-existing");
564
- }).toThrow("Node with name non-existing not found");
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
- var given = givens_1["default"]();
570
- given("child1", function () { return given.tree.getNodeByNameMustExist("child1"); });
571
- given("node1", function () { return given.tree.getNodeByNameMustExist("node1"); });
572
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
573
- context("with a tree", function () {
574
- it("returns null", function () {
575
- expect(given.tree.getParent()).toBeNull();
576
- });
577
- });
578
- context("with a node on the first level", function () {
579
- it("returns null", function () {
580
- expect(given.node1.getParent()).toBeNull();
581
- });
582
- });
583
- context("with a node on the second level", function () {
584
- it("returns the parent", function () {
585
- expect(given.child1.getParent()).toMatchObject({
586
- name: "node1"
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
- var given = givens_1["default"]();
593
- given("node2", function () { return given.tree.getNodeByNameMustExist("node2"); });
594
- given("node3", function () { return given.tree.getNodeByNameMustExist("node3"); });
595
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
596
- context("with a tree", function () {
597
- it("returns null", function () {
598
- expect(given.tree.getPreviousNode()).toBeNull();
599
- });
600
- });
601
- context("when the previous sibling has children", function () {
602
- context("when the previous node is closed", function () {
603
- it("returns the previous sibling", function () {
604
- expect(given.node2.getPreviousNode()).toMatchObject({
605
- name: "node1"
606
- });
607
- });
608
- });
609
- context("when the previous node is open", function () {
610
- beforeEach(function () {
611
- given.tree.getNodeByNameMustExist("node1").is_open = true;
612
- });
613
- it("returns the last child of the previous sibling", function () {
614
- expect(given.node2.getPreviousNode()).toMatchObject({
615
- name: "child2"
616
- });
617
- });
618
- });
619
- });
620
- context("with a node that is the first child", function () {
621
- it("returns the parent", function () {
622
- expect(given.node3.getPreviousNode()).toMatchObject({
623
- name: "node2"
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
- var given = givens_1["default"]();
630
- given("node1", function () { return given.tree.getNodeByNameMustExist("node1"); });
631
- given("node2", function () { return given.tree.getNodeByNameMustExist("node2"); });
632
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
633
- context("with a tree", function () {
634
- it("returns null", function () {
635
- expect(given.tree.getPreviousSibling()).toBeNull();
636
- });
637
- });
638
- context("when the node is the first child", function () {
639
- it("returns null", function () {
640
- expect(given.node1.getPreviousSibling()).toBeNull();
641
- });
642
- });
643
- context("when the node is the second child", function () {
644
- it("returns the first child", function () {
645
- expect(given.node2.getPreviousSibling()).toBe(given.node1);
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
- var given = givens_1["default"]();
651
- given("node", function () { return new node_1.Node(); });
652
- context("when a node has children", function () {
653
- beforeEach(function () {
654
- given.node.addChild(new node_1.Node("child1"));
655
- });
656
- it("returns true", function () {
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
- context("when a node doesn't have children", function () {
661
- it("returns false", function () {
662
- expect(given.node.hasChildren()).toEqual(false);
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
- var given = givens_1["default"]();
668
- given("tree", function () { return new node_1.Node(); });
669
- beforeEach(function () {
670
- given.tree.initFromData({
671
- name: "node1",
672
- id: 1,
673
- children: [
674
- { name: "child1", id: 2 },
675
- { name: "child2", id: 3 },
676
- ]
677
- });
678
- });
679
- it("loads the data", function () {
680
- expect(given.tree).toMatchObject({
681
- id: 1,
682
- name: "node1",
683
- children: [
684
- expect.objectContaining({ id: 2, name: "child1" }),
685
- expect.objectContaining({ id: 3, name: "child2" }),
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
- var given = givens_1["default"]();
692
- given("node", function () { return new node_1.Node(); });
693
- context("when the node has no children", function () {
694
- it("returns false", function () {
695
- expect(given.node.isFolder()).toBe(false);
696
- });
697
- context("when the node is loaded on demand", function () {
698
- beforeEach(function () {
699
- given.node.load_on_demand = true;
700
- });
701
- it("returns false", function () {
702
- expect(given.node.isFolder()).toBe(true);
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
- context("when the node has a child", function () {
707
- beforeEach(function () {
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
- var given = givens_1["default"]();
717
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
718
- given("visited", function () { return []; });
719
- beforeEach(function () {
720
- given.tree.iterate(given.visitor);
721
- });
722
- context("when the visitor function returns true", function () {
723
- var visitAllNodes = function (node, level) {
724
- given.visited.push([node.name, level]);
725
- return true;
726
- };
727
- given("visitor", function () { return visitAllNodes; });
728
- it("visits all nodes", function () {
729
- expect(given.visited).toEqual([
730
- ["node1", 0],
731
- ["child1", 1],
732
- ["child2", 1],
733
- ["node2", 0],
734
- ["node3", 1],
735
- ["child3", 2],
736
- ]);
737
- });
738
- });
739
- context("when the visitor function returns false", function () {
740
- var visitNodes = function (node, level) {
741
- given.visited.push([node.name, level]);
742
- return false;
743
- };
744
- given("visitor", function () { return visitNodes; });
745
- it("stops the iteration for the current node", function () {
746
- expect(given.visited).toEqual([
747
- ["node1", 0],
748
- ["node2", 0],
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
- var given = givens_1["default"]();
755
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
756
- it("creates a tree", function () {
757
- expect(given.tree.children).toEqual([
758
- expect.objectContaining({
759
- id: 123,
760
- intProperty: 1,
761
- name: "node1",
762
- strProperty: "1",
763
- children: [
764
- expect.objectContaining({ id: 125, name: "child1" }),
765
- expect.objectContaining({ id: 126, name: "child2" }),
766
- ]
767
- }),
768
- expect.objectContaining({
769
- id: 124,
770
- intProperty: 3,
771
- name: "node2",
772
- strProperty: "3",
773
- children: [expect.objectContaining({ id: 127, name: "node3" })]
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
- var given = givens_1["default"]();
780
- given("child1", function () { return given.tree.getNodeByNameMustExist("child1"); });
781
- given("child2", function () { return given.tree.getNodeByNameMustExist("child2"); });
782
- given("node1", function () { return given.tree.getNodeByNameMustExist("node1"); });
783
- given("node2", function () { return given.tree.getNodeByNameMustExist("node2"); });
784
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
785
- context("when moving after a node", function () {
786
- it("moves the node", function () {
787
- expect(given.tree.moveNode(given.child2, given.node2, node_1.Position.After)).toBe(true);
788
- expect(given.tree).toMatchObject({
789
- name: "",
790
- children: [
791
- expect.objectContaining({
792
- name: "node1",
793
- children: [expect.objectContaining({ name: "child1" })]
794
- }),
795
- expect.objectContaining({ name: "node2" }),
796
- expect.objectContaining({ name: "child2" }),
797
- ]
798
- });
799
- });
800
- context("when the target is the root node", function () {
801
- it("returns false", function () {
802
- expect(given.tree.moveNode(given.child2, given.tree, node_1.Position.After)).toBe(false);
803
- });
804
- });
805
- });
806
- context("when moving inside a node", function () {
807
- it("moves the node", function () {
808
- expect(given.tree.moveNode(given.child1, given.node2, node_1.Position.Inside)).toBe(true);
809
- expect(given.tree).toMatchObject({
810
- name: "",
811
- children: [
812
- expect.objectContaining({
813
- name: "node1",
814
- children: [expect.objectContaining({ name: "child2" })]
815
- }),
816
- expect.objectContaining({
817
- name: "node2",
818
- children: [
819
- expect.objectContaining({ name: "child1" }),
820
- expect.objectContaining({ name: "node3" }),
821
- ]
822
- }),
823
- ]
824
- });
825
- });
826
- });
827
- context("when moving before a node", function () {
828
- it("moves the node", function () {
829
- expect(given.tree.moveNode(given.child2, given.child1, node_1.Position.Before)).toBe(true);
830
- expect(given.tree).toMatchObject({
831
- name: "",
832
- children: [
833
- expect.objectContaining({
834
- name: "node1",
835
- children: [
836
- expect.objectContaining({ name: "child2" }),
837
- expect.objectContaining({ name: "child1" }),
838
- ]
839
- }),
840
- expect.objectContaining({ name: "node2" }),
841
- ]
842
- });
843
- });
844
- context("when the target is the root node", function () {
845
- it("returns false", function () {
846
- expect(given.tree.moveNode(given.child2, given.tree, node_1.Position.Before)).toBe(false);
847
- });
848
- });
849
- });
850
- context("when the moved node is a parent of the target node", function () {
851
- it("doesn't move the node", function () {
852
- expect(given.tree.moveNode(given.node1, given.child1, node_1.Position.Before)).toBe(false);
853
- expect(given.tree).toMatchObject({
854
- children: [
855
- expect.objectContaining({
856
- name: "node1",
857
- children: [
858
- expect.objectContaining({ name: "child1" }),
859
- expect.objectContaining({ name: "child2" }),
860
- ]
861
- }),
862
- expect.objectContaining({ name: "node2" }),
863
- ]
864
- });
865
- });
866
- });
867
- context("with position None", function () {
868
- it("returns false", function () {
869
- expect(given.tree.moveNode(given.child2, given.node2, node_1.Position.None)).toBe(false);
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
- var given = givens_1["default"]();
875
- given("node", function () { return new node_1.Node("node1"); });
876
- it("prepends a node", function () {
877
- given.node.prepend("child2");
878
- given.node.prepend("child1");
879
- expect(given.node).toMatchObject({
880
- name: "node1",
881
- children: [
882
- expect.objectContaining({ name: "child1" }),
883
- expect.objectContaining({ name: "child2" }),
884
- ]
885
- });
886
- });
887
- context("when prepending a node with children", function () {
888
- it("adds the children", function () {
889
- given.node.prepend({
890
- name: "new node",
891
- children: ["newchild1", "newchild2"]
892
- });
893
- expect(given.node).toMatchObject({
894
- children: [
895
- expect.objectContaining({
896
- name: "new node",
897
- children: [
898
- expect.objectContaining({ name: "newchild1" }),
899
- expect.objectContaining({ name: "newchild2" }),
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
- var given = givens_1["default"]();
909
- given("child1", function () { return given.tree.getNodeByNameMustExist("child1"); });
910
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
911
- beforeEach(function () {
912
- given.child1.remove();
913
- });
914
- it("removes the node", function () {
915
- expect(given.tree).toMatchObject({
916
- children: [
917
- expect.objectContaining({
918
- name: "node1",
919
- children: [expect.objectContaining({ name: "child2" })]
920
- }),
921
- expect.objectContaining({ name: "node2" }),
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
- var given = givens_1["default"]();
928
- given("child1", function () { return given.tree.getNodeByNameMustExist("child1"); });
929
- given("node1", function () { return given.tree.getNodeByNameMustExist("node1"); });
930
- given("tree", function () { return new node_1.Node().loadFromData(exampleData_1["default"]); });
931
- beforeEach(function () {
932
- given.node1.removeChild(given.child1);
933
- });
934
- it("removes the child", function () {
935
- expect(given.node1.children).toEqual([
936
- expect.objectContaining({ name: "child2" }),
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
+ });