import { expect, test } from "@playwright/test";

test("opening Agent and condition panels does not move the map camera", async ({ page }) => {
  await page.goto("/", { waitUntil: "domcontentloaded" });
  await page.waitForFunction(() =>
    Boolean(window.__waterNetworkMap?.getLayer("scada-hit"))
  );
  await page.waitForTimeout(500);
  await page.evaluate(() => {
    const map = window.__waterNetworkMap;
    document.documentElement.dataset.panelCameraMoveCount = "0";
    map?.on("movestart", () => {
      const currentCount = Number(
        document.documentElement.dataset.panelCameraMoveCount ?? "0"
      );
      document.documentElement.dataset.panelCameraMoveCount = String(currentCount + 1);
    });
  });

  await page.getByRole("button", { name: "折叠 Agent 面板" }).click();
  await page.waitForTimeout(250);
  await page.getByRole("button", { name: /展开 Agent 助手面板/ }).click();
  await page.waitForTimeout(250);

  const conditionPanel = page.getByRole("region", { name: "工况任务", exact: true });
  await conditionPanel.getByRole("button", { name: "展开工况任务" }).click();
  await page.waitForTimeout(250);

  expect(
    await page.evaluate(
      () => document.documentElement.dataset.panelCameraMoveCount
    )
  ).toBe("0");
});
