fix(ui): подтверждать удаление правил Filters

This commit is contained in:
Denozordec committed 2026-09-30 11:29:54 +07:00
1 parent 8412ba9bbe
commit c4011cfaff
6 files changed
+154 -19

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
import { test, expect } from "@playwright/test"
import type { FilterRule } from "../../lib/data"
for (const deletingId of ["rule-1", "rule-2"]) {
test(`Filters: удаление ${deletingId} сохраняет подтверждение при ошибке`, async ({ page }) => {
let rules: FilterRule[] = [1, 2].map(id => ({ id: `rule-${id}`, community: `65001:10${id}`, gateway: "", gatewayTunnelId: "", action: "blackhole", description: `Правило ${id}` }))
const deleting = rules.find(r => r.id === deletingId)!
const retained = rules.find(r => r.id !== deletingId)!
let attempts = 0
let release: (() => void) | undefined
const gate = new Promise<void>(resolve => { release = resolve })
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", async route => {
const path = new URL(route.request().url()).pathname
if (path === "/api/filters/rules" && route.request().method() === "PUT") {
attempts++
const body = route.request().postDataJSON()
expect(body.serverId).toBe("1")
expect(body.source).toBe("apply")
expect(body.rules).toEqual([retained])
if (attempts === 1) { await gate; return route.fulfill({ status: 403, json: { error: "Удаление запрещено тест" } }) }
if (attempts === 2) return route.fulfill({ json: {} })
if (attempts === 3) return route.fulfill({ json: { ok: false } })
rules = body.rules
return route.fulfill({ json: { ok: true, rules } })
}
return route.fulfill({ json: path === "/api/filters/rules" ? { rulesets: [{ serverId: "1", rules }], greTunnels: [], live: true }
: path === "/api/servers" ? [{ id: 1, name: "Тестовый роутер", host: "192.0.2.1", type: "exit-node", site: "TEST", country: "RU", asn: "", enabled: true, 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")
const rows = page.locator("tr[data-row-id]")
const deletingRow = rows.filter({ hasText: deleting.community })
await expect(rows).toHaveCount(2)
const open = async () => {
await deletingRow.hover()
await deletingRow.getByRole("button", { name: "Удалить правило", exact: true }).click()
}
await open()
const dialog = page.getByRole("alertdialog")
await expect(dialog).toContainText(deleting.community)
await expect(dialog).toContainText("Тестовый роутер")
await dialog.getByRole("button", { name: "Отмена", exact: true }).click()
await expect(dialog).toHaveCount(0)
expect(attempts).toBe(0)
await open()
const remove = dialog.getByRole("button", { name: "Удалить", exact: true })
await remove.evaluate(button => { (button as HTMLButtonElement).click(); (button as HTMLButtonElement).click() })
await expect.poll(() => attempts).toBe(1)
await expect(remove).toBeDisabled()
await expect(dialog.getByRole("button", { name: "Отмена", exact: true })).toBeDisabled()
await expect(dialog.getByRole("status")).toContainText("Ожидание подтверждения удаления")
await expect(rows).toHaveCount(2)
await page.keyboard.press("Escape")
await expect(dialog).toBeVisible()
release!()
await expect(dialog.getByRole("alert")).toContainText("Удаление запрещено тест")
await expect(deletingRow).toHaveCount(1)
await dialog.getByRole("button", { name: "Отмена", exact: true }).click()
await open()
await expect(dialog.getByRole("alert")).toHaveCount(0)
for (let attempt = 2; attempt <= 3; attempt++) {
await remove.click()
await expect.poll(() => attempts).toBe(attempt)
await expect(dialog.getByRole("alert")).toContainText("Сервер не подтвердил применение правил")
await expect(rows).toHaveCount(2)
await expect(page.getByText("Правила применены на роутер", { exact: true })).toHaveCount(0)
}
await remove.click()
await expect(dialog).toHaveCount(0)
expect(attempts).toBe(4)
await expect(deletingRow).toHaveCount(0)
await expect(rows).toHaveCount(1)
await expect(rows.first()).toContainText(retained.community)
})
}