fix(ui): сохранять подтверждение восстановления при ошибке
This commit is contained in:
1 parent
221d6db10c
commit
1d1de12c58
12 files changed
+134
-35
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
|
||||
for (const section of ["wireguard", "ipsec", "gre", "firewall", "filters", "recursive-routes"]) {
|
||||
test(`История ${section}: ошибка сохраняет подтверждение, повтор закрывает`, async ({ page }) => {
|
||||
const errors: string[] = []
|
||||
page.on("pageerror", error => errors.push(error.message))
|
||||
page.on("console", message => { if (message.type() === "error") errors.push(message.text()) })
|
||||
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.endsWith("/restore")) {
|
||||
expect(decodeURIComponent(path)).toBe(`/api/${section}/revisions/rev/1/restore`)
|
||||
expect(route.request().postDataJSON()).toEqual({ serverId: "1" })
|
||||
attempts++
|
||||
if (attempts === 1) {
|
||||
await gate
|
||||
return route.fulfill({ status: 403, json: { error: "Восстановление запрещено тест" } })
|
||||
}
|
||||
return route.fulfill({ json: { ok: true, routes: [], rules: [] } })
|
||||
}
|
||||
const json = path.endsWith("/revisions") ? { revisions: [{ id: "rev/1", serverId: "1", section, source: "apply", fingerprint: "fixture", createdAt: "2026-09-29T00:00:00Z", note: null, itemCount: 1 }] }
|
||||
: path === "/api/auth/config" ? { required: false }
|
||||
: 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/wireguard" ? { interfaces: [] }
|
||||
: path === "/api/ipsec" ? { servers: [], clients: [] }
|
||||
: path === "/api/gre/tunnels" || path === "/api/filters/gre-tunnels" ? { tunnels: [] }
|
||||
: path === "/api/firewall/all" ? { rules: [], addressLists: [] }
|
||||
: path === "/api/filters/rules" ? { rulesets: [{ serverId: "1", rules: [] }], greTunnels: [], live: true }
|
||||
: path === "/api/recursive-routes" ? { routes: [] }
|
||||
: path === "/api/recursive-routes/gateways" ? { gateways: [] }
|
||||
: path === "/api/evobgp/settings" ? { enabled: false, baseUrl: "", secretConfigured: false } : {}
|
||||
return route.fulfill({ json })
|
||||
})
|
||||
await page.goto(`/${section}?server=1`)
|
||||
if (section === "ipsec") await page.getByRole("option").filter({ hasText: "История роутер" }).click()
|
||||
await page.getByRole("button", { name: "История", exact: true }).click()
|
||||
const sheet = page.getByRole("dialog")
|
||||
await sheet.getByRole("button", { name: "Откатить", exact: true }).click()
|
||||
const dialog = page.getByRole("alertdialog")
|
||||
await dialog.getByRole("button", { name: "Откатить", exact: true }).evaluate(button => { (button as HTMLButtonElement).click(); (button as HTMLButtonElement).click() })
|
||||
await expect.poll(() => attempts).toBe(1)
|
||||
await expect(dialog.getByRole("status")).toContainText("Ожидание результата")
|
||||
await expect(dialog.getByRole("button", { name: "Отмена" })).toBeDisabled()
|
||||
await page.keyboard.press("Escape")
|
||||
await expect(dialog).toBeVisible()
|
||||
release!()
|
||||
await expect(dialog.getByRole("alert").filter({ hasText: "Восстановление запрещено тест" })).toBeVisible()
|
||||
await expect(dialog.getByRole("button", { name: "Откатить", exact: true })).toBeEnabled()
|
||||
await dialog.getByRole("button", { name: "Откатить", exact: true }).click()
|
||||
await expect(dialog).toHaveCount(0)
|
||||
expect(attempts).toBe(2)
|
||||
await sheet.getByRole("button", { name: "Откатить", exact: true }).click()
|
||||
await expect(dialog.getByText("Восстановление запрещено тест")).toHaveCount(0)
|
||||
await page.keyboard.press("Escape")
|
||||
await expect(dialog).toHaveCount(0)
|
||||
expect(errors.filter(error => !error.includes("403 (Forbidden)"))).toEqual([])
|
||||
})
|
||||
}
|
||||
@@ -461,10 +461,9 @@ test("WireGuard: восстановление требует подтвержд
|
||||
await expect.poll(() => attempts).toBe(1)
|
||||
await expect(confirm.getByRole("button", { name: "Откатить", exact: true })).toBeDisabled()
|
||||
release!()
|
||||
await expect(page.getByText("Не удалось откатить", { exact: true })).toBeVisible()
|
||||
await expect(confirm.getByRole("alert").filter({ hasText: "Сервер не подтвердил восстановление" })).toBeVisible()
|
||||
await expect(page.getByText("Версия применена на роутер", { exact: true })).toHaveCount(0)
|
||||
await expect(confirm).toHaveCount(0)
|
||||
await sheet.getByRole("button", { name: "Откатить", exact: true }).click()
|
||||
await expect(confirm).toBeVisible()
|
||||
await confirm.getByRole("button", { name: "Откатить", exact: true }).click()
|
||||
await expect(page.getByText("Версия применена на роутер", { exact: true })).toBeVisible()
|
||||
expect(attempts).toBe(2)
|
||||
|
||||
Reference in new issue
Block a user