fix(ui): показывать свежесть данных Filters
This commit is contained in:
1 parent
0ab5a23eb3
commit
4ae5f2edcd
5 files changed
+78
-2
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
test("Filters: время чтения и подтверждения API сохраняется при сбое", async ({ page }) => {
|
||||
let fails = false
|
||||
const rule = { id: "rule-1", community: "65001:101", gateway: "", gatewayTunnelId: "", action: "blackhole", description: "Правило" }
|
||||
await page.clock.install({ time: new Date("2026-09-30T01:00:00Z") })
|
||||
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
|
||||
if (path === "/api/filters/rules" && route.request().method() === "PUT") return route.fulfill({ json: { ok: true, rules: route.request().postDataJSON().rules } })
|
||||
if (fails && (path === "/api/filters/rules" && url.searchParams.has("serverId") || path === "/api/filters/gre-tunnels" || path === "/api/recursive-routes")) return route.fulfill({ status: 503, json: { error: "Сбой свежести тест" } })
|
||||
return route.fulfill({ json: path === "/api/filters/rules" ? { rulesets: [{ serverId: "1", rules: [rule] }], greTunnels: [], live: true }
|
||||
: path === "/api/servers" ? [{ id: 1, name: "Роутер", host: "192.0.2.1", type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "", status: "online", latency: 1 }]
|
||||
: path === "/api/filters/gre-tunnels" ? { tunnels: [] }
|
||||
: path === "/api/recursive-routes" ? { routes: [], stale: false }
|
||||
: path === "/api/auth/config" ? { required: false } : {} })
|
||||
})
|
||||
await page.goto("/filters")
|
||||
const group = page.getByRole("group", { name: "Свежесть данных устройства" })
|
||||
const rules = group.locator('[data-source-time="rules"]'), gre = group.locator('[data-source-time="gre"]'), rec = group.locator('[data-source-time="recursive"]')
|
||||
for (const item of [rules, gre, rec]) await expect(item.locator("time")).toHaveCount(1)
|
||||
const before = await rules.locator("time").getAttribute("datetime")
|
||||
const greBefore = await gre.locator("time").getAttribute("datetime")
|
||||
const recBefore = await rec.locator("time").getAttribute("datetime")
|
||||
fails = true
|
||||
await page.clock.fastForward(60_000)
|
||||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||||
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeDisabled()
|
||||
await expect(rules.locator("time")).toHaveAttribute("datetime", before!)
|
||||
await expect(gre.locator("time")).toHaveAttribute("datetime", greBefore!)
|
||||
await expect(rec.locator("time")).toHaveAttribute("datetime", recBefore!)
|
||||
fails = false
|
||||
await page.clock.fastForward(60_000)
|
||||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||||
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeEnabled()
|
||||
await expect(rules.locator("time")).not.toHaveAttribute("datetime", before!)
|
||||
await expect(gre.locator("time")).not.toHaveAttribute("datetime", greBefore!)
|
||||
await expect(rec.locator("time")).not.toHaveAttribute("datetime", recBefore!)
|
||||
const afterRead = await rules.locator("time").getAttribute("datetime")
|
||||
await page.clock.fastForward(60_000)
|
||||
await page.locator("tr[data-row-id]").first().hover()
|
||||
await page.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(rules).toContainText("Применение подтверждено API")
|
||||
await expect(rules.locator("time")).not.toHaveAttribute("datetime", afterRead!)
|
||||
await expect(page.locator("tr[data-row-id]")).toHaveCount(0)
|
||||
})
|
||||
Reference in new issue
Block a user