fix(ui): различать ошибку и пустые данные VXLAN

This commit is contained in:
Denozordec committed 2026-09-30 09:37:31 +07:00
1 parent 3d518ff902
commit 4dc2ee2129
5 files changed
+56 -12

No files matched your search

+23 -1
View File
@@ -1,7 +1,7 @@
import { test, expect, type Page } from "@playwright/test"
async function setup(page: Page, url: string, failed = 0) {
const control = { partial: false, failed, posts: [] as { path: string; body: unknown }[] }
const control = { malformed: false, partial: false, failed, posts: [] as { path: string; body: unknown }[] }
const servers = [{ id: 1, name: "Источник", host: "192.0.2.1", type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "64512", status: "online", latency: 1, os: "7", model: "CHR", wanUplinks: [] }]
const tunnels = ["1", "2"].flatMap(serverId => ["*/2", "other"].map(id => ({ id, serverId, name: "vx-same", vni: Number(serverId) * 100 + (id === "other" ? 1 : 0), port: 0, dstPort: 8472, vtepIp: "192.0.2.1", remoteVteps: ["192.0.2.22"], l2mtu: 1500, arpProxy: false, macLearning: true, comment: "", enabled: true, status: "down" })))
servers.push({ ...servers[0], id: 2, name: "Второй сервер", host: "192.0.2.2" });
@@ -12,6 +12,7 @@ async function setup(page: Page, url: string, failed = 0) {
const path = new URL(request.url()).pathname
if (!["GET", "HEAD"].includes(request.method())) control.posts.push({ path, body: request.postDataJSON() })
if (path === "/api/vxlan" && control.failed) return route.fulfill({ status: control.failed, json: { error: "Мониторинг недоступен" } })
if (path === "/api/vxlan" && control.malformed) return route.fulfill({ json: {} })
const json = path === "/api/auth/config" ? { required: false }
: path === "/api/evobgp/settings" ? { enabled: false, baseUrl: "", secretConfigured: false }
: path === "/api/servers" ? servers
@@ -109,3 +110,24 @@ for (const status of [403, 500]) {
expect(control.posts).toEqual([])
})
}
for (const initiallyFailed of [true, false]) {
test(`VXLAN: повреждённый ответ сохраняет состояние ${initiallyFailed}`, async ({ page }) => {
const control = await setup(page, "/vxlan", initiallyFailed ? 503 : 0)
const rows = page.locator("tr[data-row-id]")
if (initiallyFailed) {
await expect(page.getByText("Ошибка загрузки:", { exact: false })).toBeVisible()
await expect(page.getByLabel("Сводка VXLAN")).toContainText("—")
} else await expect(rows).toHaveCount(4)
control.failed = 0
control.malformed = true
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByText("Ошибка загрузки: Некорректный ответ загрузки VXLAN", { exact: true })).toBeVisible()
await expect(rows).toHaveCount(initiallyFailed ? 0 : 4)
await expect(page.getByText("На опрошенных серверах нет VXLAN-интерфейсов", { exact: true })).toHaveCount(0)
control.malformed = false
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(rows).toHaveCount(4)
await expect(page.getByText("Ошибка загрузки:", { exact: false })).toHaveCount(0)
})
}