fix(ui): показывать достоверное состояние и экспорт VXLAN
This commit is contained in:
1 parent
6fc342cd2c
commit
d200e87e3d
8 files changed
+164
-43
No files matched your search
@@ -0,0 +1,42 @@
|
||||
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 tunnel = (port: string) => ({ id: "*1", name: port === "8101" ? "Новый VXLAN" : "Старый VXLAN", serverId: "1", vni: port === "8101" ? 200 : 100, port: 0, dstPort: 8472, vtepIp: "192.0.2.1", remoteVteps: [], l2mtu: 1500, arpProxy: false, macLearning: true, comment: "", enabled: true, status: "up" })
|
||||
|
||||
for (const change of ["backend", "mode"]) for (const fails of [false, true]) {
|
||||
test(`VXLAN: позднее чтение после смены ${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/vxlan" ? { tunnels: [tunnel(url.port)] } : 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: /^VXLAN/ }).click()
|
||||
await expect(page.locator("tr[data-row-id]")).toContainText("Старый VXLAN")
|
||||
let release: (() => void) | undefined, started = false
|
||||
const gate = new Promise<void>(resolve => { release = resolve })
|
||||
await page.route("**/api/vxlan", 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: "Старая ошибка VXLAN" } } : { headers, json: { tunnels: [] } })
|
||||
})
|
||||
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: /^VXLAN/ }).click()
|
||||
if (change === "backend") await expect(page.locator("tr[data-row-id]")).toContainText("Новый VXLAN")
|
||||
else await expect(page.getByText("Моковые данные", { exact: true })).toBeVisible()
|
||||
const response = page.waitForResponse(r => r.url().includes(":8000/api/vxlan"))
|
||||
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("Новый VXLAN")
|
||||
await expect(page.getByText("Ошибка загрузки:", { exact: false })).toHaveCount(0)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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, vni: number) => ({ id: "*" + id, serverId: id, name: "vxlan-" + id, vni, port: 0, dstPort: 8472, vtepIp: "192.0.2." + id, remoteVteps: ["198.51.100.1"], l2mtu: 1500, arpProxy: false, macLearning: true, comment: "", enabled: true, status: "up" })
|
||||
|
||||
test("VXLAN: свежесть, неизвестный статус и честный режим просмотра", 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/vxlan" && phase === 2) return r.fulfill({ status: 503, json: { error: "Опрос VXLAN недоступен" } })
|
||||
return r.fulfill({ json: path === "/api/vxlan" ? { tunnels: phase === 1 ? [tunnel("1", 100)] : [tunnel("1", 100), tunnel("2", phase === 3 ? 300 : 200)], failures: phase === 1 ? [{ serverId: "2", error: "Таймаут тест" }] : [] }
|
||||
: path === "/api/servers" ? devices : path === "/api/auth/config" ? { required: false } : {} })
|
||||
})
|
||||
await page.goto("/vxlan?server=2")
|
||||
const rows = page.locator("tr[data-row-id]")
|
||||
await expect(rows).toHaveCount(1)
|
||||
await expect(page.getByText("Только просмотр", { exact: true })).toBeVisible()
|
||||
await expect(page.getByRole("button", { name: "Новый VXLAN" })).toHaveCount(0)
|
||||
const time = page.getByRole("group", { name: "Свежесть VXLAN" }).locator("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: "Действия: vxlan-2" }).click()
|
||||
for (const name of ["Редактировать", "Отключить", "Удалить"]) await expect(page.getByRole("menuitem", { name, exact: true })).toHaveCount(0)
|
||||
await page.getByRole("menuitem", { name: "Экспорт .rsc", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
await expect(dialog).toContainText("актуальность не подтверждена")
|
||||
await expect(dialog).toContainText("vni=200")
|
||||
phase = 3
|
||||
const refresh = page.getByRole("button", { name: "Обновить", exact: true, includeHidden: true })
|
||||
await refresh.evaluate(el => (el as HTMLButtonElement).click())
|
||||
await expect(rows).toContainText("300")
|
||||
await expect(dialog).toContainText("vni=200")
|
||||
await expect(dialog).toContainText("актуальность не подтверждена")
|
||||
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.getByText("Ошибка загрузки: Опрос VXLAN недоступен", { exact: true })).toBeVisible()
|
||||
await expect(rows).toHaveCount(1)
|
||||
await expect(rows).toContainText("Неизвестно")
|
||||
await expect(page.getByLabel("Сводка VXLAN")).toContainText("—")
|
||||
await expect(time).toHaveAttribute("datetime", after!)
|
||||
expect(writes).toBe(0)
|
||||
})
|
||||
Reference in new issue
Block a user