import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { calculateCircuitTotalPower, calculateRowTotalPower, } from "../src/domain/calculations/circuit-power-calculation.js"; import { resolveCircuitPhaseType, resolveProjectVoltage, normalizeKnownElectricalPhaseType, } from "../src/domain/services/project-voltage.service.js"; describe("circuit power calculation", () => { it("calculates row and circuit totals from device rows", () => { assert.equal(calculateRowTotalPower(2, 1.5, 0.5), 1.5); const total = calculateCircuitTotalPower([ { quantity: 2, powerPerUnit: 1.5, simultaneityFactor: 0.5 }, { quantity: 1, powerPerUnit: 3, simultaneityFactor: 1 }, ]); assert.equal(total, 4.5); }); }); describe("project voltage derivation", () => { const settings = { singlePhaseVoltageV: 240, threePhaseVoltageV: 415, }; it("derives device voltage exclusively from phase and project settings", () => { assert.equal(resolveProjectVoltage("single_phase", settings), 240); assert.equal(resolveProjectVoltage("three_phase", settings), 415); }); it("uses section phase and handles unassigned circuits conservatively", () => { assert.equal(resolveCircuitPhaseType("lighting", ["three_phase"]), "single_phase"); assert.equal(resolveCircuitPhaseType("single_phase", ["three_phase"]), "single_phase"); assert.equal(resolveCircuitPhaseType("three_phase", ["single_phase"]), "three_phase"); assert.equal(resolveCircuitPhaseType("unassigned", ["three_phase"]), "three_phase"); assert.equal( resolveCircuitPhaseType("unassigned", ["three_phase", "single_phase"]), "single_phase" ); assert.equal(resolveCircuitPhaseType("unassigned", []), "single_phase"); assert.equal(resolveCircuitPhaseType("unassigned", [null]), "single_phase"); }); it("normalizes known legacy phase labels without guessing unknown values", () => { assert.equal(normalizeKnownElectricalPhaseType("1phasig"), "single_phase"); assert.equal(normalizeKnownElectricalPhaseType("1-phasig"), "single_phase"); assert.equal(normalizeKnownElectricalPhaseType("3phase"), "three_phase"); assert.equal(normalizeKnownElectricalPhaseType("3-phasig"), "three_phase"); assert.equal(normalizeKnownElectricalPhaseType(null), null); assert.throws( () => normalizeKnownElectricalPhaseType("zweiphasig"), /Unknown electrical phase type/ ); }); });