forked from jappel/leistungsbilanz-ts
tsx runs tests without type checking and tsconfig.json covers only src, so 71 type errors had accumulated unnoticed. tsconfig.tests.json now checks every test and helper, and npm run typecheck includes it. Fixtures gain the fields the DTOs have grown since they were written (manualQuantity, circuit apparent power/cos phi, downstream board loads, section totals, building, cover and board info fields). Repository lookups that return "row ?? null" now declare the null in their type, which their callers already handle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
148 lines
3.8 KiB
TypeScript
148 lines
3.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import { buildCircuitStructureProjection } from "../src/frontend/utils/circuit-structure-projection.js";
|
|
import type {
|
|
CircuitTreeCircuitDto,
|
|
CircuitTreeComponentDto,
|
|
CircuitTreeSectionDto,
|
|
} from "../src/frontend/types.js";
|
|
|
|
function component(
|
|
id: string,
|
|
placement: CircuitTreeComponentDto["placement"],
|
|
sortOrder: number,
|
|
sectionId?: string
|
|
): CircuitTreeComponentDto {
|
|
return {
|
|
id,
|
|
circuitListId: "list-1",
|
|
sectionId,
|
|
equipmentIdentifier: `-${id}`,
|
|
name: id,
|
|
role:
|
|
placement === "header"
|
|
? "main_switch"
|
|
: placement === "footer"
|
|
? "auxiliary"
|
|
: "group_residual_current_protection",
|
|
placement,
|
|
sortOrder,
|
|
};
|
|
}
|
|
|
|
function circuit(
|
|
id: string,
|
|
sectionId: string
|
|
): CircuitTreeCircuitDto {
|
|
return {
|
|
id,
|
|
circuitListId: "list-1",
|
|
sectionId,
|
|
equipmentIdentifier: `-${id}`,
|
|
sortOrder: 10,
|
|
isReserve: true,
|
|
circuitTotalPower: 0,
|
|
circuitApparentPower: 0,
|
|
circuitCosPhi: 1,
|
|
deviceRows: [],
|
|
downstreamBoardLoads: [],
|
|
};
|
|
}
|
|
|
|
function section(
|
|
id: string,
|
|
sortOrder: number
|
|
): CircuitTreeSectionDto {
|
|
return {
|
|
id,
|
|
key: id,
|
|
displayName: id,
|
|
prefix: "-1F1.",
|
|
sortOrder,
|
|
category: "lighting",
|
|
groupNumber: sortOrder / 10,
|
|
sectionTotalPower: 0,
|
|
components: [
|
|
component(`${id}-rcd-late`, "group", 20, id),
|
|
component(`${id}-rcd-first`, "group", 10, id),
|
|
],
|
|
circuits: [circuit(`${id}-circuit`, id)],
|
|
};
|
|
}
|
|
|
|
describe("circuit structure projection", () => {
|
|
it("projects fixed header, complete groups and auxiliary footer in stable order", () => {
|
|
const rows = buildCircuitStructureProjection({
|
|
headerComponents: [
|
|
component("surge", "header", 20),
|
|
component("main", "header", 10),
|
|
],
|
|
sections: [section("group-2", 20), section("group-1", 10)],
|
|
footerComponents: [
|
|
component("actor-2", "footer", 20),
|
|
component("actor-1", "footer", 10),
|
|
],
|
|
});
|
|
assert.deepEqual(
|
|
rows.map((row) => row.rowKey),
|
|
[
|
|
"header-component:main",
|
|
"header-component:surge",
|
|
"group:group-1",
|
|
"group-component:group-1-rcd-first",
|
|
"group-component:group-1-rcd-late",
|
|
"circuit-block:group-1-circuit",
|
|
"group-placeholder:group-1",
|
|
"group:group-2",
|
|
"group-component:group-2-rcd-first",
|
|
"group-component:group-2-rcd-late",
|
|
"circuit-block:group-2-circuit",
|
|
"group-placeholder:group-2",
|
|
"footer-component:actor-1",
|
|
"footer-component:actor-2",
|
|
]
|
|
);
|
|
});
|
|
|
|
it("keeps structural rows around an empty group", () => {
|
|
const empty = section("group-empty", 10);
|
|
empty.components = [];
|
|
empty.circuits = [];
|
|
assert.deepEqual(
|
|
buildCircuitStructureProjection({
|
|
headerComponents: [],
|
|
sections: [empty],
|
|
footerComponents: [],
|
|
}).map((row) => row.rowType),
|
|
["groupHeader", "groupPlaceholder"]
|
|
);
|
|
});
|
|
|
|
it("keeps circuit device rows inside their circuit block", () => {
|
|
const grouped = section("group-1", 10);
|
|
grouped.circuits[0].deviceRows = [
|
|
{
|
|
id: "device-1",
|
|
sortOrder: 10,
|
|
name: "Leuchte",
|
|
displayName: "Leuchte",
|
|
quantity: 1,
|
|
manualQuantity: 1,
|
|
powerPerUnit: 0.1,
|
|
simultaneityFactor: 1,
|
|
rowTotalPower: 0.1,
|
|
},
|
|
];
|
|
const block = buildCircuitStructureProjection({
|
|
headerComponents: [],
|
|
sections: [grouped],
|
|
footerComponents: [],
|
|
}).find((row) => row.rowType === "circuitBlock");
|
|
assert.equal(
|
|
block?.rowType === "circuitBlock"
|
|
? block.circuit.deviceRows[0].id
|
|
: null,
|
|
"device-1"
|
|
);
|
|
});
|
|
});
|