146 lines
4.3 KiB
TypeScript
146 lines
4.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import {
|
|
defaultMainSwitchComponent,
|
|
defaultSurgeProtectiveDeviceComponent,
|
|
distributionBoardComponentPlacements,
|
|
distributionBoardComponentRoles,
|
|
} from "../src/shared/constants/distribution-board-component.js";
|
|
import { circuitGroupCategories } from "../src/shared/constants/circuit-group.js";
|
|
import {
|
|
buildDistributionBoardComponentSnapshot,
|
|
getNextComponentSortOrder,
|
|
getSuggestedGroupComponentIdentifier,
|
|
toDistributionBoardComponentSnapshot,
|
|
updateDistributionBoardComponentSnapshot,
|
|
} from "../src/frontend/utils/distribution-board-component-editing.js";
|
|
import "./distribution-board-component-structure-project-command.repository.test.js";
|
|
|
|
describe("distribution board component catalog", () => {
|
|
it("defines the agreed component roles and placement zones", () => {
|
|
assert.deepEqual(distributionBoardComponentRoles, [
|
|
"main_switch",
|
|
"surge_protective_device",
|
|
"group_upstream_protection",
|
|
"group_residual_current_protection",
|
|
"auxiliary",
|
|
]);
|
|
assert.deepEqual(distributionBoardComponentPlacements, [
|
|
"header",
|
|
"group",
|
|
"footer",
|
|
]);
|
|
});
|
|
|
|
it("defines exactly the three supported circuit group categories", () => {
|
|
assert.deepEqual(circuitGroupCategories, [
|
|
"lighting",
|
|
"single_phase",
|
|
"three_phase",
|
|
]);
|
|
});
|
|
|
|
it("provides the fixed header component defaults", () => {
|
|
assert.deepEqual(defaultMainSwitchComponent, {
|
|
equipmentIdentifier: "-Q0",
|
|
name: "Hauptschalter",
|
|
role: "main_switch",
|
|
placement: "header",
|
|
});
|
|
assert.deepEqual(defaultSurgeProtectiveDeviceComponent, {
|
|
equipmentIdentifier: "-FA",
|
|
name: "Überspannungsableiter",
|
|
role: "surge_protective_device",
|
|
placement: "header",
|
|
});
|
|
});
|
|
|
|
it("builds exact editable component snapshots for persistent commands", () => {
|
|
const groupRcd = buildDistributionBoardComponentSnapshot({
|
|
id: "component-1",
|
|
circuitListId: "list-1",
|
|
role: "group_residual_current_protection",
|
|
sectionId: "section-1",
|
|
sortOrder: 20,
|
|
values: {
|
|
equipmentIdentifier: " -1Q1.0 ",
|
|
name: " Gruppen-FI ",
|
|
protectionDevice: {
|
|
type: "FI",
|
|
ratedCurrentA: 40,
|
|
rcdType: "A",
|
|
ratedResidualCurrentMa: 30,
|
|
},
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(groupRcd, {
|
|
component: {
|
|
id: "component-1",
|
|
circuitListId: "list-1",
|
|
sectionId: "section-1",
|
|
equipmentIdentifier: "-1Q1.0",
|
|
name: "Gruppen-FI",
|
|
role: "group_residual_current_protection",
|
|
placement: "group",
|
|
sortOrder: 20,
|
|
},
|
|
protectionDevice: {
|
|
componentId: "component-1",
|
|
type: "FI",
|
|
ratedCurrentA: 40,
|
|
fuseUtilizationCategory: null,
|
|
tripCharacteristic: null,
|
|
rcdType: "A",
|
|
ratedResidualCurrentMa: 30,
|
|
},
|
|
});
|
|
assert.deepEqual(
|
|
updateDistributionBoardComponentSnapshot(groupRcd, {
|
|
equipmentIdentifier: "-1Q1.0",
|
|
name: "FI Beleuchtung",
|
|
protectionDevice: {
|
|
type: "FI",
|
|
ratedCurrentA: 63,
|
|
rcdType: "B+",
|
|
ratedResidualCurrentMa: 300,
|
|
},
|
|
}).component,
|
|
{ ...groupRcd.component, name: "FI Beleuchtung" }
|
|
);
|
|
});
|
|
|
|
it("maps tree DTOs and derives stable group suggestions and sort positions", () => {
|
|
const snapshot = toDistributionBoardComponentSnapshot({
|
|
id: "actor-1",
|
|
circuitListId: "list-1",
|
|
equipmentIdentifier: "-K1",
|
|
name: "KNX Aktor",
|
|
role: "auxiliary",
|
|
placement: "footer",
|
|
sortOrder: 10,
|
|
});
|
|
assert.equal(snapshot.component.sectionId, null);
|
|
assert.equal(snapshot.protectionDevice, null);
|
|
assert.equal(getNextComponentSortOrder([{ sortOrder: 10 }, { sortOrder: 40 }]), 50);
|
|
assert.equal(
|
|
getSuggestedGroupComponentIdentifier(
|
|
{
|
|
id: "section-1",
|
|
key: "lighting",
|
|
displayName: "Beleuchtung 2",
|
|
prefix: "-1F2",
|
|
sortOrder: 10,
|
|
category: "lighting",
|
|
groupNumber: 2,
|
|
sectionTotalPower: 0,
|
|
components: [],
|
|
circuits: [],
|
|
},
|
|
"group_upstream_protection"
|
|
),
|
|
"-1F2.0"
|
|
);
|
|
});
|
|
});
|