Files
next-tjwater-drainage-frontend/features/workbench/utils/feature-properties.test.ts
T

111 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { formatFeaturePropertyValue, getFeaturePanelModel, getFeaturePanelProperties, getLocalizedFeatureProperties } from "./feature-properties";
describe("feature panel properties", () => {
it.each([
["pumps", ["id", "status", "startup_depth", "shutoff_depth"]],
["conduits", ["id", "length", "diameter"]],
["junctions", ["id", "invert_elevation", "max_depth"]],
["orifices", ["id", "discharge_coeff", "gated", "shape", "geom1", "geom2"]],
["outfalls", ["id", "invert_elevation", "outfall_type"]]
] as const)("shows the configured %s fields", (layer, expectedKeys) => {
const entries = getFeaturePanelProperties(layer, {}, "feature-id");
expect(entries.map((entry) => entry.key)).toEqual(expectedKeys);
expect(entries[0].value).toBe("feature-id");
});
it("formats conduit diameter from meters to millimeters", () => {
const entries = getFeaturePanelProperties("conduits", {
id: "C-1",
length: 42.5,
diameter: 0.6
});
expect(entries.map(({ label, value }) => [label, value])).toEqual([
["编号", "C-1"],
["长度", "42.50 m"],
["管径", "600 mm"]
]);
});
it("localizes free outfall type", () => {
const entries = getFeaturePanelProperties("outfalls", {
id: "OF-1",
invert_elevation: -5.67,
outfall_type: "FREE"
});
expect(entries.map((entry) => entry.value)).toEqual(["OF-1", "-5.67 m", "自由出流"]);
});
it.each([
{
layer: "pumps",
properties: { id: "P-1", status: "ON", startup_depth: 1.2, shutoff_depth: 0.4 },
badge: { label: "运行", tone: "active" },
attributeKeys: ["startup_depth", "shutoff_depth"]
},
{
layer: "orifices",
properties: { id: "O-1", gated: "YES", discharge_coeff: 0.65, shape: "RECT_CLOSED" },
badge: { label: "有闸门", tone: "info" },
attributeKeys: ["discharge_coeff", "shape", "geom1", "geom2"]
}
] as const)("promotes the $layer badge without repeating it", ({ layer, properties, badge, attributeKeys }) => {
const model = getFeaturePanelModel(layer, properties);
expect(model.id).toBe(properties.id);
expect(model.badge).toEqual(badge);
expect(model.attributes.map((entry) => entry.key)).toEqual(attributeKeys);
expect(model.attributes.every((entry) => entry.value !== properties.id)).toBe(true);
});
it("uses the map feature id when the properties omit it", () => {
const model = getFeaturePanelModel("junctions", { max_depth: 3.4 }, "map-feature-id");
expect(model.id).toBe("map-feature-id");
expect(model.badge).toBeUndefined();
expect(model.attributes.map((entry) => entry.key)).toEqual(["invert_elevation", "max_depth"]);
});
it("shows SCADA identity, device, state, and sync fields", () => {
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"
});
expect(model.id).toBe("4bfa834b-cbbb-5f35-9523-7487ac021ed2");
expect(model.badge).toEqual({ label: "在线", tone: "active" });
expect(model.attributes.map((entry) => entry.key)).toEqual([
"site_external_id",
"name",
"external_id",
"kind",
"junction_id",
"synced_at"
]);
});
it("omits the internal SCADA clustering size from user-facing properties", () => {
const entries = getLocalizedFeatureProperties({
name: "THC雷达液位计(MQTT",
cluster_size: 29,
external_id: "DEVICE-002"
});
expect(entries.map((entry) => entry.key)).toEqual(["name", "external_id"]);
});
it("labels uniformly sampled SCADA locations", () => {
expect(formatFeaturePropertyValue("location_source", "uniform_farthest_point_demo"))
.toBe("空间均匀采样模拟位置");
});
});