feat(workbench): integrate runtime data and map tooling
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { FeaturePopover } from "./feature-popover";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
fetchElementGisProperties: vi.fn()
|
||||
}));
|
||||
|
||||
vi.mock("../api/gis-properties-client", async (importOriginal) => ({
|
||||
...await importOriginal<typeof import("../api/gis-properties-client")>(),
|
||||
fetchElementGisProperties: mocks.fetchElementGisProperties
|
||||
}));
|
||||
|
||||
describe("feature GIS properties", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("keeps imported GIS fields folded by dataset", async () => {
|
||||
mocks.fetchElementGisProperties.mockResolvedValue([{
|
||||
dataset_key: "fx_pipe_inventory_20200811",
|
||||
dataset_title: "奉贤 DN100 及以上管网台账",
|
||||
source_date: "2020-08-11",
|
||||
layer_key: "fx_20200811_dn100_pipes",
|
||||
layer_name: "DN100 及以上管线台账",
|
||||
source_fid: 117,
|
||||
match_method: "geometry",
|
||||
match_distance_m: 0.12,
|
||||
attributes: { PIPE_D: 300, MATERIAL: "DI" }
|
||||
}]);
|
||||
|
||||
render(
|
||||
<FeaturePopover
|
||||
feature={{
|
||||
id: "DEMO-P001",
|
||||
layer: "pipes",
|
||||
title: "管线 DEMO-P001",
|
||||
subtitle: "",
|
||||
properties: {
|
||||
id: "DEMO-P001",
|
||||
diameter: 300,
|
||||
status: "open"
|
||||
}
|
||||
}}
|
||||
projectId="project-117"
|
||||
getAccessToken={async () => "read-token"}
|
||||
onClose={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(await screen.findByText("1 份")).toBeVisible();
|
||||
expect(screen.getByText("PIPE_D")).not.toBeVisible();
|
||||
|
||||
fireEvent.click(screen.getByText("GIS 台账属性"));
|
||||
expect(screen.getByText("DN100 及以上管线台账")).toBeVisible();
|
||||
expect(screen.getByText("PIPE_D")).not.toBeVisible();
|
||||
|
||||
fireEvent.click(screen.getByText("DN100 及以上管线台账"));
|
||||
expect(screen.getByTitle("300 mm")).toBeVisible();
|
||||
expect(screen.getByText("材质")).toBeVisible();
|
||||
expect(screen.getByTitle("球墨铸铁")).toBeVisible();
|
||||
expect(screen.getByText("PIPE_D")).not.toBeVisible();
|
||||
|
||||
fireEvent.click(screen.getByText("全部原始字段 · 2 项"));
|
||||
expect(screen.getByText("PIPE_D")).toBeVisible();
|
||||
});
|
||||
|
||||
it("hides the GIS inventory section when the element has no linked records", async () => {
|
||||
mocks.fetchElementGisProperties.mockResolvedValue([]);
|
||||
|
||||
render(
|
||||
<FeaturePopover
|
||||
feature={{
|
||||
id: "P-NO-GIS",
|
||||
layer: "pipes",
|
||||
title: "未关联管线",
|
||||
subtitle: "",
|
||||
properties: { id: "P-NO-GIS", status: "open" }
|
||||
}}
|
||||
projectId="project-117"
|
||||
getAccessToken={async () => "read-token"}
|
||||
onClose={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
await waitFor(() => expect(mocks.fetchElementGisProperties).toHaveBeenCalledOnce());
|
||||
expect(screen.queryByText("GIS 台账属性")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user