86 lines
2.4 KiB
TypeScript
86 lines
2.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import {
|
|
getInsertionSortOrder,
|
|
resolveGridInsertionIntent,
|
|
} from "../src/frontend/utils/circuit-grid-insertion.js";
|
|
|
|
describe("circuit grid insertion", () => {
|
|
it("inserts a circuit after circuit-level selections", () => {
|
|
assert.deepEqual(
|
|
resolveGridInsertionIntent(
|
|
{
|
|
rowType: "circuitCompact",
|
|
cellKind: "circuitField",
|
|
sectionId: "section-1",
|
|
circuitId: "circuit-1",
|
|
deviceId: "row-1",
|
|
},
|
|
"fallback"
|
|
),
|
|
{ kind: "circuit", sectionId: "section-1", afterCircuitId: "circuit-1" }
|
|
);
|
|
});
|
|
|
|
it("inserts a device after device-level selections in compact and expanded circuits", () => {
|
|
assert.deepEqual(
|
|
resolveGridInsertionIntent({
|
|
rowType: "circuitCompact",
|
|
cellKind: "deviceField",
|
|
sectionId: "section-1",
|
|
circuitId: "circuit-1",
|
|
deviceId: "row-1",
|
|
}),
|
|
{
|
|
kind: "device",
|
|
sectionId: "section-1",
|
|
circuitId: "circuit-1",
|
|
afterDeviceRowId: "row-1",
|
|
}
|
|
);
|
|
assert.deepEqual(
|
|
resolveGridInsertionIntent({
|
|
rowType: "deviceRow",
|
|
cellKind: "deviceField",
|
|
sectionId: "section-1",
|
|
circuitId: "circuit-1",
|
|
deviceId: "row-2",
|
|
}),
|
|
{
|
|
kind: "device",
|
|
sectionId: "section-1",
|
|
circuitId: "circuit-1",
|
|
afterDeviceRowId: "row-2",
|
|
}
|
|
);
|
|
});
|
|
|
|
it("uses the active section for placeholders and missing selections", () => {
|
|
assert.deepEqual(
|
|
resolveGridInsertionIntent({
|
|
rowType: "placeholder",
|
|
cellKind: "deviceField",
|
|
sectionId: "section-1",
|
|
}),
|
|
{ kind: "circuit", sectionId: "section-1" }
|
|
);
|
|
assert.deepEqual(resolveGridInsertionIntent(null, "section-2"), {
|
|
kind: "circuit",
|
|
sectionId: "section-2",
|
|
});
|
|
});
|
|
|
|
it("creates stable sort values between neighbours or at the end", () => {
|
|
const entries = [
|
|
{ id: "a", sortOrder: 10 },
|
|
{ id: "b", sortOrder: 20 },
|
|
{ id: "c", sortOrder: 30 },
|
|
];
|
|
|
|
assert.equal(getInsertionSortOrder(entries, "a"), 15);
|
|
assert.equal(getInsertionSortOrder(entries, "c"), 40);
|
|
assert.equal(getInsertionSortOrder(entries), 40);
|
|
assert.equal(getInsertionSortOrder([], "missing"), 10);
|
|
});
|
|
});
|