fix(ui): различать ошибки и пустую историю WireGuard

This commit is contained in:
Denozordec committed 2026-09-29 13:42:00 +07:00
1 parent 1d1de12c58
commit d0f5649725
7 files changed
+116 -14

No files matched your search

+59
View File
@@ -468,3 +468,62 @@ test("WireGuard: восстановление требует подтвержд
await expect(page.getByText("Версия применена на роутер", { exact: true })).toBeVisible()
expect(attempts).toBe(2)
})
test("WireGuard: ошибка истории не становится пустым списком", async ({ page }) => {
await setup(page, "/wireguard?server=1")
let attempts = 0
await page.route("**/api/wireguard/revisions?**", route => {
attempts++
if (attempts === 1) return route.fulfill({ status: 403, json: { error: "История запрещена тест" } })
if (attempts === 2) return route.fulfill({ json: {} })
if (attempts === 3) return route.fulfill({ json: { revisions: [{ id: "wrong", serverId: "2", section: "wireguard", source: "apply", fingerprint: "fixture", createdAt: "2026-09-29T00:00:00Z", note: null, itemCount: 1 }] } })
return route.fulfill({ json: { revisions: [] } })
})
await page.getByRole("button", { name: "История", exact: true }).click()
const sheet = page.getByRole("dialog", { name: "История WireGuard" })
for (const message of ["История запрещена тест", "Некорректный ответ истории WireGuard", "Некорректный ответ истории WireGuard"]) {
await expect(sheet.getByRole("alert")).toContainText(message)
await expect(sheet.getByText("Истории пока нет", { exact: true })).toHaveCount(0)
await expect(sheet.getByRole("button", { name: "Откатить", exact: true })).toHaveCount(0)
await sheet.getByRole("button", { name: "Повторить загрузку" }).click()
}
await expect(sheet.getByText("Истории пока нет", { exact: true })).toBeVisible()
await expect(sheet.getByRole("alert")).toHaveCount(0)
expect(attempts).toBe(4)
})
for (const oldFails of [false, true]) {
test("WireGuard: закрытая история не меняет новый запрос " + oldFails, async ({ page }) => {
await setup(page, "/wireguard?server=1")
let releaseOld: (() => void) | undefined
let releaseNew: (() => void) | undefined
const oldGate = new Promise<void>(resolve => { releaseOld = resolve })
const newGate = new Promise<void>(resolve => { releaseNew = resolve })
let attempts = 0
await page.route("**/api/wireguard/revisions?**", async route => {
const current = ++attempts
await (current === 1 ? oldGate : newGate)
if (current === 1 && oldFails) return route.fulfill({ status: 500, json: { error: "Старая ошибка истории" } })
return route.fulfill({ json: { revisions: current === 1 ? [] : [{ id: "new", serverId: "1", section: "wireguard", source: "apply", fingerprint: "fixture", createdAt: "2026-09-29T00:00:00Z", note: null, itemCount: 9 }] } })
})
const open = page.getByRole("button", { name: "История", exact: true })
const sheet = page.getByRole("dialog", { name: "История WireGuard" })
await open.click()
await expect.poll(() => attempts).toBe(1)
await expect(sheet.getByRole("status")).toContainText("Загрузка истории")
await page.keyboard.press("Escape")
await expect(sheet).toHaveCount(0)
await open.click()
await expect.poll(() => attempts).toBe(2)
const response = page.waitForResponse(r => r.url().includes("/api/wireguard/revisions?"))
releaseOld!()
await (await response).finished()
await page.waitForTimeout(150)
await expect(sheet.getByRole("status")).toContainText("Загрузка истории")
await expect(sheet.getByRole("alert")).toHaveCount(0)
releaseNew!()
await expect(sheet).toContainText("9 интерфейсов")
await expect(sheet.getByRole("status")).toHaveCount(0)
await expect(sheet.getByRole("button", { name: "Откатить", exact: true })).toBeVisible()
})
}