File tree 2 files changed +42
-2
lines changed
2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -610,7 +610,8 @@ function addNodeAtDepthAndIndex({
610
610
}
611
611
612
612
// If the current position is the only possible place to add, add it
613
- if ( currentIndex >= minimumTreeIndex - 1 || ( isLastChild && ! node . children ) ) {
613
+ if ( currentIndex >= minimumTreeIndex - 1
614
+ || ( isLastChild && ! ( node . children && node . children . length ) ) ) {
614
615
if ( typeof node . children === 'function' ) {
615
616
throw new Error ( 'Cannot add to children defined by a function' ) ;
616
617
} else {
@@ -740,7 +741,7 @@ function addNodeAtDepthAndIndex({
740
741
* Insert a node into the tree at the given depth, after the minimum index
741
742
*
742
743
* @param {!Object[] } treeData - Tree data
743
- * @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)
744
745
* @param {!number } minimumTreeIndex - The lowest possible treeIndex to insert the node at
745
746
* @param {!Object } newNode - The node to insert into the tree
746
747
* @param {boolean= } ignoreCollapsed - Ignore children of nodes without `expanded` set to `true`
Original file line number Diff line number Diff line change @@ -1350,6 +1350,45 @@ describe('insertNode', () => {
1350
1350
path : [ 1 , 3 , 4 ] ,
1351
1351
} ) ;
1352
1352
} ) ;
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
+ } ) ;
1353
1392
} ) ;
1354
1393
1355
1394
describe ( 'walk' , ( ) => {
You can’t perform that action at this time.
0 commit comments