Configure circuit protection
This commit is contained in:
@@ -11,6 +11,7 @@ import { CircuitDeviceRowMoveProjectCommandRepository } from "../src/db/reposito
|
||||
import { DistributionBoardFixtureRepository } from "./support/distribution-board-fixture.js";
|
||||
import { ProjectHistoryRepository } from "../src/db/repositories/project-history.repository.js";
|
||||
import { circuitDeviceRows } from "../src/db/schema/circuit-device-rows.js";
|
||||
import { circuitProtectionDevices } from "../src/db/schema/circuit-protection-devices.js";
|
||||
import { circuitSections } from "../src/db/schema/circuit-sections.js";
|
||||
import { circuits } from "../src/db/schema/circuits.js";
|
||||
import { projectRevisions } from "../src/db/schema/project-revisions.js";
|
||||
@@ -193,6 +194,15 @@ function createMoveTargetSnapshot(
|
||||
isReserve: true,
|
||||
remark: null,
|
||||
deviceRows: [],
|
||||
protectionDevice: {
|
||||
circuitId: "circuit-new",
|
||||
type: "LS",
|
||||
ratedCurrentA: 10,
|
||||
fuseUtilizationCategory: null,
|
||||
tripCharacteristic: "B",
|
||||
rcdType: null,
|
||||
ratedResidualCurrentMa: null,
|
||||
},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -520,6 +530,14 @@ describe("circuit device-row move project-command repository", () => {
|
||||
"-1F4"
|
||||
);
|
||||
assert.equal(isReserve(fixture.context, "circuit-new"), false);
|
||||
assert.equal(
|
||||
fixture.context.db
|
||||
.select({ ratedCurrentA: circuitProtectionDevices.ratedCurrentA })
|
||||
.from(circuitProtectionDevices)
|
||||
.where(eq(circuitProtectionDevices.circuitId, "circuit-new"))
|
||||
.get()?.ratedCurrentA,
|
||||
10
|
||||
);
|
||||
assert.equal(isReserve(fixture.context, "circuit-1"), false);
|
||||
assert.equal(isReserve(fixture.context, "circuit-2"), true);
|
||||
|
||||
@@ -538,6 +556,14 @@ describe("circuit device-row move project-command repository", () => {
|
||||
.get(),
|
||||
undefined
|
||||
);
|
||||
assert.equal(
|
||||
fixture.context.db
|
||||
.select()
|
||||
.from(circuitProtectionDevices)
|
||||
.where(eq(circuitProtectionDevices.circuitId, "circuit-new"))
|
||||
.get(),
|
||||
undefined
|
||||
);
|
||||
assert.deepEqual(
|
||||
[
|
||||
getRow(fixture.context, "row-1"),
|
||||
@@ -562,6 +588,14 @@ describe("circuit device-row move project-command repository", () => {
|
||||
getRow(fixture.context, "row-2")?.circuitId,
|
||||
"circuit-new"
|
||||
);
|
||||
assert.equal(
|
||||
fixture.context.db
|
||||
.select({ type: circuitProtectionDevices.type })
|
||||
.from(circuitProtectionDevices)
|
||||
.where(eq(circuitProtectionDevices.circuitId, "circuit-new"))
|
||||
.get()?.type,
|
||||
"LS"
|
||||
);
|
||||
assert.deepEqual(
|
||||
new ProjectHistoryRepository(fixture.context.db).getState(
|
||||
"project-1"
|
||||
|
||||
@@ -128,12 +128,29 @@ describe("circuit grid model", () => {
|
||||
assert.equal(getCellKind("circuitSummary", "controlRequirement"), "circuitField");
|
||||
assert.equal(getCellKind("deviceRow", "controlRequirement"), "readonly");
|
||||
assert.equal(getCellKind("circuitCompact", "rowTotalPower"), "computed");
|
||||
assert.equal(getCellKind("circuitCompact", "protectionType"), "computed");
|
||||
});
|
||||
|
||||
it("projects circuit and device values without mixing ownership", () => {
|
||||
assert.equal(getDeviceValue(device, "roomSummary"), "1.01 Office");
|
||||
assert.equal(getDeviceValue(device, "rowTotalPower"), 0.08);
|
||||
assert.equal(getCircuitValue(circuit, "protectionSummary"), "MCB 16A B");
|
||||
assert.equal(
|
||||
getCircuitValue(
|
||||
{
|
||||
...circuit,
|
||||
protectionDevice: {
|
||||
type: "FI_LS",
|
||||
ratedCurrentA: 16,
|
||||
tripCharacteristic: "B",
|
||||
rcdType: "A",
|
||||
ratedResidualCurrentMa: 30,
|
||||
},
|
||||
},
|
||||
"protectionSummary"
|
||||
),
|
||||
"FI/LS · 16 A · B · Typ A · 30 mA"
|
||||
);
|
||||
assert.equal(getCircuitValue(circuit, "voltage"), 230);
|
||||
assert.equal(getCircuitValue(circuit, "controlRequirement"), "DALI");
|
||||
assert.equal(getCircuitValue(circuit, "cableSummary"), "NYM-J, 1.5 mm², 20 m");
|
||||
|
||||
@@ -65,12 +65,22 @@ describe("circuit structure command adapters", () => {
|
||||
controlRequirement: "DALI",
|
||||
},
|
||||
deviceRows: [],
|
||||
category: "single_phase",
|
||||
});
|
||||
|
||||
assert.equal(reserve.isReserve, true);
|
||||
assert.equal(reserve.displayName, null);
|
||||
assert.equal(reserve.voltage, 230);
|
||||
assert.equal(reserve.controlRequirement, "DALI");
|
||||
assert.deepEqual(reserve.protectionDevice, {
|
||||
circuitId: "circuit-1",
|
||||
type: "FI_LS",
|
||||
ratedCurrentA: 16,
|
||||
fuseUtilizationCategory: null,
|
||||
tripCharacteristic: "B",
|
||||
rcdType: "A",
|
||||
ratedResidualCurrentMa: 30,
|
||||
});
|
||||
|
||||
const row = buildCircuitDeviceRowInsertSnapshot({
|
||||
id: "row-1",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { CircuitStructureProjectCommandRepository } from "../src/db/repositories
|
||||
import { DistributionBoardFixtureRepository } from "./support/distribution-board-fixture.js";
|
||||
import { ProjectHistoryRepository } from "../src/db/repositories/project-history.repository.js";
|
||||
import { circuitDeviceRows } from "../src/db/schema/circuit-device-rows.js";
|
||||
import { circuitProtectionDevices } from "../src/db/schema/circuit-protection-devices.js";
|
||||
import { circuitSections } from "../src/db/schema/circuit-sections.js";
|
||||
import { circuits } from "../src/db/schema/circuits.js";
|
||||
import { projectDevices } from "../src/db/schema/project-devices.js";
|
||||
@@ -165,6 +166,18 @@ function createTestDatabase(): TestFixture {
|
||||
},
|
||||
])
|
||||
.run();
|
||||
context.db
|
||||
.insert(circuitProtectionDevices)
|
||||
.values({
|
||||
circuitId: "circuit-existing",
|
||||
type: "LS",
|
||||
ratedCurrentA: 10,
|
||||
fuseUtilizationCategory: null,
|
||||
tripCharacteristic: "B",
|
||||
rcdType: null,
|
||||
ratedResidualCurrentMa: null,
|
||||
})
|
||||
.run();
|
||||
|
||||
return {
|
||||
context,
|
||||
@@ -377,6 +390,11 @@ describe("circuit structure project-command repository", () => {
|
||||
"circuit-existing"
|
||||
);
|
||||
const beforeRows = getRows(fixture.context, "circuit-existing");
|
||||
const beforeProtection = fixture.context.db
|
||||
.select()
|
||||
.from(circuitProtectionDevices)
|
||||
.where(eq(circuitProtectionDevices.circuitId, "circuit-existing"))
|
||||
.get();
|
||||
assert.ok(beforeCircuit);
|
||||
const store = new CircuitStructureProjectCommandRepository(
|
||||
fixture.context.db
|
||||
@@ -395,6 +413,14 @@ describe("circuit structure project-command repository", () => {
|
||||
undefined
|
||||
);
|
||||
assert.equal(getRows(fixture.context, "circuit-existing").length, 0);
|
||||
assert.equal(
|
||||
fixture.context.db
|
||||
.select()
|
||||
.from(circuitProtectionDevices)
|
||||
.where(eq(circuitProtectionDevices.circuitId, "circuit-existing"))
|
||||
.get(),
|
||||
undefined
|
||||
);
|
||||
|
||||
store.execute({
|
||||
projectId: "project-1",
|
||||
@@ -411,6 +437,14 @@ describe("circuit structure project-command repository", () => {
|
||||
getRows(fixture.context, "circuit-existing"),
|
||||
beforeRows
|
||||
);
|
||||
assert.deepEqual(
|
||||
fixture.context.db
|
||||
.select()
|
||||
.from(circuitProtectionDevices)
|
||||
.where(eq(circuitProtectionDevices.circuitId, "circuit-existing"))
|
||||
.get(),
|
||||
beforeProtection
|
||||
);
|
||||
} finally {
|
||||
fixture.context.close();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ import {
|
||||
} from "../src/domain/services/protection-device-defaults.js";
|
||||
import { protectionDeviceConfigurationSchema } from "../src/shared/validation/protection-device.schemas.js";
|
||||
import "./circuit-protection-project-command.repository.test.js";
|
||||
import {
|
||||
getCircuitProtectionEditorInitialValue,
|
||||
toCircuitProtectionSnapshot,
|
||||
} from "../src/frontend/utils/circuit-protection-editing.js";
|
||||
|
||||
describe("protection device catalog", () => {
|
||||
it("contains exactly the agreed protection device types", () => {
|
||||
@@ -175,6 +179,32 @@ describe("protection device validation", () => {
|
||||
});
|
||||
|
||||
describe("protection device defaults", () => {
|
||||
it("maps editor values to complete circuit-owned snapshots", () => {
|
||||
const initial = getCircuitProtectionEditorInitialValue(
|
||||
"single_phase",
|
||||
undefined
|
||||
);
|
||||
assert.deepEqual(initial, {
|
||||
type: "FI_LS",
|
||||
ratedCurrentA: 16,
|
||||
tripCharacteristic: "B",
|
||||
rcdType: "A",
|
||||
ratedResidualCurrentMa: 30,
|
||||
});
|
||||
assert.deepEqual(
|
||||
toCircuitProtectionSnapshot("circuit-1", initial),
|
||||
{
|
||||
circuitId: "circuit-1",
|
||||
type: "FI_LS",
|
||||
ratedCurrentA: 16,
|
||||
fuseUtilizationCategory: null,
|
||||
tripCharacteristic: "B",
|
||||
rcdType: "A",
|
||||
ratedResidualCurrentMa: 30,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("creates the agreed circuit defaults", () => {
|
||||
assert.deepEqual(createDefaultCircuitProtection("lighting"), {
|
||||
type: "LS",
|
||||
|
||||
Reference in New Issue
Block a user