feat(history): align units and history data
This commit is contained in:
+41
-6
@@ -1,4 +1,11 @@
|
||||
import { FLOW_DISPLAY_UNIT, isLpsFlowProperty, toM3h } from "./units";
|
||||
import {
|
||||
FLOW_DISPLAY_UNIT,
|
||||
metricForResultProperty,
|
||||
networkResultUnitsFromOptions,
|
||||
toDisplayValue,
|
||||
toM3h,
|
||||
toModelDisplayValue,
|
||||
} from "./units";
|
||||
|
||||
describe("flow display units", () => {
|
||||
it("uses cubic meters per hour as the flow display unit", () => {
|
||||
@@ -10,10 +17,38 @@ describe("flow display units", () => {
|
||||
expect(toM3h(10, "L/s")).toBe(36);
|
||||
});
|
||||
|
||||
it("recognizes computed properties that arrive from the backend in L/s", () => {
|
||||
expect(isLpsFlowProperty("flow")).toBe(true);
|
||||
expect(isLpsFlowProperty("actual_demand")).toBe(true);
|
||||
expect(isLpsFlowProperty("actualdemand")).toBe(true);
|
||||
expect(isLpsFlowProperty("pressure")).toBe(false);
|
||||
it("centralizes model and SCADA conversion for all UI consumers", () => {
|
||||
expect(toDisplayValue(2, "flow", "MLD")).toBeCloseTo(83.3333333334);
|
||||
expect(toDisplayValue(10, "pressure", "KPA")).toBeCloseTo(1.019716213);
|
||||
expect(toDisplayValue(2, "velocity", "ft/s")).toBeCloseTo(0.6096);
|
||||
expect(toDisplayValue(36, "flow", "m3/h")).toBe(36);
|
||||
});
|
||||
|
||||
it("maps result properties to their physical metrics", () => {
|
||||
expect(metricForResultProperty("flow")).toBe("flow");
|
||||
expect(metricForResultProperty("base_demand")).toBe("flow");
|
||||
expect(metricForResultProperty("actual_demand")).toBe("flow");
|
||||
expect(metricForResultProperty("pressure")).toBe("pressure");
|
||||
expect(metricForResultProperty("velocity")).toBe("velocity");
|
||||
expect(metricForResultProperty("headloss")).toBeNull();
|
||||
});
|
||||
|
||||
it("resolves legacy and v3 model options in one place", () => {
|
||||
expect(
|
||||
networkResultUnitsFromOptions({
|
||||
FLOW_UNITS: "MLD",
|
||||
PRESSURE_UNITS: "METERS",
|
||||
}),
|
||||
).toEqual({ flow: "MLD", pressure: "METERS", velocity: "m/s" });
|
||||
expect(networkResultUnitsFromOptions({ UNITS: "GPM", PRESSURE: "PSI" }))
|
||||
.toEqual({ flow: "GPM", pressure: "PSI", velocity: "ft/s" });
|
||||
});
|
||||
|
||||
it("converts model properties using project result units", () => {
|
||||
const units = { flow: "MLD", pressure: "KPA", velocity: "ft/s" };
|
||||
expect(toModelDisplayValue(2, "flow", units)).toBeCloseTo(83.3333333334);
|
||||
expect(toModelDisplayValue(10, "pressure", units)).toBeCloseTo(1.019716213);
|
||||
expect(toModelDisplayValue(2, "velocity", units)).toBeCloseTo(0.6096);
|
||||
expect(toModelDisplayValue(3, "headloss", units)).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user