fix: hide unavailable GeoServer layers
This commit is contained in:
@@ -1,25 +1,8 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { mockScadaApi } from "./support/mock-scada-api";
|
||||
|
||||
test("loads SCADA from the backend API and aligns map features by device_id", async ({ page }) => {
|
||||
await page.route("**/runtime-config.js", async (route) => {
|
||||
await route.fulfill({
|
||||
contentType: "application/javascript",
|
||||
body: `globalThis.__TJWATER_CONFIG__ = {
|
||||
TJWATER_AUTH_MODE: "disabled",
|
||||
TJWATER_MAPBOX_ACCESS_TOKEN: "",
|
||||
TJWATER_MAP_URL: "https://scada-map.invalid/geoserver",
|
||||
TJWATER_GEOSERVER_WORKSPACE: "tjwater_next",
|
||||
TJWATER_SERVER_API_BASE_URL: "https://tjwater-api.invalid",
|
||||
TJWATER_AGENT_API_BASE_URL: "http://127.0.0.1:8787",
|
||||
TJWATER_ENABLE_DEV_PANEL: "false",
|
||||
TJWATER_ENABLE_MSW: "false"
|
||||
};`
|
||||
});
|
||||
});
|
||||
await page.route("https://scada-map.invalid/**", async (route) => {
|
||||
await route.fulfill({ status: 204, body: "" });
|
||||
});
|
||||
await mockRuntimeAndMap(page, { pumps: 0, tanks: 0 });
|
||||
await mockScadaApi(page, [{
|
||||
device_id: "SCADA-1",
|
||||
device_type: "pressure",
|
||||
@@ -50,4 +33,87 @@ test("loads SCADA from the backend API and aligns map features by device_id", as
|
||||
deviceId: String(feature.properties?.device_id)
|
||||
}));
|
||||
})).toContainEqual({ id: "SCADA-1", deviceId: "SCADA-1" });
|
||||
|
||||
const layerTool = page.getByRole("button", { name: /图层:管理地图图层/ });
|
||||
await expect(layerTool).toBeEnabled();
|
||||
await layerTool.click();
|
||||
await expect(page.getByRole("button", { name: /^管线/ })).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: /^水泵/ })).toHaveCount(0);
|
||||
await expect(page.getByRole("button", { name: /^水箱/ })).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("shows data-dependent layer controls only when GeoServer reports features", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await mockRuntimeAndMap(page, { pumps: 2, tanks: 1 });
|
||||
await mockScadaApi(page);
|
||||
|
||||
await page.goto("/", { waitUntil: "domcontentloaded" });
|
||||
|
||||
const layerTool = page.getByRole("button", { name: /图层:管理地图图层/ });
|
||||
await expect(layerTool).toBeEnabled();
|
||||
await layerTool.click();
|
||||
await expect(page.getByRole("button", { name: /^水泵/ })).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: /^水箱/ })).toBeVisible();
|
||||
await expect.poll(() => page.evaluate(() => ({
|
||||
pump: Boolean(globalThis.__waterNetworkMap?.getLayer("pumps-symbol")),
|
||||
tank: Boolean(globalThis.__waterNetworkMap?.getLayer("tanks-symbol"))
|
||||
}))).toEqual({ pump: true, tank: true });
|
||||
});
|
||||
|
||||
test("loads required map layers while optional layer probes are still pending", async ({ page }) => {
|
||||
let releaseProbe = () => {};
|
||||
const probeGate = new Promise<void>((resolve) => {
|
||||
releaseProbe = resolve;
|
||||
});
|
||||
await mockRuntimeAndMap(page, { pumps: 1, tanks: 0 }, { probeGate });
|
||||
await mockScadaApi(page);
|
||||
|
||||
await page.goto("/", { waitUntil: "domcontentloaded" });
|
||||
|
||||
try {
|
||||
await expect.poll(() => page.evaluate(() => ({
|
||||
pipes: Boolean(globalThis.__waterNetworkMap?.getLayer("pipes-casing")),
|
||||
pumps: Boolean(globalThis.__waterNetworkMap?.getLayer("pumps-symbol"))
|
||||
}))).toEqual({ pipes: true, pumps: false });
|
||||
} finally {
|
||||
releaseProbe();
|
||||
}
|
||||
|
||||
await expect.poll(() => page.evaluate(() =>
|
||||
Boolean(globalThis.__waterNetworkMap?.getLayer("pumps-symbol"))
|
||||
)).toBe(true);
|
||||
});
|
||||
|
||||
async function mockRuntimeAndMap(
|
||||
page: Page,
|
||||
featureCounts: { pumps: number; tanks: number },
|
||||
options: { probeGate?: Promise<void> } = {}
|
||||
) {
|
||||
await page.route("**/runtime-config.js", async (route) => {
|
||||
await route.fulfill({
|
||||
contentType: "application/javascript",
|
||||
body: `globalThis.__TJWATER_CONFIG__ = {
|
||||
TJWATER_AUTH_MODE: "disabled",
|
||||
TJWATER_MAPBOX_ACCESS_TOKEN: "",
|
||||
TJWATER_MAP_URL: "https://scada-map.invalid/geoserver",
|
||||
TJWATER_GEOSERVER_WORKSPACE: "tjwater_next",
|
||||
TJWATER_SERVER_API_BASE_URL: "https://tjwater-api.invalid",
|
||||
TJWATER_AGENT_API_BASE_URL: "http://127.0.0.1:8787",
|
||||
TJWATER_ENABLE_DEV_PANEL: "false",
|
||||
TJWATER_ENABLE_MSW: "false"
|
||||
};`
|
||||
});
|
||||
});
|
||||
await page.route("https://scada-map.invalid/**", async (route) => {
|
||||
await route.fulfill({ status: 204, body: "" });
|
||||
});
|
||||
await page.route("https://scada-map.invalid/geoserver/tjwater_next/ows?**", async (route) => {
|
||||
await options.probeGate;
|
||||
const typeNames = new URL(route.request().url()).searchParams.get("typeNames");
|
||||
const sourceId = typeNames?.endsWith(":pumps") ? "pumps" : "tanks";
|
||||
await route.fulfill({
|
||||
contentType: "application/xml",
|
||||
body: `<wfs:FeatureCollection numberMatched="${featureCounts[sourceId]}" numberReturned="0" />`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user