fix(ui): читать актуальную цель копирования Filters
This commit is contained in:
1 parent
365ab2173c
commit
860e88ed3e
5 files changed
+99
-10
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
|
||||
for (const mode of ["append", "replace"] as const) {
|
||||
test(`Filters: копирование ${mode} читает актуальную цель до PUT`, async ({ page }) => {
|
||||
const makeRule = (id: string, community: string) => ({ id, community, gateway: "", gatewayTunnelId: "", action: "blackhole", description: id })
|
||||
const source = makeRule("source", "65001:101"), cached = makeRule("cached", "65002:201"), fresh = makeRule("fresh", "65002:202")
|
||||
let phase = 0, targetReads = 0, writes = 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 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.source).toBe("copy")
|
||||
expect(body.rules.map((r: { community: string }) => r.community)).toEqual(mode === "append" ? [fresh.community, source.community] : [source.community])
|
||||
expect(body.rules.some((r: { id: string }) => r.id === cached.id)).toBe(false)
|
||||
return route.fulfill({ json: { ok: true, rules: body.rules } })
|
||||
}
|
||||
if (path === "/api/filters/rules" && url.searchParams.get("serverId") === "2") {
|
||||
targetReads++
|
||||
if (phase === 0) { await gate; return route.fulfill({ status: 503, json: { error: "Цель недоступна тест" } }) }
|
||||
return route.fulfill({ json: { rulesets: [{ serverId: phase === 1 ? "3" : "2", rules: phase === 3 ? [{ ...fresh, description: null }] : [fresh] }], greTunnels: [], live: true, stale: phase === 2 } })
|
||||
}
|
||||
return route.fulfill({ json: path === "/api/filters/rules" ? { rulesets: [{ serverId: "1", rules: [source] }, { serverId: "2", rules: [cached] }], greTunnels: [], live: true }
|
||||
: 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(page.getByRole("button", { name: "Копировать", exact: true })).toBeEnabled()
|
||||
await page.getByRole("button", { name: "Копировать", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
const target = dialog.getByRole("button", { name: /Роутер 2/ })
|
||||
await target.click()
|
||||
const choice = dialog.getByRole("button", { name: mode === "append" ? /^Добавить/ : /^Заменить/ })
|
||||
await choice.click()
|
||||
const submit = dialog.getByRole("button", { name: "Копировать 1 правил", exact: true })
|
||||
await submit.evaluate(button => { (button as HTMLButtonElement).click(); (button as HTMLButtonElement).click() })
|
||||
await expect.poll(() => targetReads).toBe(1)
|
||||
expect(writes).toBe(0)
|
||||
await expect(target).toBeDisabled()
|
||||
await expect(dialog.getByRole("button", { name: "Отмена", exact: true })).toBeDisabled()
|
||||
await page.keyboard.press("Escape")
|
||||
await expect(dialog).toBeVisible()
|
||||
release!()
|
||||
await expect(dialog.getByRole("alert")).toContainText("Цель недоступна тест")
|
||||
for (phase = 1; phase <= 3; phase++) {
|
||||
await submit.click()
|
||||
await expect.poll(() => targetReads).toBe(phase + 1)
|
||||
await expect(dialog.getByRole("alert")).toContainText("Не удалось получить актуальные правила целевого устройства")
|
||||
await expect(target).toHaveAttribute("aria-pressed", "true")
|
||||
await expect(choice).toHaveAttribute("aria-pressed", "true")
|
||||
expect(writes).toBe(0)
|
||||
}
|
||||
phase = 4
|
||||
await submit.click()
|
||||
await expect(dialog).toHaveCount(0)
|
||||
expect(targetReads).toBe(5)
|
||||
expect(writes).toBe(1)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user