feat: expand intelligent investigation workspace
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createInvestigationDevCase, investigationDevCases } from "./investigation-dev-cases";
|
||||
import { parseInvestigationDevJsonl } from "./investigation-dev-preview";
|
||||
|
||||
const center: [number, number] = [121.48, 31.1];
|
||||
const target = { source_id: "scada", feature_id: "P1" } as const;
|
||||
|
||||
describe("switchable investigation Dev cases", () => {
|
||||
it.each(investigationDevCases.filter((item) => !item.id.startsWith("invalid_")))(
|
||||
"$label produces a valid, nonempty batch within the existing presentation contract",
|
||||
({ id }) => {
|
||||
const input = createInvestigationDevCase(id, center, target);
|
||||
const preview = parseInvestigationDevJsonl(input);
|
||||
const records = input.split("\n").map((line) => JSON.parse(line));
|
||||
expect(records.every((record) => typeof record.record_type === "string")).toBe(true);
|
||||
expect(
|
||||
records
|
||||
.filter((record) => record.record_type === "presentation")
|
||||
.every((record) => !record.name && !record.params && record.command.action)
|
||||
).toBe(true);
|
||||
expect(preview.blocks.every((block) => block.phase === "final")).toBe(true);
|
||||
expect(
|
||||
preview.commands.length + preview.blocks.length + preview.records.length
|
||||
).toBeGreaterThan(0);
|
||||
}
|
||||
);
|
||||
|
||||
it.each(investigationDevCases.filter((item) => item.id.startsWith("invalid_")))(
|
||||
"$label cannot produce an executable batch",
|
||||
({ id }) => {
|
||||
expect(() => parseInvestigationDevJsonl(createInvestigationDevCase(id, center))).toThrow(
|
||||
id === "invalid_json" ? "第 2 行不是合法 JSON" : "第 1 行展示指令不合法"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
it("only queries an existing task target and falls back to a synthetic map point without one", () => {
|
||||
const withTarget = parseInvestigationDevJsonl(
|
||||
createInvestigationDevCase("map_targets", center, target)
|
||||
);
|
||||
expect(withTarget.commands[0]).toMatchObject({
|
||||
action: "highlight_features",
|
||||
layer: "scada",
|
||||
feature_ids: ["P1"]
|
||||
});
|
||||
const withoutTarget = parseInvestigationDevJsonl(
|
||||
createInvestigationDevCase("map_targets", center)
|
||||
);
|
||||
expect(withoutTarget.commands).toHaveLength(1);
|
||||
expect(withoutTarget.commands[0]).toMatchObject({ action: "set_overlay", mode: "geometry" });
|
||||
});
|
||||
|
||||
it.each(["data_only", "candidates_table", "valves_table"] as const)(
|
||||
"%s never turns synthetic asset IDs or embedded action fields into map queries or writes",
|
||||
(id) => {
|
||||
const preview = parseInvestigationDevJsonl(createInvestigationDevCase(id, center));
|
||||
expect(preview.commands).toEqual([]);
|
||||
expect(preview.records).toHaveLength(2);
|
||||
expect(preview.records.every((record) => record.origin === "synthetic")).toBe(true);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
[180, 90],
|
||||
[-180, -90],
|
||||
[540, 85]
|
||||
] as Array<[number, number]>)(
|
||||
"keeps synthetic geometry within schema bounds near longitude %s, latitude %s",
|
||||
(longitude, latitude) => {
|
||||
for (const id of ["combined", "map_targets", "impact_area", "complaint_heatmap"] as const) {
|
||||
expect(() =>
|
||||
parseInvestigationDevJsonl(createInvestigationDevCase(id, [longitude, latitude]))
|
||||
).not.toThrow();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user