fix(ui): сохранять контекст и свежесть опроса BGP

This commit is contained in:
Denozordec committed 2026-09-30 17:05:37 +07:00
1 parent 8fdc4b917b
commit 2e17cbe926
8 files changed
+182 -19

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import { test, expect } from "@playwright/test"
const headers = { "access-control-allow-origin": "*", "access-control-allow-methods": "GET,OPTIONS", "access-control-allow-headers": "Content-Type,Authorization" }
const session = (serverId: number, name = "Сессия " + serverId) => ({ id: "*1", serverId, serverName: "Роутер " + serverId, serverSite: "", serverCountry: "RU", name, peerIp: "192.0.2." + serverId, remoteAs: 64513, localAs: 64512, localId: "192.0.2.100", remoteId: "192.0.2." + serverId, state: "Established", type: "eBGP", uptime: "1h", holdTime: 90, keepalive: 30, prefixesRx: 12, prefixesTx: 2, inputMessages: 20, outputMessages: 10, capabilities: ["Тест capability"], lastError: null })
for (const change of ["backend", "mode"]) for (const fails of [false, true]) {
test(`BGP: позднее чтение после смены ${change}/${fails}`, async ({ page }) => {
await page.route("**/health", r => r.fulfill({ headers, json: { ok: true } }))
await page.route("**/api/**", r => {
const url = new URL(r.request().url()), path = url.pathname
return r.fulfill({ headers, json: path === "/api/bgp/catalog" ? { sessions: [session(1, url.port === "8101" ? "Новая BGP" : "Старая BGP")], failures: [] } : path === "/api/servers" ? [{ id: 1, name: "Роутер", host: "192.0.2.1", enabled: true, country: "RU" }] : path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/settings")
await page.getByRole("link", { name: /^BGP/ }).click()
await expect(page.locator("tr[data-row-id]")).toContainText("Старая BGP")
let release: (() => void) | undefined, started = false
const gate = new Promise<void>(resolve => { release = resolve })
await page.route("**/api/bgp/catalog", async r => {
if (new URL(r.request().url()).port !== "8000") return r.fallback()
started = true
await gate
return r.fulfill(fails ? { headers, status: 503, json: { error: "Старая ошибка BGP" } } : { headers, json: { sessions: [], failures: [] } })
})
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect.poll(() => started).toBe(true)
await page.goBack()
await expect(page).toHaveURL(/settings/)
if (change === "backend") {
const input = page.getByPlaceholder("http://localhost:8000")
await input.fill("http://localhost:8101")
await input.press("Enter")
} else await page.getByRole("button", { name: "Моковые", exact: true }).click()
await page.getByRole("link", { name: /^BGP/ }).click()
if (change === "backend") await expect(page.locator("tr[data-row-id]")).toContainText("Новая BGP")
else await expect(page.getByText("Моковые данные", { exact: true })).toBeVisible()
const response = page.waitForResponse(r => r.url().includes(":8000/api/bgp/catalog"))
release!()
await (await response).finished()
await page.evaluate(() => new Promise<void>(resolve => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))))
if (change === "backend") await expect(page.locator("tr[data-row-id]")).toContainText("Новая BGP")
await expect(page.getByText("Не удалось загрузить BGP", { exact: false })).toHaveCount(0)
})
}
+66
View File
@@ -0,0 +1,66 @@
import { test, expect } from "@playwright/test"
const server = (id: number) => ({ id, name: "Роутер " + id, host: "192.0.2." + id, enabled: true, country: "RU", status: null })
const session = (serverId: number, name = "Сессия " + serverId) => ({ id: "*1", serverId, serverName: "Роутер " + serverId, serverSite: "", serverCountry: "RU", name, peerIp: "192.0.2." + serverId, remoteAs: 64513, localAs: 64512, localId: "192.0.2.100", remoteId: "192.0.2." + serverId, state: "Established", type: "eBGP", uptime: "1h", holdTime: 90, keepalive: 30, prefixesRx: 12, prefixesTx: 2, inputMessages: 20, outputMessages: 10, capabilities: ["Тест capability"], lastError: null })
test("BGP: URL устройства/сессии/вкладки, возврат и неизвестный контекст", async ({ page }) => {
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
await page.route("**/api/**", r => {
const path = new URL(r.request().url()).pathname
return r.fulfill({ json: path === "/api/servers" ? [server(1), server(2)] : path === "/api/bgp/catalog" ? { sessions: [session(1), session(2)], failures: [] } : path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/bgp?server=1&session=1-%2A1&keep=x")
await expect(page.locator("tr[data-row-id]")).toHaveCount(1)
await expect(page.getByText("Тест capability", { exact: true })).toBeVisible()
await page.getByRole("button", { name: "Аналитика", exact: true }).click()
await expect(page).toHaveURL(/tab=analytics/)
await page.getByRole("option").filter({ hasText: "Роутер 2" }).click()
await expect(page).toHaveURL(/server=2/)
await expect.poll(() => new URL(page.url()).searchParams.has("session")).toBe(false)
expect(new URL(page.url()).searchParams.get("keep")).toBe("x")
await page.goBack()
await expect(page).toHaveURL(/server=1/)
await page.getByRole("button", { name: "Сессии", exact: true }).click()
await expect(page.getByText("Тест capability", { exact: true })).toBeVisible()
await page.reload()
await expect(page.getByText("Тест capability", { exact: true })).toBeVisible()
await page.goto("/bgp?server=99")
await expect(page.getByRole("alert").filter({ hasText: "Устройство BGP недоступно" })).toBeVisible()
await expect(page.locator("tr[data-row-id]")).toHaveCount(0)
await expect(page).toHaveURL(/server=99/)
await page.getByRole("button", { name: "Все устройства BGP" }).click()
await expect(page.locator("tr[data-row-id]")).toHaveCount(2)
await page.goto("/bgp?server=1&session=missing")
await expect(page.getByRole("alert").filter({ hasText: "Сессия из ссылки отсутствует" })).toBeVisible()
await page.getByRole("button", { name: "Все сессии BGP" }).click()
await expect.poll(() => new URL(page.url()).searchParams.has("session")).toBe(false)
})
test("BGP: время успешного опроса устройства сохраняется при отказе", 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/bgp/catalog" && phase === 2) return r.fulfill({ status: 503, json: { error: "Общий отказ BGP" } })
return r.fulfill({ json: path === "/api/servers" ? [server(1), server(2)] : path === "/api/bgp/catalog" ? { sessions: phase === 1 ? [session(1)] : [session(1), session(2)], failures: phase === 1 ? [{ serverId: 2, serverName: "Роутер 2", error: "Таймаут тест" }] : [] } : path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/bgp")
const group = page.getByRole("group", { name: "Свежесть BGP" })
const first = await group.locator('[data-bgp-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-bgp-server="2"]')).toHaveAttribute("datetime", first!)
await expect(group.locator('[data-bgp-server="1"]')).not.toHaveAttribute("datetime", first!)
const after = await group.locator('[data-bgp-server="1"]').getAttribute("datetime")
phase = 2
await page.clock.fastForward(60_000)
await page.getByRole("button", { name: "Повторить загрузку BGP" }).click()
await expect(page.getByRole("alert").filter({ hasText: "Общий отказ BGP" })).toBeVisible()
await expect(group.locator('[data-bgp-server="1"]')).toHaveAttribute("datetime", after!)
await expect(group.locator('[data-bgp-server="2"]')).toHaveAttribute("datetime", first!)
phase = 3
await page.getByRole("button", { name: "Повторить загрузку BGP" }).click()
await expect(page.getByRole("alert").filter({ hasText: "Не удалось" })).toHaveCount(0)
await expect(group.locator('[data-bgp-server="2"]')).not.toHaveAttribute("datetime", first!)
})