import { test, expect } from "@playwright/test" test("IPsec: действия требуют актуальный опрос конкретного устройства", async ({ page }) => { const devices = [1, 2].map(id => ({ id, name: "Устройство " + id, host: "192.0.2." + id, enabled: true, country: "RU" })) const clients = ["1", "2"].map(id => ({ id: id + "-*1", rosId: "*1", serverId: id, serverName: "Устройство " + id, name: "Клиент " + id, authMethod: "certificate", kind: "cert", online: false, disabled: false, managed: true })) const summaries = ["1", "2"].map(id => ({ serverId: id, serverName: "Устройство " + id, initialized: false, ike2Ready: false, peers: [], natRuleManaged: false, clientsTotal: 1, clientsOnline: 0 })) let phase = 0, writes = 0 await page.route("**/health", r => r.fulfill({ json: { ok: true } })) await page.route("**/api/**", r => { const path = new URL(r.request().url()).pathname if (r.request().method() !== "GET") { writes++; return r.fulfill({ json: { ok: true } }) } if (path === "/api/ipsec") { if (phase === 0 || phase === 3) return r.fulfill({ status: 503, json: { error: "Опрос недоступен тест" } }) return r.fulfill({ json: phase === 2 ? { servers: [summaries[0]], clients: [clients[0]], failures: [{ serverId: "2", error: "Таймаут тест" }] } : { servers: summaries, clients } }) } return r.fulfill({ json: path === "/api/servers" ? devices : path === "/api/auth/config" ? { required: false } : {} }) }) await page.goto("/ipsec") const add = page.getByRole("button", { name: "Новый клиент", exact: true }) await expect(page.getByRole("alert").filter({ hasText: "Не удалось загрузить IPsec" })).toBeVisible() await expect(add).toBeDisabled() phase = 1 await page.getByRole("button", { name: "Обновить", exact: true }).click() const rows = page.locator("tr[data-row-id]") await expect(rows).toHaveCount(2) await expect(add).toBeEnabled() const one = rows.filter({ hasText: "Клиент 1" }), two = rows.filter({ hasText: "Клиент 2" }) await expect(two.getByRole("button", { name: "Удалить клиента" })).toBeEnabled() phase = 2 await page.getByRole("button", { name: "Обновить", exact: true }).click() await expect(page.getByRole("alert").filter({ hasText: "Не удалось опросить часть роутеров" })).toBeVisible() await expect(rows).toHaveCount(2) await expect(two.getByRole("button", { name: "Удалить клиента" })).toBeDisabled() await expect(two.getByRole("button", { name: "Клиент 2", exact: true })).toBeDisabled() await expect(one.getByRole("button", { name: "Удалить клиента" })).toBeEnabled() await expect(add).toBeEnabled() phase = 3 await page.getByRole("button", { name: "Обновить", exact: true }).click() await expect(page.getByRole("alert").filter({ hasText: "Не удалось загрузить IPsec" })).toBeVisible() await expect(one.getByRole("button", { name: "Удалить клиента" })).toBeDisabled() await expect(add).toBeDisabled() phase = 4 await page.getByRole("button", { name: "Обновить", exact: true }).click() await expect(add).toBeEnabled() await expect(two.getByRole("button", { name: "Удалить клиента" })).toBeEnabled() expect(writes).toBe(0) })