fix(ui): проверять ревизии и сохранять ошибки истории

This commit is contained in:
Denozordec committed 2026-09-29 19:04:00 +07:00
1 parent 46d62c98b8
commit 4a8d696e4e
11 files changed
+183 -98

No files matched your search

+59 -41
View File
@@ -68,47 +68,65 @@ for (const section of ["wireguard", "ipsec", "gre", "firewall", "filters", "recu
})
}
test("История IPsec: ошибка, повтор и поздний ответ закрытой панели", async ({ page }) => {
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/ipsec/revisions") {
attempts++
if (attempts === 1) return route.fulfill({ status: 403, json: { error: "История недоступна тест" } })
if (attempts === 2) {
await gate
return route.fulfill({ status: 500, json: { error: "Устаревшая ошибка тест" } })
for (const section of ["ipsec", "gre", "firewall", "filters", "recursive-routes"]) {
test(`История ${section}: ошибка, повтор и поздний ответ закрытой панели`, async ({ page }) => {
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/${section}/revisions`) {
attempts++
if (attempts === 1) return route.fulfill({ status: 403, json: { error: "История недоступна тест" } })
if (attempts === 2) {
await gate
return route.fulfill({ status: 500, json: { error: "Устаревшая ошибка тест" } })
}
if (attempts === 3) return route.fulfill({ json: {} })
const revision = { id: "rev/1", serverId: "1", section, source: "apply", fingerprint: "fixture", createdAt: "2026-09-29T00:00:00Z", note: null, itemCount: 1 }
if (attempts === 4) return route.fulfill({ json: { revisions: [{ ...revision, serverId: "2" }] } })
if (attempts === 5) return route.fulfill({ json: { revisions: [{ ...revision, section: "wireguard" }] } })
if (attempts === 6) return route.fulfill({ json: { revisions: [{ ...revision, createdAt: "invalid" }] } })
return route.fulfill({ json: { revisions: [] } })
}
if (attempts === 3) return route.fulfill({ json: {} })
return route.fulfill({ json: { revisions: [] } })
return route.fulfill({ json: path === "/api/auth/config" ? { required: false }
: 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 }
: path === "/api/servers" ? [{ id: 1, name: "История роутер", host: "192.0.2.1", enabled: true, type: "exit-node", country: "RU", status: "online" }] : {} })
})
await page.goto(`/${section}?server=1`)
if (section === "ipsec") await page.getByRole("option").filter({ hasText: "История роутер" }).click()
const open = page.getByRole("button", { name: "История", exact: true })
const sheet = page.getByRole("dialog")
await open.click()
await expect(sheet.getByRole("alert")).toContainText("История недоступна тест")
await expect(sheet.getByText("Истории пока нет", { exact: true })).toHaveCount(0)
await sheet.getByRole("button", { name: "Повторить загрузку" }).click()
await expect.poll(() => attempts).toBe(2)
await expect(sheet.getByRole("status")).toContainText("Загрузка истории")
await page.keyboard.press("Escape")
await expect(sheet).toHaveCount(0)
await open.click()
await expect(sheet.getByRole("alert")).toContainText("Некорректный ответ истории")
for (let attempt = 4; attempt <= 6; attempt++) {
await sheet.getByRole("button", { name: "Повторить загрузку" }).click()
await expect.poll(() => attempts).toBe(attempt)
await expect(sheet.getByRole("alert")).toContainText("Некорректный ответ истории")
await expect(sheet.getByRole("button", { name: "Откатить", exact: true })).toHaveCount(0)
}
return route.fulfill({ json: path === "/api/auth/config" ? { required: false }
: path === "/api/ipsec" ? { servers: [], clients: [] }
: path === "/api/servers" ? [{ id: 1, name: "История роутер", host: "192.0.2.1", enabled: true, type: "exit-node", country: "RU", status: "online" }] : {} })
await sheet.getByRole("button", { name: "Повторить загрузку" }).click()
await expect(sheet.getByText("Истории пока нет", { exact: true })).toBeVisible()
const response = page.waitForResponse(r => r.url().includes(`/api/${section}/revisions?`))
release!()
await (await response).finished()
await page.waitForTimeout(150)
await expect(sheet.getByRole("alert")).toHaveCount(0)
await expect(sheet.getByText("Истории пока нет", { exact: true })).toBeVisible()
})
await page.goto("/ipsec")
await page.getByRole("option").filter({ hasText: "История роутер" }).click()
const open = page.getByRole("button", { name: "История", exact: true })
const sheet = page.getByRole("dialog", { name: "История конфигураций IPsec" })
await open.click()
await expect(sheet.getByRole("alert")).toContainText("История недоступна тест")
await expect(sheet.getByText("Истории пока нет", { exact: true })).toHaveCount(0)
await sheet.getByRole("button", { name: "Повторить загрузку" }).click()
await expect.poll(() => attempts).toBe(2)
await expect(sheet.getByRole("status")).toContainText("Загрузка истории")
await page.keyboard.press("Escape")
await expect(sheet).toHaveCount(0)
await open.click()
await expect(sheet.getByRole("alert")).toContainText("Некорректный ответ истории IPsec")
await sheet.getByRole("button", { name: "Повторить загрузку" }).click()
await expect(sheet.getByText("Истории пока нет", { exact: true })).toBeVisible()
const response = page.waitForResponse(r => r.url().includes("/api/ipsec/revisions?"))
release!()
await (await response).finished()
await page.waitForTimeout(150)
await expect(sheet.getByRole("alert")).toHaveCount(0)
await expect(sheet.getByText("Истории пока нет", { exact: true })).toBeVisible()
})
}