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

72 lines
2.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { getFeaturePanelModel, getFeaturePanelProperties } 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"]);
});
});