import * as assert from 'assert'; import * as OV from '../../source/engine/main.js'; import { GetHierarchicalModelNoFinalization } from '../utils/testutils.js'; import { StepDeletionState } from '../../source/website/stepdeletionstate.js'; export default function suite () { describe ('StepDeletionState', function () { it ('builds stable child-index paths', function () { let model = GetHierarchicalModelNoFinalization (); let state = new StepDeletionState (model); assert.strictEqual (state.GetNodePath (0), ''); assert.strictEqual (state.GetNodePath (1), '0'); assert.strictEqual (state.GetNodePath (2), '1'); assert.strictEqual (state.GetNodePath (3), '0/0'); assert.strictEqual (state.GetNodePath (4), '0/1'); }); it ('normalizes subtree deletions', function () { let model = GetHierarchicalModelNoFinalization (); let state = new StepDeletionState (model); state.DeleteNodePath ('0'); state.DeleteNodePath ('0/0'); state.DeleteNodePath ('1'); assert.deepStrictEqual (state.GetDeletedNodePaths (), ['0', '1']); assert.ok (state.IsNodeDeletedByPath ('0/0')); assert.ok (state.IsNodeDeletedByPath ('0/1')); assert.ok (!state.IsNodeDeletedByPath ('')); }); it ('maps mesh-backed leaf parts to their owning node path', function () { let model = GetHierarchicalModelNoFinalization (); let state = new StepDeletionState (model); let meshInstanceId = new OV.MeshInstanceId (3, 4); assert.strictEqual (state.GetMeshNodePath (meshInstanceId), '0/0'); state.DeleteMeshNode (meshInstanceId); assert.deepStrictEqual (state.GetDeletedNodePaths (), ['0/0']); }); it ('keeps root undeletable while regular nodes stay deletable', function () { let model = GetHierarchicalModelNoFinalization (); let state = new StepDeletionState (model); assert.strictEqual (state.CanDeleteNode (0), false); assert.strictEqual (state.CanDeleteNode (1), true); assert.strictEqual (state.CanDeleteNode (3), true); }); it ('orders assembly nodes before leaf parts when building deletion paths', function () { let model = new OV.Model (); let root = model.GetRootNode (); let leafPartMeshIndex = model.AddMesh (new OV.Mesh ()); let leafPart = new OV.Node (); leafPart.SetName ('Leaf Part'); root.AddChildNode (leafPart); leafPart.AddMeshIndex (leafPartMeshIndex); let assembly = new OV.Node (); assembly.SetName ('Assembly'); root.AddChildNode (assembly); let assemblyLeafPartMeshIndex = model.AddMesh (new OV.Mesh ()); let assemblyLeafPart = new OV.Node (); assemblyLeafPart.SetName ('Assembly Leaf Part'); assembly.AddChildNode (assemblyLeafPart); assemblyLeafPart.AddMeshIndex (assemblyLeafPartMeshIndex); let state = new StepDeletionState (model); assert.strictEqual (state.GetNodePath (assembly.GetId ()), '0'); assert.strictEqual (state.GetNodePath (assemblyLeafPart.GetId ()), '0/0'); assert.strictEqual (state.GetNodePath (leafPart.GetId ()), '1'); assert.strictEqual (state.GetMeshNodePath (new OV.MeshInstanceId (leafPart.GetId (), leafPartMeshIndex)), '1'); }); }); }