fix(ui): проверять данные загрузки Filters
This commit is contained in:
1 parent
1fba16e1f2
commit
1c7ffa07a8
6 files changed
+143
-44
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
|
||||
for (const invalid of ["container", "rule", "duplicate", "server"] as const) {
|
||||
test(`Filters: повреждённый ответ ${invalid}, первый сбой, повтор и сохранение данных`, async ({ page }) => {
|
||||
let phase = 0
|
||||
const rule = { id: "rule-1", community: "65001:101", gateway: "", gatewayTunnelId: "", action: "blackhole", description: "Подтверждённые данные" }
|
||||
const server = { id: 1, name: "Реальный каталог тест", host: "192.0.2.1", type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "", status: "online", latency: 1 }
|
||||
const good = { rulesets: [{ serverId: "1", rules: [rule] }], greTunnels: [], live: true }
|
||||
const bad = invalid === "container" ? { rulesets: {} } : invalid === "rule" ? { ...good, rulesets: [{ serverId: "1", rules: [{ ...rule, description: null }] }] } : { ...good, rulesets: [{ serverId: "1", rules: [rule, rule] }] }
|
||||
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
|
||||
await page.route("**/api/**", route => {
|
||||
const path = new URL(route.request().url()).pathname
|
||||
if (path === "/api/filters/rules" && phase === 2 && invalid === "server") return route.fulfill({ status: 503, json: { error: "Опрос недоступен тест" } })
|
||||
return route.fulfill({ json: path === "/api/filters/rules" ? phase !== 1 && invalid !== "server" ? bad : good
|
||||
: path === "/api/servers" ? [phase === 0 && invalid === "server" ? { ...server, host: null } : server]
|
||||
: 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("alert").filter({ hasText: "Не удалось загрузить Filters" })).toBeVisible()
|
||||
await expect(page.locator("tr[data-row-id]")).toHaveCount(0)
|
||||
await expect(page.getByPlaceholder("Community, gateway, описание…")).toHaveCount(0)
|
||||
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toHaveCount(0)
|
||||
phase = 1
|
||||
await page.getByRole("button", { name: "Повторить загрузку", exact: true }).click()
|
||||
const rows = page.locator("tr[data-row-id]")
|
||||
await expect(rows).toHaveCount(1)
|
||||
await expect(rows.first()).toContainText("Подтверждённые данные")
|
||||
await expect(page.getByRole("option", { name: /Реальный каталог тест/ })).toHaveCount(1)
|
||||
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeEnabled()
|
||||
phase = 2
|
||||
const refresh = page.getByRole("button", { name: "Обновить", exact: true })
|
||||
await refresh.click()
|
||||
await expect(refresh).toBeEnabled()
|
||||
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeDisabled()
|
||||
await expect(rows).toHaveCount(1)
|
||||
await expect(rows.first()).toContainText("Подтверждённые данные")
|
||||
phase = 1
|
||||
await refresh.click()
|
||||
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeEnabled()
|
||||
})
|
||||
}
|
||||
|
||||
test("Filters: повреждённые подтверждённые правила не закрывают форму и не заменяют таблицу", async ({ page }) => {
|
||||
const rule = { id: "rule-1", community: "65001:101", gateway: "", gatewayTunnelId: "", action: "blackhole", description: "Прежние данные" }
|
||||
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
|
||||
await page.route("**/api/**", route => {
|
||||
const path = new URL(route.request().url()).pathname
|
||||
if (path === "/api/filters/rules" && route.request().method() === "PUT") return route.fulfill({ json: { ok: true, rules: [{ ...rule, gateway: null }] } })
|
||||
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/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(1)
|
||||
await rows.first().hover()
|
||||
await rows.first().getByRole("button", { name: "Редактировать правило", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog")
|
||||
await dialog.getByRole("textbox", { name: "Описание правила" }).fill("Сохранить ввод")
|
||||
await dialog.getByRole("button", { name: "Сохранить", exact: true }).click()
|
||||
await expect(dialog.getByRole("alert")).toContainText("Сервер не подтвердил применение правил")
|
||||
await expect(dialog.getByRole("textbox", { name: "Описание правила" })).toHaveValue("Сохранить ввод")
|
||||
await expect(rows.first()).toContainText("Прежние данные")
|
||||
await expect(page.getByText("Правила применены на роутер", { exact: true })).toHaveCount(0)
|
||||
})
|
||||
Reference in new issue
Block a user