11import { describe , test , expect } from "@jest/globals" ;
22import { updateCells } from "./updateCells" ;
33import { SYMBOL_FOR_SIZE_INITIALIZED } from "../constants" ;
4- import { DecoratorView } from "../interfaces" ;
4+ import { Cell , DecoratorView } from "../interfaces" ;
55
66describe ( "updateCells" , ( ) => {
77 test ( "add related nodes on right side of siblings" , ( ) => {
@@ -134,8 +134,8 @@ describe("updateCells", () => {
134134 id : "4" ,
135135 type : "node" ,
136136 view : {
137- x : 316 ,
138- y : 100 ,
137+ x : 256 ,
138+ y : 160 ,
139139 height : 80 ,
140140 width : 120 ,
141141 } ,
@@ -146,8 +146,8 @@ describe("updateCells", () => {
146146 id : "4" ,
147147 type : "node" ,
148148 view : {
149- x : 316 ,
150- y : 100 ,
149+ x : 256 ,
150+ y : 160 ,
151151 height : 80 ,
152152 width : 120 ,
153153 } ,
@@ -862,4 +862,73 @@ describe("updateCells", () => {
862862 shouldReCenter : false ,
863863 } ) ;
864864 } ) ;
865+
866+ test ( "siblings alternate left-right placement" , ( ) => {
867+ const result = updateCells ( {
868+ cells : [
869+ { type : "edge" , source : "1" , target : "2" } ,
870+ { type : "edge" , source : "1" , target : "3" } ,
871+ { type : "edge" , source : "1" , target : "4" } ,
872+ { type : "edge" , source : "1" , target : "5" } ,
873+ { type : "edge" , source : "2" , target : "6" } ,
874+ { type : "edge" , source : "2" , target : "7" } ,
875+ {
876+ id : "1" ,
877+ type : "node" ,
878+ view : { x : 200 , y : 50 , height : 100 , width : 60 } ,
879+ } ,
880+ { id : "2" , type : "node" } ,
881+ { id : "3" , type : "node" } ,
882+ { id : "4" , type : "node" } ,
883+ { id : "5" , type : "node" } ,
884+ { id : "6" , type : "node" } ,
885+ ] ,
886+ previousCells : [ ] ,
887+ defaultNodeSize : [ 100 , 60 ] ,
888+ canvasWidth : 800 ,
889+ canvasHeight : 600 ,
890+ scaleRange : [ 0.5 , 2 ] ,
891+ transform : { k : 1 , x : 0 , y : 0 } ,
892+ layoutOptions : {
893+ initialLayout : "layered-staggered" ,
894+ } ,
895+ reason : "add-related-nodes" ,
896+ parentNode : {
897+ id : "1" ,
898+ type : "node" ,
899+ view : { x : 200 , y : 50 , height : 100 , width : 60 } ,
900+ } ,
901+ } ) ;
902+ const views = result . updated . map ( ( n ) => n ?. view ?. x ) ;
903+ expect ( new Set ( views ) . size ) . toBe ( 4 ) ;
904+ } ) ;
905+
906+ test ( "missing parent falls back to default layout" , ( ) => {
907+ const result = updateCells ( {
908+ cells : [
909+ {
910+ id : "1" ,
911+ type : "node" ,
912+ view : { x : 200 , y : 50 , height : 100 , width : 60 } ,
913+ } ,
914+ { id : "2" , type : "node" } ,
915+ ] ,
916+ previousCells : [
917+ {
918+ id : "1" ,
919+ type : "node" ,
920+ view : { x : 200 , y : 50 , height : 100 , width : 60 } ,
921+ } ,
922+ { id : "2" , type : "node" } as Cell ,
923+ ] ,
924+ defaultNodeSize : [ 120 , 80 ] ,
925+ canvasWidth : 800 ,
926+ canvasHeight : 600 ,
927+ scaleRange : [ 0.5 , 2 ] ,
928+ transform : { k : 1 , x : 0 , y : 0 } ,
929+ reason : "add-related-nodes" ,
930+ } ) ;
931+ expect ( result . updated . length ) . toBeGreaterThan ( 0 ) ;
932+ expect ( result . shouldReCenter ) . toBe ( true ) ;
933+ } ) ;
865934} ) ;
0 commit comments