58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
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);
|
|
});
|
|
});
|
|
|
|
}
|