fix(ui): подтверждать перемещение правил Filters
This commit is contained in:
1 parent
c4011cfaff
commit
7554f1804b
6 files changed
+138
-24
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import type { FilterRule } from "../../lib/data"
|
||||
|
||||
for (const direction of ["up", "down"] as const) {
|
||||
test(`Filters: перемещение ${direction} в поиске сохраняет порядок при ошибке`, async ({ page }) => {
|
||||
let rules: FilterRule[] = [1, 2, 3].map(id => ({ id: `rule-${id}`, community: `65001:10${id}`, gateway: "", gatewayTunnelId: "", action: "blackhole", description: `Правило ${id}` }))
|
||||
const original = rules.map(r => r.id)
|
||||
const confirmed = direction === "up" ? ["rule-2", "rule-1", "rule-3"] : ["rule-1", "rule-3", "rule-2"]
|
||||
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.map((r: FilterRule) => r.id)).toEqual(confirmed)
|
||||
expect(rules.map(r => r.id)).toEqual(original)
|
||||
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]")
|
||||
await expect(rows).toHaveCount(3)
|
||||
await expect(page.getByRole("button", { name: "Поднять правило 65001:101", exact: true })).toBeDisabled()
|
||||
await expect(page.getByRole("button", { name: "Опустить правило 65001:103", exact: true })).toBeDisabled()
|
||||
const search = page.getByPlaceholder("Community, gateway, описание…")
|
||||
await search.fill("Правило 2")
|
||||
await expect(rows).toHaveCount(1)
|
||||
await expect(rows.first().getByRole("cell").first()).toHaveText("2")
|
||||
const up = page.getByRole("button", { name: "Поднять правило 65001:102", exact: true })
|
||||
const down = page.getByRole("button", { name: "Опустить правило 65001:102", exact: true })
|
||||
await expect(up).toBeEnabled()
|
||||
await expect(down).toBeEnabled()
|
||||
const move = direction === "up" ? up : down
|
||||
await move.evaluate(button => { (button as HTMLButtonElement).click(); (button as HTMLButtonElement).click() })
|
||||
await expect.poll(() => attempts).toBe(1)
|
||||
await expect(page.getByRole("status")).toContainText("Ожидание подтверждения порядка")
|
||||
for (const control of [up, down, page.getByRole("button", { name: "Редактировать правило", exact: true }), page.getByRole("button", { name: "Удалить правило", exact: true }), page.getByRole("button", { name: "Новое правило", exact: true }), page.getByRole("button", { name: "Копировать", exact: true }), page.getByRole("button", { name: "Обновить", exact: true }), page.getByRole("button", { name: "История", exact: true })]) await expect(control).toBeDisabled()
|
||||
release!()
|
||||
await expect(page.getByRole("alert").filter({ hasText: "Перемещение запрещено тест" })).toBeVisible()
|
||||
await expect(rows.first().getByRole("cell").first()).toHaveText("2")
|
||||
for (let attempt = 2; attempt <= 3; attempt++) {
|
||||
await rows.first().hover()
|
||||
await move.click()
|
||||
await expect.poll(() => attempts).toBe(attempt)
|
||||
await expect(page.getByRole("alert").filter({ hasText: "Сервер не подтвердил применение правил" })).toBeVisible()
|
||||
await expect(rows.first().getByRole("cell").first()).toHaveText("2")
|
||||
await expect(page.getByText("Правила применены на роутер", { exact: true })).toHaveCount(0)
|
||||
}
|
||||
await move.focus()
|
||||
await page.keyboard.press("Enter")
|
||||
await expect.poll(() => attempts).toBe(4)
|
||||
await expect(move).toBeDisabled()
|
||||
await expect(page.getByRole("alert").filter({ hasText: "Сервер не подтвердил применение правил" })).toHaveCount(0)
|
||||
await search.fill("")
|
||||
await expect(rows).toHaveCount(3)
|
||||
expect(await rows.evaluateAll(elements => elements.map(e => e.getAttribute("data-row-id")))).toEqual(confirmed)
|
||||
await expect(page.getByRole("button", { name: `${direction === "up" ? "Поднять" : "Опустить"} правило 65001:102`, exact: true })).toBeDisabled()
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user