Derive project device phases from category
This commit is contained in:
@@ -3,36 +3,27 @@ import { describe, it } from "node:test";
|
||||
import {
|
||||
inferProjectDeviceSectionKey,
|
||||
isProjectDevicePlacementValid,
|
||||
resolveProjectDevicePhaseType,
|
||||
} from "../src/domain/services/project-device-placement.service.js";
|
||||
|
||||
describe("project device placement", () => {
|
||||
it("routes lighting categories to the lighting section before phase classification", () => {
|
||||
assert.equal(
|
||||
inferProjectDeviceSectionKey({ category: "Lighting", phaseType: "three_phase" }),
|
||||
"lighting"
|
||||
);
|
||||
assert.equal(
|
||||
inferProjectDeviceSectionKey({ category: "Beleuchtung", phaseType: "single_phase" }),
|
||||
"lighting"
|
||||
);
|
||||
});
|
||||
|
||||
it("routes non-lighting devices by phase type", () => {
|
||||
assert.equal(
|
||||
inferProjectDeviceSectionKey({ category: "Socket", phaseType: "single_phase" }),
|
||||
"single_phase"
|
||||
);
|
||||
assert.equal(
|
||||
inferProjectDeviceSectionKey({ category: "Motor", phaseType: "three_phase" }),
|
||||
"three_phase"
|
||||
);
|
||||
it("routes project devices by their required category", () => {
|
||||
assert.equal(inferProjectDeviceSectionKey({ category: "lighting" }), "lighting");
|
||||
assert.equal(inferProjectDeviceSectionKey({ category: "single_phase" }), "single_phase");
|
||||
assert.equal(inferProjectDeviceSectionKey({ category: "three_phase" }), "three_phase");
|
||||
});
|
||||
|
||||
it("accepts only the inferred default section", () => {
|
||||
const device = { category: "Motor", phaseType: "three_phase" as const };
|
||||
const device = { category: "three_phase" as const };
|
||||
|
||||
assert.equal(isProjectDevicePlacementValid(device, { key: "three_phase" }), true);
|
||||
assert.equal(isProjectDevicePlacementValid(device, { key: "single_phase" }), false);
|
||||
assert.equal(isProjectDevicePlacementValid(device, { key: "unassigned" }), false);
|
||||
});
|
||||
|
||||
it("derives the electrical phase type from the category", () => {
|
||||
assert.equal(resolveProjectDevicePhaseType("lighting"), "single_phase");
|
||||
assert.equal(resolveProjectDevicePhaseType("single_phase"), "single_phase");
|
||||
assert.equal(resolveProjectDevicePhaseType("three_phase"), "three_phase");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,10 +14,9 @@ describe("project device circuit-first schema", () => {
|
||||
const result = createProjectDeviceSchema.safeParse({
|
||||
name: "E-Line Pro",
|
||||
displayName: "Office lighting",
|
||||
phaseType: "single_phase",
|
||||
connectionKind: "fixed",
|
||||
costGroup: "440",
|
||||
category: "Lighting",
|
||||
category: "lighting",
|
||||
quantity: 6,
|
||||
powerPerUnit: 0.04,
|
||||
simultaneityFactor: 0.8,
|
||||
@@ -28,7 +27,7 @@ describe("project device circuit-first schema", () => {
|
||||
assert.equal(result.success, true);
|
||||
});
|
||||
|
||||
it("requires the circuit-first power and phase fields", () => {
|
||||
it("requires the circuit-first power and category fields", () => {
|
||||
const result = createProjectDeviceSchema.safeParse({
|
||||
name: "Test device",
|
||||
displayName: "Test device",
|
||||
@@ -45,7 +44,7 @@ describe("project device circuit-first schema", () => {
|
||||
const result = createProjectDeviceSchema.safeParse({
|
||||
name: "Pumpe",
|
||||
displayName: "Pumpe",
|
||||
phaseType: "three_phase",
|
||||
category: "three_phase",
|
||||
quantity: 1,
|
||||
powerPerUnit: 2,
|
||||
simultaneityFactor: 1,
|
||||
@@ -59,7 +58,7 @@ describe("project device circuit-first schema", () => {
|
||||
const device = {
|
||||
name: "E-Line Pro",
|
||||
displayName: "Bürobeleuchtung",
|
||||
phaseType: "single_phase" as const,
|
||||
category: "lighting" as const,
|
||||
quantity: 6,
|
||||
powerPerUnit: 0.04,
|
||||
simultaneityFactor: 0.8,
|
||||
|
||||
@@ -283,7 +283,6 @@ describe("project device modal presentation", () => {
|
||||
"Kategorie",
|
||||
"Anschlussart",
|
||||
"Kostengruppe",
|
||||
"Phasenart",
|
||||
"Anzahl",
|
||||
"Leistung je Stück [kW]",
|
||||
"Gleichzeitigkeitsfaktor",
|
||||
@@ -292,6 +291,10 @@ describe("project device modal presentation", () => {
|
||||
assert.match(markup, new RegExp(label.replace("[", "\\[").replace("]", "\\]")));
|
||||
}
|
||||
assert.doesNotMatch(markup, /Spannung \[V\]/);
|
||||
assert.doesNotMatch(markup, /Phasenart/);
|
||||
assert.match(markup, /Beleuchtung/);
|
||||
assert.match(markup, /1-phasig/);
|
||||
assert.match(markup, /3-phasig/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user