fix(ui): отклонять устаревшее чтение Filters

This commit is contained in:
Denozordec committed 2026-09-30 11:57:22 +07:00
1 parent 1c7ffa07a8
commit 24cc66d8d2
5 files changed
+104 -8

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
import { test, expect } from "@playwright/test"
for (const outcome of ["success", "error"] as const) {
test(`Filters: исходный кэш readonly и поздний ${outcome} предыдущего устройства отклонён`, async ({ page }) => {
const makeRule = (id: string, community: string) => ({ id, community, gateway: "", gatewayTunnelId: "", action: "blackhole", description: id })
const firstRules = [makeRule("cache-1", "65001:101")]
let secondRules = [makeRule("device-2", "65002:201")]
let release: (() => void) | undefined
const gate = new Promise<void>(resolve => { release = resolve })
let firstWaiting = false, firstFinished = false, writes = 0
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", async route => {
const url = new URL(route.request().url()), path = url.pathname
if (path === "/api/filters/rules" && route.request().method() === "PUT") {
writes++
const body = route.request().postDataJSON()
expect(body.serverId).toBe("2")
expect(body.rules).toEqual([])
secondRules = body.rules
return route.fulfill({ json: { ok: true, rules: [] } })
}
if (path === "/api/filters/rules" && url.searchParams.get("serverId") === "1") {
firstWaiting = true
await gate
if (outcome === "error") await route.fulfill({ status: 503, json: { error: "Устаревший сбой первого устройства" } })
else await route.fulfill({ json: { rulesets: [{ serverId: "1", rules: firstRules }], greTunnels: [], live: true } })
firstFinished = true
return
}
return route.fulfill({ json: path === "/api/filters/rules" ? url.searchParams.has("serverId") ? { rulesets: [{ serverId: "2", rules: secondRules }], greTunnels: [], live: true }
: { rulesets: [{ serverId: "1", rules: firstRules }, { serverId: "2", rules: secondRules }], greTunnels: [], live: false, stale: false }
: path === "/api/servers" ? [1, 2].map(id => ({ id, name: `Роутер ${id}`, host: `192.0.2.${id}`, type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "", status: "online", latency: 1 }))
: path === "/api/auth/config" ? { required: false }
: path === "/api/filters/gre-tunnels" ? { tunnels: [] }
: path === "/api/recursive-routes" ? { routes: [] } : {} })
})
await page.goto("/filters")
await expect.poll(() => firstWaiting).toBe(true)
await expect(page.locator("tr[data-row-id]")).toHaveCount(1)
await expect(page.getByRole("status")).toContainText("Чтение актуальных правил устройства")
for (const name of ["Новое правило", "Копировать", "Редактировать правило", "Удалить правило"]) await expect(page.getByRole("button", { name, exact: true })).toBeDisabled()
expect(writes).toBe(0)
await page.getByRole("option", { name: /Роутер 2/ }).click()
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeEnabled()
const rows = page.locator("tr[data-row-id]")
await expect(rows.first()).toContainText("65002:201")
await rows.first().hover()
await rows.first().getByRole("button", { name: "Удалить правило", exact: true }).click()
await page.getByRole("alertdialog").getByRole("button", { name: "Удалить", exact: true }).click()
await expect(page.getByRole("alertdialog")).toHaveCount(0)
await expect(rows).toHaveCount(0)
expect(writes).toBe(1)
release!()
await expect.poll(() => firstFinished).toBe(true)
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeEnabled()
await expect(page.getByRole("option", { name: /Роутер 2/ })).toHaveAttribute("aria-selected", "true")
await expect(rows).toHaveCount(0)
await expect(page.getByText("Не удалось прочитать правила с роутера", { exact: true })).toHaveCount(0)
await expect(page.getByRole("status").filter({ hasText: "Чтение актуальных правил устройства" })).toHaveCount(0)
})
}