import { test, expect } from "@playwright/test" test("IPsec: время успешного опроса сохраняется при частичном/полном отказе", async ({ page }) => { await page.clock.install({ time: new Date("2026-09-30T05:00:00Z") }) const summary = (id: string) => ({ serverId: id, serverName: "Роутер " + id, initialized: false, ike2Ready: false, peers: [], natRuleManaged: false, clientsTotal: 0, clientsOnline: 0 }) let phase = 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 (path === "/api/ipsec" && phase === 2) return r.fulfill({ status: 503, json: { error: "Опрос недоступен тест" } }) return r.fulfill({ json: path === "/api/ipsec" ? { servers: phase === 1 ? [summary("1")] : [summary("1"), summary("2")], clients: [], failures: phase === 1 ? [{ serverId: "2", error: "Таймаут тест" }] : [] } : path === "/api/servers" ? [1, 2].map(id => ({ id, name: "Роутер " + id, host: "192.0.2." + id, enabled: true, country: "RU" })) : path === "/api/auth/config" ? { required: false } : {} }) }) await page.goto("/ipsec") const time = page.getByRole("group", { name: "Свежесть IPsec" }).locator('[data-source-time="read"] time') await expect(time).toHaveCount(1) await page.getByRole("option").filter({ hasText: "Роутер 2" }).click() const first = await time.getAttribute("datetime") phase = 1 await page.clock.fastForward(60_000) await page.getByRole("button", { name: "Обновить", exact: true }).click() await expect(page.getByRole("alert").filter({ hasText: "Не удалось опросить часть роутеров" })).toBeVisible() await expect(time).toHaveAttribute("datetime", first!) phase = 2 await page.clock.fastForward(60_000) await page.getByRole("button", { name: "Обновить", exact: true }).click() await expect(page.getByRole("alert").filter({ hasText: "Не удалось загрузить IPsec" })).toBeVisible() await expect(time).toHaveAttribute("datetime", first!) phase = 3 await page.clock.fastForward(60_000) await page.getByRole("button", { name: "Повторить загрузку IPsec" }).click() await expect(time).not.toHaveAttribute("datetime", first!) await expect(page.getByRole("button", { name: "Новый клиент", exact: true })).toBeEnabled() })