fix(ui): сохранять недоступные шлюзы Filters
This commit is contained in:
1 parent
860e88ed3e
commit
0ab5a23eb3
7 files changed
+149
-30
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
for (const kind of ["gre", "recursive"] as const) {
|
||||
test(`Filters: каталог ${kind} сохраняется при сбое и блокирует маршрут/копирование`, async ({ page }) => {
|
||||
let phase = 0, writes = 0, catalogReads = 0
|
||||
const tunnel = (id: string) => ({ id: "t" + id, serverId: id, name: "GRE-" + id, localAddress: "192.0.2." + id, remoteAddress: "198.51.100.1", localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "", ipsec: null, mtu: 1476, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: true, comment: "", enabled: true, status: "up" })
|
||||
const rec = { id: "rec1", dstAddress: "10.0.0.2/32", gateway: "198.51.100.1", distance: 1, routingTable: "main", comment: "Рекурсивный шлюз", disabled: false }
|
||||
const rule = { id: "rule-1", community: "65001:101", gateway: "10.0.0.2", gatewayTunnelId: kind === "gre" ? "t1" : "rec:rec1", action: "route", description: "Маршрут" }
|
||||
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
|
||||
await page.route("**/api/**", route => {
|
||||
const url = new URL(route.request().url()), path = url.pathname, id = url.searchParams.get("serverId") ?? "1"
|
||||
if (path === "/api/filters/rules" && route.request().method() === "PUT") { writes++; return route.fulfill({ json: { ok: true, rules: route.request().postDataJSON().rules } }) }
|
||||
const catalog = kind === "gre" ? "/api/filters/gre-tunnels" : "/api/recursive-routes"
|
||||
if (path === catalog) catalogReads++
|
||||
if (path === catalog && phase === 1) return route.fulfill({ status: 503, json: { error: "Каталог недоступен тест" } })
|
||||
if (path === catalog && phase === 2) return route.fulfill({ json: kind === "gre" ? { tunnels: [{ ...tunnel(id), name: null }] } : { routes: [rec], stale: true } })
|
||||
return route.fulfill({ json: path === "/api/filters/rules" ? { rulesets: [{ serverId: "1", rules: [rule] }, { serverId: "2", rules: [] }], live: true, greTunnels: [] }
|
||||
: path === "/api/servers" ? [1, 2].map(i => ({ id: i, name: "Роутер " + i, host: "192.0.2." + i, type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "", status: "online", latency: 1 }))
|
||||
: path === "/api/filters/gre-tunnels" ? { tunnels: kind === "gre" && phase !== 3 ? [tunnel(id)] : [] }
|
||||
: path === "/api/recursive-routes" ? { routes: kind === "recursive" && phase !== 3 ? [rec] : [], stale: false }
|
||||
: path === "/api/auth/config" ? { required: false } : {} })
|
||||
})
|
||||
await page.goto("/filters")
|
||||
const row = page.locator("tr[data-row-id]").first()
|
||||
await expect(row).toContainText(kind === "gre" ? "GRE-1" : rec.dstAddress)
|
||||
phase = 1
|
||||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||||
await expect(page.getByRole("alert").filter({ hasText: "Каталог недоступен тест" })).toBeVisible()
|
||||
await expect(row).toContainText(kind === "gre" ? "GRE-1" : rec.dstAddress)
|
||||
await row.hover()
|
||||
await row.getByRole("button", { name: "Редактировать правило", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
await dialog.getByRole("textbox", { name: "Описание правила" }).fill("Сохранить маршрут")
|
||||
await dialog.getByRole("button", { name: "Сохранить", exact: true }).click()
|
||||
await expect(dialog.getByRole("alert")).toContainText("Шлюзы устройства не подтверждены")
|
||||
expect(writes).toBe(0)
|
||||
await dialog.getByRole("button", { name: "Отмена", exact: true }).click()
|
||||
await page.getByRole("button", { name: "Копировать", exact: true }).click()
|
||||
await dialog.getByRole("button", { name: /Роутер 2/ }).click()
|
||||
const copy = dialog.getByRole("button", { name: "Копировать 1 правил", exact: true })
|
||||
await expect(copy).toBeDisabled()
|
||||
phase = 2
|
||||
let priorReads = catalogReads
|
||||
await dialog.getByRole("button", { name: "Обновить шлюзы", exact: true }).click()
|
||||
await expect.poll(() => catalogReads).toBeGreaterThanOrEqual(priorReads + 2)
|
||||
await expect(copy).toBeDisabled()
|
||||
await expect(dialog.getByRole("alert")).toContainText("сопоставление шлюзов не подтверждены")
|
||||
phase = 3
|
||||
priorReads = catalogReads
|
||||
await dialog.getByRole("button", { name: "Обновить шлюзы", exact: true }).click()
|
||||
await expect.poll(() => catalogReads).toBeGreaterThanOrEqual(priorReads + 2)
|
||||
await page.evaluate(() => new Promise<void>(resolve => requestAnimationFrame(() => resolve())))
|
||||
await expect(copy).toBeDisabled()
|
||||
phase = 4
|
||||
await dialog.getByRole("button", { name: "Обновить шлюзы", exact: true }).click()
|
||||
await expect(copy).toBeEnabled()
|
||||
await expect(dialog.getByRole("alert")).toHaveCount(0)
|
||||
await copy.click()
|
||||
await expect(dialog).toHaveCount(0)
|
||||
expect(writes).toBe(1)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user