import { test, expect } from "@playwright/test" test("GRE: открытое меню переживает обновление и использует свежие права и данные", async ({ page }) => { let loads = 0 let refreshing = false let release: (() => void) | undefined const gate = new Promise(resolve => { release = resolve }) const tunnel = { id: "*M", name: "gre-menu", serverId: "1", localAddress: "192.0.2.1", remoteAddress: "192.0.2.2", localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "pool", ipsec: null, mtu: 1400, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: true, comment: "", enabled: true, status: "up" } await page.route("**/health", route => route.fulfill({ json: { ok: true } })) await page.route("**/api/**", async route => { const path = new URL(route.request().url()).pathname if (path === "/api/gre/tunnels") { loads++ if (refreshing) await gate return route.fulfill({ json: { tunnels: [{ ...tunnel, remoteInnerIp: refreshing ? "10.0.0.6/30" : tunnel.remoteInnerIp }] } }) } return route.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? [{ id: 1, name: "Роутер", host: "192.0.2.1", enabled: true, type: "exit-node", country: "RU", status: "online" }] : {} }) }) await page.goto("/gre") const refresh = page.getByRole("button", { name: "Обновить", exact: true }) await expect(refresh).toBeEnabled() await page.getByRole("button", { name: "Действия: gre-menu" }).click() const edit = page.getByRole("menuitem", { name: /Редактировать/ }) await expect(edit).toBeEnabled() // Invoke refresh without an outside pointer event: that event should close a menu. const initialLoads = loads refreshing = true await refresh.evaluate(element => (element as HTMLButtonElement).click()) await expect.poll(() => loads).toBe(initialLoads + 1) await expect(edit).toBeVisible() await expect(edit).toBeDisabled() release!() await expect(refresh).toBeEnabled() await expect(edit).toBeVisible() await expect(edit).toBeEnabled() await edit.click() const dialog = page.getByRole("dialog", { name: "Редактировать GRE-туннель" }) await expect(dialog).toBeVisible() await expect(dialog.getByLabel("Удалённый IP", { exact: true })).toHaveValue("10.0.0.6/30") })