refactor: abstract feature property panels

This commit is contained in:
2026-07-20 17:26:35 +08:00
parent bae4b65005
commit 86389de3fa
5 changed files with 316 additions and 106 deletions
@@ -1,5 +1,12 @@
import { describe, expect, it } from "vitest";
import { formatFeaturePropertyValue, getFeaturePanelModel, getFeaturePanelProperties, getLocalizedFeatureProperties } from "./feature-properties";
import {
formatFeaturePropertyValue,
getFeatureInsightMetrics,
getFeaturePanelModel,
getFeaturePanelProperties,
getLocalizedFeatureProperties,
getScadaMetricProperties
} from "./feature-properties";
describe("feature panel properties", () => {
it.each([
@@ -29,6 +36,22 @@ describe("feature panel properties", () => {
]);
});
it("builds insight metrics from the layer configuration", () => {
const metrics = getFeatureInsightMetrics("conduits", {
diameter: 0.6,
length: 42.5,
roughness: 0.013,
status: "OPEN"
});
expect(metrics).toEqual([
{ label: "管径", value: "600 mm" },
{ label: "长度", value: "42.50 m" },
{ label: "粗糙系数", value: "0.01" },
{ label: "状态", value: "开启" }
]);
});
it("localizes free outfall type", () => {
const entries = getFeaturePanelProperties("outfalls", {
id: "OF-1",
@@ -69,27 +92,55 @@ describe("feature panel properties", () => {
expect(model.attributes.map((entry) => entry.key)).toEqual(["invert_elevation", "max_depth"]);
});
it("shows SCADA identity, device, state, and sync fields", () => {
it("shows SCADA facility properties without monitoring readings", () => {
const model = getFeaturePanelModel("scada", {
scada_id: "4bfa834b-cbbb-5f35-9523-7487ac021ed2",
site_external_id: "36455",
name: "DY22东市南街环城南路西段交叉口",
external_id: "26825171",
kind: "water_quality",
active: true,
junction_id: "31011502010001809",
synced_at: "Jul 15, 2026, 7:38:45 AM"
sensor_id: "SCADA-001",
sensor_name: "DY22东市南街环城南路西段交叉口",
kind: "integrated_monitoring",
swmm_node: "J-1024",
topology_order: 17,
upstream_node_count: 8,
distance_to_wwtp_m: 1260,
COD_mg_L: 23.45,
氨氮_mg_L: 1.26,
电导率_uS_cm: 746,
液位_m: 2.18,
流量_m3_s: 0.37
});
expect(model.id).toBe("4bfa834b-cbbb-5f35-9523-7487ac021ed2");
expect(model.badge).toEqual({ label: "在线", tone: "active" });
expect(model.id).toBe("SCADA-001");
expect(model.badge).toBeUndefined();
expect(model.attributes.map((entry) => entry.key)).toEqual([
"site_external_id",
"name",
"external_id",
"kind",
"junction_id",
"synced_at"
"swmm_node",
"topology_order",
"upstream_node_count",
"distance_to_wwtp_m"
]);
expect(model.attributes.map((entry) => entry.value)).toEqual([
"综合监测点",
"J-1024",
"17",
"8",
"1260 m"
]);
});
it("formats the five integrated SCADA metrics with localized labels and units", () => {
const metrics = getScadaMetricProperties({
cod_mg_l: 23.45,
氨氮_mg_L: 1.26,
电导率_uS_cm: 746,
液位_m: 2.18,
流量_m3_s: 0.37
});
expect(metrics.map(({ label, value }) => [label, value])).toEqual([
["COD", "23.45 mg/L"],
["氨氮", "1.26 mg/L"],
["电导率", "746 μS/cm"],
["液位", "2.18 m"],
["流量", "0.37 m³/s"]
]);
});