fix(ui): сохранять подтверждённые данные GRE при отказах

This commit is contained in:
Denozordec committed 2026-09-30 15:49:26 +07:00
1 parent 6ea3cdad0e
commit fb009344e1
7 files changed
+183 -104

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
import { test, expect } from "@playwright/test"
const tunnel = (id: string, name = "Туннель " + id) => ({ id: "*1", serverId: id, name, localAddress: "192.0.2.1", remoteAddress: "192.0.2.2", localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "live", ipsec: null, mtu: 1476, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: true, comment: "", enabled: true, status: "up" })
const servers = [1, 2].map(id => ({ id, name: "Роутер " + id, host: "192.0.2." + id, enabled: true, country: "RU", type: "exit-node", status: null, latency: null }))
const full = { tunnels: [tunnel("1"), tunnel("2")] }
for (const broken of ["http", "payload", "duplicate", "conflict", "duplicate-failure", "blank-failure", "inventory"]) {
test(`GRE: неизвестное начало, сохранение кэша и восстановление ${broken}`, async ({ page }) => {
let phase = 0
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
await page.route("**/api/**", r => {
const path = new URL(r.request().url()).pathname
if (path === "/api/servers") return r.fulfill({ json: phase === 2 && broken === "inventory" ? [servers[0], servers[0]] : servers })
if (path === "/api/gre/tunnels") {
if (phase === 0 || phase === 2 && broken === "http") return r.fulfill({ status: 503, json: { error: "GRE недоступен тест" } })
const failure = { serverId: "2", error: "Сбой роутера тест" }
return r.fulfill({ json: phase !== 2 ? full : broken === "payload" ? { tunnels: [{}] }
: broken === "duplicate" ? { tunnels: [tunnel("1"), tunnel("1")] }
: broken === "conflict" ? { ...full, failures: [failure] }
: broken === "duplicate-failure" ? { tunnels: [], failures: [failure, failure] }
: broken === "blank-failure" ? { tunnels: [], failures: [{ ...failure, serverId: " " }] } : full })
}
return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/gre")
const alert = page.getByRole("alert").filter({ hasText: "Не удалось загрузить GRE" })
await expect(alert).toContainText("Данные пока неизвестны")
await expect(page.getByText("Нет GRE-туннелей", { exact: true })).toHaveCount(0)
await expect(page.getByLabel("Сводка GRE")).toContainText("неизвестно")
phase = 1
await alert.getByRole("button", { name: "Повторить загрузку GRE" }).click()
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(2)
await expect(page.getByRole("option").filter({ hasText: "Роутер 1" })).toContainText("Статус неизвестен")
phase = 2
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(alert).toContainText("Показаны последние полученные данные")
await expect(rows).toHaveCount(2)
await expect(rows.filter({ hasText: "Неизвестно" })).toHaveCount(2)
await expect(page.getByLabel("Сводка GRE")).toContainText("неизвестно")
phase = 3
await alert.getByRole("button", { name: "Повторить загрузку GRE" }).click()
await expect(alert).toHaveCount(0)
await expect(rows.filter({ hasText: "Неизвестно" })).toHaveCount(0)
})
}
test("GRE: частичный отказ сохраняет строки устройства, успешный пустой опрос очищает", async ({ page }) => {
let phase = 0
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
await page.route("**/api/**", r => {
const path = new URL(r.request().url()).pathname
return r.fulfill({ json: path === "/api/servers" ? servers : path === "/api/gre/tunnels" ? phase === 0 ? full : phase === 1 ? { tunnels: [tunnel("1", "Обновлённый GRE")], failures: [{ serverId: "2", serverName: "Роутер 2", error: "Таймаут тест" }] } : { tunnels: [tunnel("1", "Обновлённый GRE")] } : path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/gre")
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(2)
phase = 1
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByRole("alert").filter({ hasText: "Не удалось опросить часть роутеров" })).toContainText("Роутер 2: Таймаут тест")
await expect(rows).toHaveCount(2)
await expect(rows.filter({ hasText: "Туннель 2" })).toContainText("Неизвестно")
await expect(rows.filter({ hasText: "Обновлённый GRE" })).toContainText("Up")
phase = 2
await page.getByRole("button", { name: "Повторить загрузку GRE" }).click()
await expect(rows).toHaveCount(1)
await expect(rows.filter({ hasText: "Туннель 2" })).toHaveCount(0)
})
+2 -1
View File
@@ -69,7 +69,8 @@ test("GRE: прямая ссылка, сброс, назад, reload и ошиб
control.partial = true
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(context).toContainText("Не удалось получить данные выбранного сервера")
await expect(rows).toHaveCount(0)
await expect(rows).toHaveCount(1)
await expect(rows).toContainText("Неизвестно")
expect(control.posts).toEqual([])
await page.setViewportSize({ width: 390, height: 844 })
await context.scrollIntoViewIfNeeded()