import { expect, test } from "@playwright/test"; import { mockBackend } from "./support/mockBackend"; test("地图缩放不会重新请求已打开的 SCADA 历史数据", async ({ page }) => { await mockBackend(page); await page.route("**/ows?**", (route) => route.fulfill({ contentType: "application/json", body: JSON.stringify({ type: "FeatureCollection", features: [ { type: "Feature", id: "S-1", properties: { id: "S-1", device_type: "pressure", reliability: 0.95, transmission_frequency: "00:15:00", }, geometry: { type: "Point", coordinates: [13530000, 3620000] }, }, ], }), }), ); await page.route("**/api/v1/scada-devices", (route) => route.fulfill({ contentType: "application/json", body: JSON.stringify([ { device_id: "S-1", device_type: "pressure", node_id: "J-1", link_id: null }, ]), }), ); let historyRequests = 0; await page.route("**/api/v1/timeseries/views/element-history/query", (route) => { historyRequests += 1; return route.fulfill({ contentType: "application/json", body: JSON.stringify({ series: [] }), }); }); await page.goto("/network-simulation"); await page.getByText("S-1", { exact: true }).click(); await expect(page.getByText("SCADA 历史数据")).toBeVisible(); await expect.poll(() => historyRequests).toBe(1); const zoomLabel = page.getByText(/缩放: \d+\.\d/); const initialZoom = await zoomLabel.textContent(); // The history drawer covers the map controls. Invoke their real handlers // without targeting a covered screen coordinate. await page.getByRole("button", { name: "放大" }).evaluate((button: HTMLButtonElement) => button.click()); await expect(zoomLabel).not.toHaveText(initialZoom!); expect(historyRequests).toBe(1); await page.getByRole("button", { name: "缩小" }).evaluate((button: HTMLButtonElement) => button.click()); await expect(zoomLabel).toHaveText(initialZoom!); expect(historyRequests).toBe(1); });