Files
MikrotikManager/tests/e2e/ospf-bfd-conflict.spec.ts
T

40 lines
3.2 KiB
TypeScript

import { test, expect } from "@playwright/test"
for (const width of [1440, 320]) {
for (const ipv6 of [false, true]) {
test(`OSPF Full/BFD Down: предупреждение, scope и recovery, IPv${ipv6 ? 6 : 4}, ширина ${width}`, async ({ page }) => {
await page.setViewportSize({ width, height: 1000 })
let phase = "down"
const base = { serverId: 1, serverName: "CHR 1", serverSite: "", serverCountry: "RU" }
const neighbor = { ...base, id: "*n", address: ipv6 ? "FE80:0000:0000:0000:0000:0000:0000:0002%gre-own" : "198.18.153.2", routerId: "198.18.253.2", instance: "own", area: "own", areaId: "0.0.0.0", interface: "gre-own", state: "Full", uptime: "1m", stateChanges: 1, priority: 1 }
const iface = { ...base, id: "*i", instance: "own", area: "own", areaId: "0.0.0.0", interface: "gre-own", cost: 10, type: "ptp", disabled: false, inactive: false, priority: 1, helloInterval: 1, deadInterval: 20, useBfd: true }
const bfd = { ...base, id: "*b", localAddr: ipv6 ? "fe80::1" : "198.18.153.1", remoteAddr: ipv6 ? "fe80::2" : "198.18.153.2", interface: "gre-own", state: "Down", uptime: "1s", multihop: false, multiplier: 3, txInterval: 200, rxInterval: 200, holdTime: null, packetsRx: 10, packetsTx: 20, stateChanges: 1 }
const errors: string[] = []
page.on("pageerror", e => errors.push(e.message))
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", route => {
const path = new URL(route.request().url()).pathname
if (path === "/api/servers") return route.fulfill({ json: [1, 2].map(id => ({ id, name: "CHR " + id, host: "192.0.2." + id, country: "RU", enabled: true, status: "online" })) })
if (path === "/api/ospf/catalog") return route.fulfill({ json: { neighbors: [neighbor], interfaces: [{ ...iface, useBfd: phase === "not-used" ? false : true }], instances: [], bfdSessions: [{ ...bfd, serverId: phase === "foreign" ? 2 : 1, state: phase === "up" ? "Up" : phase === "unknown" ? "Unknown" : "Down" }], routes: [], failures: [] } })
return route.fulfill({ json: path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/ospf?server=1&tab=neighbors&q=253")
const alert = page.getByRole("alert").filter({ hasText: "OSPF Full при недоступном BFD" })
await expect(alert).toBeVisible()
await expect(alert).toContainText("CHR 1 · gre-own")
await expect(page.locator("tr[data-row-id]").first()).toContainText("Full")
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
await alert.getByRole("button", { name: "Проверить BFD" }).click()
await expect.poll(() => new URL(page.url()).searchParams.get("tab")).toBe("bfd")
expect(new URL(page.url()).searchParams.get("server")).toBe("1")
expect(new URL(page.url()).searchParams.has("q")).toBe(false)
await expect(page.locator("tr[data-row-id]").first()).toContainText("Down")
for (const next of ["up", "foreign", "not-used", "unknown"]) {
phase = next
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(alert).toHaveCount(0)
}
expect(errors).toEqual([])
})
}
}