Skip to content

Commit d8fa03b

Browse files
committed
Add tests for fix and a comment on depth
1 parent e451e40 commit d8fa03b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/utils/tree-data-utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ function addNodeAtDepthAndIndex({
741741
* Insert a node into the tree at the given depth, after the minimum index
742742
*
743743
* @param {!Object[]} treeData - Tree data
744-
* @param {!number} depth - The depth to insert the node at
744+
* @param {!number} depth - The depth to insert the node at (the first level of the array being depth 0)
745745
* @param {!number} minimumTreeIndex - The lowest possible treeIndex to insert the node at
746746
* @param {!Object} newNode - The node to insert into the tree
747747
* @param {boolean=} ignoreCollapsed - Ignore children of nodes without `expanded` set to `true`

src/utils/tree-data-utils.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,45 @@ describe('insertNode', () => {
13501350
path: [1, 3, 4],
13511351
});
13521352
});
1353+
1354+
it('should work with nodes with an empty children array', () => {
1355+
expect(insertNode({
1356+
treeData: [
1357+
{
1358+
expanded: true,
1359+
children: [
1360+
{
1361+
expanded: true,
1362+
children: [
1363+
{ children: [] },
1364+
],
1365+
},
1366+
],
1367+
},
1368+
],
1369+
newNode: { key: 'new' },
1370+
depth: 2,
1371+
minimumTreeIndex: 2,
1372+
getNodeKey: keyFromTreeIndex,
1373+
})).toEqual({
1374+
treeData: [
1375+
{
1376+
expanded: true,
1377+
children: [
1378+
{
1379+
expanded: true,
1380+
children: [
1381+
{ key: 'new' },
1382+
{ children: [] },
1383+
],
1384+
},
1385+
],
1386+
},
1387+
],
1388+
treeIndex: 2,
1389+
path: [0, 1, 2],
1390+
});
1391+
});
13531392
});
13541393

13551394
describe('walk', () => {

0 commit comments

Comments
 (0)