64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import type { MapGeoJSONFeature } from "maplibre-gl";
|
|
import { describe, expect, it } from "vitest";
|
|
import { toDetailFeature } from "./feature-adapter";
|
|
import { SOURCE_LAYERS } from "./sources";
|
|
|
|
describe("drainage feature adapter", () => {
|
|
it.each([
|
|
{
|
|
layer: "conduits",
|
|
sourceLayer: SOURCE_LAYERS.conduits,
|
|
properties: { id: "C-1", diameter: 600, length: 42.5 },
|
|
title: "管渠 C-1",
|
|
subtitle: "DN600 · 42.50 m"
|
|
},
|
|
{
|
|
layer: "junctions",
|
|
sourceLayer: SOURCE_LAYERS.junctions,
|
|
properties: { id: "J-1", max_depth: 4.2, invert_elevation: -1.8 },
|
|
title: "检查井 J-1",
|
|
subtitle: "最大深度 4.20 m · 井底高程 -1.80 m"
|
|
},
|
|
{
|
|
layer: "orifices",
|
|
sourceLayer: SOURCE_LAYERS.orifices,
|
|
properties: { id: "O-1", orifice_type: "SIDE", shape: "RECT_CLOSED" },
|
|
title: "孔口 O-1",
|
|
subtitle: "类型 SIDE · 断面 RECT_CLOSED"
|
|
},
|
|
{
|
|
layer: "pumps",
|
|
sourceLayer: SOURCE_LAYERS.pumps,
|
|
properties: { id: "P-1", status: "ON", pump_curve: "CURVE-1" },
|
|
title: "泵 P-1",
|
|
subtitle: "状态 ON · 曲线 CURVE-1"
|
|
},
|
|
{
|
|
layer: "outfalls",
|
|
sourceLayer: SOURCE_LAYERS.outfalls,
|
|
properties: { id: "OF-1", outfall_type: "FREE", invert_elevation: -5.67 },
|
|
title: "排放口 OF-1",
|
|
subtitle: "类型 FREE · 井底高程 -5.67 m"
|
|
}
|
|
] as const)("adapts $layer features", ({ layer, sourceLayer, properties, title, subtitle }) => {
|
|
const detail = toDetailFeature({
|
|
sourceLayer,
|
|
properties
|
|
} as unknown as MapGeoJSONFeature);
|
|
|
|
expect(detail).toMatchObject({
|
|
id: properties.id,
|
|
layer,
|
|
title,
|
|
subtitle,
|
|
properties
|
|
});
|
|
});
|
|
|
|
it("rejects features outside the drainage network sources", () => {
|
|
expect(() => toDetailFeature({ sourceLayer: "other" } as unknown as MapGeoJSONFeature)).toThrow(
|
|
"Unsupported water network source layer: other"
|
|
);
|
|
});
|
|
});
|