Persist circuit cell edits
This commit is contained in:
@@ -2,6 +2,8 @@ import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import {
|
||||
allColumns,
|
||||
buildCircuitEditPatch,
|
||||
buildDeviceRowEditPatch,
|
||||
getBlockSortValue,
|
||||
getCellKind,
|
||||
getCircuitValue,
|
||||
@@ -85,4 +87,38 @@ describe("circuit grid model", () => {
|
||||
assert.equal(parseNumeric("quantity", ""), undefined);
|
||||
assert.throws(() => parseNumeric("quantity", "two"), /Ungültiger Zahlenwert/);
|
||||
});
|
||||
|
||||
it("builds nullable circuit command patches from grid drafts", () => {
|
||||
assert.deepEqual(buildCircuitEditPatch("voltage", ""), {
|
||||
voltage: null,
|
||||
});
|
||||
assert.deepEqual(
|
||||
buildCircuitEditPatch("controlRequirement", " DALI "),
|
||||
{ controlRequirement: "DALI" }
|
||||
);
|
||||
assert.deepEqual(buildCircuitEditPatch("isReserve", "ja"), {
|
||||
isReserve: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("builds device command patches with explicit clearing semantics", () => {
|
||||
assert.deepEqual(buildDeviceRowEditPatch("roomSummary", ""), {
|
||||
roomNumberSnapshot: null,
|
||||
roomNameSnapshot: null,
|
||||
});
|
||||
assert.deepEqual(
|
||||
buildDeviceRowEditPatch("roomSummary", "1.01 Büro"),
|
||||
{
|
||||
roomNumberSnapshot: "1.01",
|
||||
roomNameSnapshot: "Büro",
|
||||
}
|
||||
);
|
||||
assert.deepEqual(buildDeviceRowEditPatch("technicalName", " Leuchte "), {
|
||||
name: "Leuchte",
|
||||
});
|
||||
assert.throws(
|
||||
() => buildDeviceRowEditPatch("quantity", ""),
|
||||
/darf nicht leer sein/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,6 +71,8 @@ function createTestFixture(): TestFixture {
|
||||
displayName: "Licht Bestand",
|
||||
sortOrder: 10,
|
||||
protectionRatedCurrent: 10,
|
||||
voltage: 230,
|
||||
controlRequirement: "none",
|
||||
isReserve: 0,
|
||||
},
|
||||
{
|
||||
@@ -111,6 +113,8 @@ describe("circuit project-command repository", () => {
|
||||
const command = createCircuitUpdateProjectCommand("circuit-1", {
|
||||
displayName: null,
|
||||
protectionRatedCurrent: 16,
|
||||
voltage: 400,
|
||||
controlRequirement: "DALI",
|
||||
isReserve: true,
|
||||
});
|
||||
|
||||
@@ -125,6 +129,8 @@ describe("circuit project-command repository", () => {
|
||||
const circuit = getCircuit(fixture.context);
|
||||
assert.equal(circuit.displayName, null);
|
||||
assert.equal(circuit.protectionRatedCurrent, 16);
|
||||
assert.equal(circuit.voltage, 400);
|
||||
assert.equal(circuit.controlRequirement, "DALI");
|
||||
assert.equal(circuit.isReserve, 1);
|
||||
assert.equal(executed.revision.revisionNumber, 1);
|
||||
assert.deepEqual(executed.inverse.payload, {
|
||||
@@ -132,6 +138,8 @@ describe("circuit project-command repository", () => {
|
||||
changes: [
|
||||
{ field: "displayName", value: "Licht Bestand" },
|
||||
{ field: "protectionRatedCurrent", value: 10 },
|
||||
{ field: "voltage", value: 230 },
|
||||
{ field: "controlRequirement", value: "none" },
|
||||
{ field: "isReserve", value: false },
|
||||
],
|
||||
});
|
||||
|
||||
@@ -16,45 +16,6 @@ describe("circuit write service rules", () => {
|
||||
assert.equal(parsed.success, true);
|
||||
});
|
||||
|
||||
it("passes voltage and control requirements through circuit updates", async () => {
|
||||
let updatePayload: Record<string, unknown> = {};
|
||||
const circuit = {
|
||||
id: "c1",
|
||||
circuitListId: "l1",
|
||||
sectionId: "s1",
|
||||
equipmentIdentifier: "-1F1",
|
||||
sortOrder: 10,
|
||||
isReserve: 0,
|
||||
voltage: 230,
|
||||
controlRequirement: "none",
|
||||
};
|
||||
const service = new CircuitWriteService({
|
||||
circuitSectionRepository: {
|
||||
async findById() {
|
||||
return { id: "s1", circuitListId: "l1" } as never;
|
||||
},
|
||||
} as never,
|
||||
circuitRepository: {
|
||||
async findById() {
|
||||
return circuit as never;
|
||||
},
|
||||
async existsByEquipmentIdentifier() {
|
||||
return false;
|
||||
},
|
||||
async updateFields(_id: string, payload: Record<string, unknown>) {
|
||||
updatePayload = payload;
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
await service.updateCircuit("c1", { voltage: 400, controlRequirement: "DALI" });
|
||||
|
||||
assert.deepEqual(updatePayload, {
|
||||
voltage: 400,
|
||||
controlRequirement: "DALI",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects duplicate equipment identifiers in same circuit list", async () => {
|
||||
const service = new CircuitWriteService({
|
||||
circuitListRepository: {
|
||||
@@ -741,36 +702,4 @@ describe("circuit write service rules", () => {
|
||||
assert.equal(safeCalled, true);
|
||||
});
|
||||
|
||||
it("tracks local edits on linked device rows as overridden fields", async () => {
|
||||
let updatePayload: Record<string, unknown> = {};
|
||||
const current = {
|
||||
id: "r1",
|
||||
circuitId: "c1",
|
||||
linkedProjectDeviceId: "pd1",
|
||||
name: "Luminaire",
|
||||
displayName: "Local name",
|
||||
quantity: 1,
|
||||
powerPerUnit: 0.1,
|
||||
simultaneityFactor: 1,
|
||||
sortOrder: 10,
|
||||
overriddenFields: null,
|
||||
};
|
||||
const service = new CircuitWriteService({
|
||||
deviceRowRepository: {
|
||||
async findById() {
|
||||
return current as never;
|
||||
},
|
||||
async updateFields(_rowId: string, input: Record<string, unknown>) {
|
||||
updatePayload = input;
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
await service.updateDeviceRow("r1", { quantity: 2 });
|
||||
|
||||
assert.deepEqual(updatePayload, {
|
||||
quantity: 2,
|
||||
overriddenFields: "[\"quantity\"]",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user