Files

47 lines
3.3 KiB
TypeScript

import { test, expect } from "@playwright/test"
const devices = [1, 2].map(id => ({ id, name: "Роутер " + id, host: "192.0.2." + id, enabled: true, country: "RU" }))
const tunnel = (id: string, remoteAddress: string) => ({ id: "*" + id, serverId: id, name: "gre-" + id, localAddress: "192.0.2.1", remoteAddress, localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "live", ipsec: null, mtu: 1476, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: true, comment: "", enabled: true, status: "up" })
test("GRE: отметка чтения и закреплённый экспорт при частичном отказе", async ({ page }) => {
await page.clock.install({ time: new Date("2026-09-30T05:00:00Z") })
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++
if (path === "/api/gre/tunnels" && phase === 2) return r.fulfill({ status: 503, json: { error: "Опрос GRE недоступен" } })
return r.fulfill({ json: path === "/api/gre/tunnels" ? { tunnels: phase === 1 ? [tunnel("1", "198.51.100.1")] : [tunnel("1", "198.51.100.1"), tunnel("2", phase === 3 ? "198.51.100.33" : "198.51.100.22")], failures: phase === 1 ? [{ serverId: "2", error: "Таймаут тест" }] : [] } : path === "/api/servers" ? devices : path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/gre?server=2")
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(1)
const time = page.getByRole("group", { name: "Свежесть GRE" }).locator('[data-source-time="read"] time')
const first = await time.getAttribute("datetime")
await page.clock.fastForward(60_000)
phase = 1
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByRole("alert").filter({ hasText: "Таймаут тест" })).toBeVisible()
await expect(rows).toContainText("Неизвестно")
await expect(time).toHaveAttribute("datetime", first!)
await page.getByRole("button", { name: "Действия: gre-2" }).click()
await page.getByRole("menuitem", { name: "Просмотр кода", exact: true }).click()
const dialog = page.getByRole("dialog")
await expect(dialog).toContainText("актуальность не подтверждена")
await expect(dialog).toContainText("198.51.100.22")
phase = 3
const refresh = page.getByRole("button", { name: "Обновить", exact: true, includeHidden: true })
await refresh.evaluate(el => (el as HTMLButtonElement).click())
await expect(rows).toContainText("198.51.100.33")
await expect(dialog).toContainText("198.51.100.22")
await expect(dialog).not.toContainText("198.51.100.33")
await page.keyboard.press("Escape")
await expect(time).not.toHaveAttribute("datetime", first!)
const after = await time.getAttribute("datetime")
phase = 2
await page.clock.fastForward(60_000)
await refresh.click()
await expect(page.getByRole("alert").filter({ hasText: "Опрос GRE недоступен" })).toBeVisible()
await expect(time).toHaveAttribute("datetime", after!)
expect(writes).toBe(0)
})