88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import {
|
|
findDuplicateEquipmentIdentifierCircuitIds,
|
|
hasEquipmentIdentifierConflict,
|
|
requiresCrossSectionMoveConfirmation,
|
|
resolveGridDeleteIntent,
|
|
} from "../src/frontend/utils/circuit-grid-safety.js";
|
|
|
|
describe("circuit grid safety", () => {
|
|
it("deletes only the device for device-level selections", () => {
|
|
assert.deepEqual(
|
|
resolveGridDeleteIntent({
|
|
rowType: "circuitCompact",
|
|
cellKind: "deviceField",
|
|
circuitId: "circuit-1",
|
|
deviceId: "device-1",
|
|
}),
|
|
{ kind: "device", deviceId: "device-1" }
|
|
);
|
|
assert.deepEqual(
|
|
resolveGridDeleteIntent({
|
|
rowType: "deviceRow",
|
|
cellKind: "deviceField",
|
|
circuitId: "circuit-1",
|
|
deviceId: "device-2",
|
|
}),
|
|
{ kind: "device", deviceId: "device-2" }
|
|
);
|
|
});
|
|
|
|
it("deletes the whole circuit for circuit-level selections", () => {
|
|
assert.deepEqual(
|
|
resolveGridDeleteIntent({
|
|
rowType: "circuitCompact",
|
|
cellKind: "circuitField",
|
|
circuitId: "circuit-1",
|
|
deviceId: "device-1",
|
|
}),
|
|
{ kind: "circuit", circuitId: "circuit-1" }
|
|
);
|
|
assert.deepEqual(
|
|
resolveGridDeleteIntent({
|
|
rowType: "reserveCircuit",
|
|
cellKind: "deviceField",
|
|
circuitId: "circuit-2",
|
|
}),
|
|
{ kind: "circuit", circuitId: "circuit-2" }
|
|
);
|
|
});
|
|
|
|
it("does nothing on the free placeholder", () => {
|
|
assert.equal(
|
|
resolveGridDeleteIntent({ rowType: "placeholder", cellKind: "deviceField" }),
|
|
null
|
|
);
|
|
});
|
|
|
|
it("detects normalized BMK conflicts while excluding the edited circuit", () => {
|
|
const circuits = [
|
|
{ id: "a", equipmentIdentifier: "-2F1" },
|
|
{ id: "b", equipmentIdentifier: "-2F2" },
|
|
];
|
|
|
|
assert.equal(hasEquipmentIdentifierConflict(circuits, "b", " -2f1 "), true);
|
|
assert.equal(hasEquipmentIdentifierConflict(circuits, "a", "-2f1"), false);
|
|
assert.equal(hasEquipmentIdentifierConflict(circuits, "b", "-2F3"), false);
|
|
});
|
|
|
|
it("returns every circuit participating in a normalized duplicate", () => {
|
|
assert.deepEqual(
|
|
findDuplicateEquipmentIdentifierCircuitIds([
|
|
{ id: "a", equipmentIdentifier: "-2F1" },
|
|
{ id: "b", equipmentIdentifier: " -2f1 " },
|
|
{ id: "c", equipmentIdentifier: "-2F2" },
|
|
]).sort(),
|
|
["a", "b"]
|
|
);
|
|
});
|
|
|
|
it("requires confirmation when any moved device crosses a section boundary", () => {
|
|
assert.equal(requiresCrossSectionMoveConfirmation(["single"], "single"), false);
|
|
assert.equal(requiresCrossSectionMoveConfirmation(["single", "single"], "single"), false);
|
|
assert.equal(requiresCrossSectionMoveConfirmation(["single"], "three"), true);
|
|
assert.equal(requiresCrossSectionMoveConfirmation(["single", "three"], "three"), true);
|
|
});
|
|
});
|