import { test, expect } from "@playwright/test" const servers = [1, 2].map(id => ({ id, name: "Роутер " + id, host: "192.0.2." + id, country: "RU", enabled: true, status: null })) const host = (serverId: number) => ({ serverId, serverName: "Роутер " + serverId, serverSite: "", serverCountry: "RU" }) const neighbor = (serverId: number, address = "192.0.2." + serverId) => ({ ...host(serverId), id: "*1", address, routerId: address, instance: "default", area: "backbone", areaId: "0.0.0.0", interface: "ether1", state: "Full", uptime: "1h", stateChanges: 0, priority: 1 }) const all = { neighbors: [neighbor(1), neighbor(2)], interfaces: [], instances: [], bfdSessions: [], routes: [], failures: [] } test("OSPF: время успешного опроса устройства сохраняется при отказе", async ({ page }) => { await page.clock.install({ time: new Date("2026-09-30T05:00:00Z") }) 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/ospf/catalog" && phase === 2) return r.fulfill({ status: 503, json: { error: "Общий отказ OSPF" } }) return r.fulfill({ json: path === "/api/servers" ? [...servers] : path === "/api/ospf/catalog" ? { ...all, neighbors: phase === 1 ? [neighbor(1)] : [neighbor(1), neighbor(2)], failures: phase === 1 ? [{ serverId: 2, serverName: "Роутер 2", error: "Таймаут тест" }] : [] } : path === "/api/auth/config" ? { required: false } : {} }) }) await page.goto("/ospf") const group = page.getByRole("group", { name: "Свежесть OSPF" }) const first = await group.locator('[data-ospf-server="2"]').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(group.locator('[data-ospf-server="2"]')).toHaveAttribute("datetime", first!) await expect(group.locator('[data-ospf-server="1"]')).not.toHaveAttribute("datetime", first!) const after = await group.locator('[data-ospf-server="1"]').getAttribute("datetime") phase = 2 await page.clock.fastForward(60_000) await page.getByRole("button", { name: "Повторить загрузку OSPF" }).click() await expect(page.getByRole("alert").filter({ hasText: "Общий отказ OSPF" })).toBeVisible() await expect(group.locator('[data-ospf-server="1"]')).toHaveAttribute("datetime", after!) await expect(group.locator('[data-ospf-server="2"]')).toHaveAttribute("datetime", first!) phase = 3 await page.getByRole("button", { name: "Повторить загрузку OSPF" }).click() await expect(page.getByRole("alert").filter({ hasText: "Не удалось" })).toHaveCount(0) await expect(group.locator('[data-ospf-server="2"]')).not.toHaveAttribute("datetime", first!) })