Normalize root scene nodes and fix level duplication

This commit is contained in:
sudhir
2026-04-29 12:53:40 +05:30
parent 9ff657419c
commit e761084635
7 changed files with 204 additions and 18 deletions
@@ -401,6 +401,27 @@ describe('SceneBridge', () => {
})
describe('setScene / exportJSON / loadJSON', () => {
test('setScene prunes duplicated levels that were accidentally saved as roots', () => {
const level0 = LevelNode.parse({ level: 0, children: [] })
const building = BuildingNode.parse({ children: [level0.id] })
const site = SiteNode.parse({ children: [building] })
const orphanLevel = LevelNode.parse({ level: 1, children: [] })
bridge.setScene(
{
[site.id]: site,
[building.id]: building,
[level0.id]: level0,
[orphanLevel.id]: orphanLevel,
} as any,
[site.id, orphanLevel.id] as any,
)
expect(bridge.getRootNodeIds()).toEqual([site.id])
expect(bridge.getNode(orphanLevel.id)).toBeNull()
expect(bridge.findNodes({ type: 'level' }).map((node) => node.id)).toEqual([level0.id])
})
test('exportJSON returns the scene shape', () => {
const exp = bridge.exportJSON()
expect(typeof exp.nodes).toBe('object')