91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
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();
|
|
});
|
|
});
|