fix(ui): учитывать готовность устройства в действиях IPsec

This commit is contained in:
Denozordec committed 2026-09-30 14:48:21 +07:00
1 parent b8923d075d
commit f0071a495c
7 files changed
+97 -12

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ async function setup(page: Page, path: string, empty = false) {
const path = new URL(route.request().url()).pathname
return route.fulfill({ json: path === "/api/ipsec" ? (empty ? { servers: [], clients: [] } : ipsec)
: path === "/api/gre/tunnels" ? { tunnels: empty ? [] : tunnels }
: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? [] : {} })
: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? [{ id: 1, name: "Тестовый роутер", host: "192.0.2.1", enabled: true, country: "RU" }] : {} })
})
await page.goto(path)
}
+47
View File
@@ -0,0 +1,47 @@
import { test, expect } from "@playwright/test"
test("IPsec: действия требуют актуальный опрос конкретного устройства", async ({ page }) => {
const devices = [1, 2].map(id => ({ id, name: "Устройство " + id, host: "192.0.2." + id, enabled: true, country: "RU" }))
const clients = ["1", "2"].map(id => ({ id: id + "-*1", rosId: "*1", serverId: id, serverName: "Устройство " + id, name: "Клиент " + id, authMethod: "certificate", kind: "cert", online: false, disabled: false, managed: true }))
const summaries = ["1", "2"].map(id => ({ serverId: id, serverName: "Устройство " + id, initialized: false, ike2Ready: false, peers: [], natRuleManaged: false, clientsTotal: 1, clientsOnline: 0 }))
let phase = 0, writes = 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 (r.request().method() !== "GET") { writes++; return r.fulfill({ json: { ok: true } }) }
if (path === "/api/ipsec") {
if (phase === 0 || phase === 3) return r.fulfill({ status: 503, json: { error: "Опрос недоступен тест" } })
return r.fulfill({ json: phase === 2 ? { servers: [summaries[0]], clients: [clients[0]], failures: [{ serverId: "2", error: "Таймаут тест" }] } : { servers: summaries, clients } })
}
return r.fulfill({ json: path === "/api/servers" ? devices : path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/ipsec")
const add = page.getByRole("button", { name: "Новый клиент", exact: true })
await expect(page.getByRole("alert").filter({ hasText: "Не удалось загрузить IPsec" })).toBeVisible()
await expect(add).toBeDisabled()
phase = 1
await page.getByRole("button", { name: "Обновить", exact: true }).click()
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(2)
await expect(add).toBeEnabled()
const one = rows.filter({ hasText: "Клиент 1" }), two = rows.filter({ hasText: "Клиент 2" })
await expect(two.getByRole("button", { name: "Удалить клиента" })).toBeEnabled()
phase = 2
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByRole("alert").filter({ hasText: "Не удалось опросить часть роутеров" })).toBeVisible()
await expect(rows).toHaveCount(2)
await expect(two.getByRole("button", { name: "Удалить клиента" })).toBeDisabled()
await expect(two.getByRole("button", { name: "Клиент 2", exact: true })).toBeDisabled()
await expect(one.getByRole("button", { name: "Удалить клиента" })).toBeEnabled()
await expect(add).toBeEnabled()
phase = 3
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByRole("alert").filter({ hasText: "Не удалось загрузить IPsec" })).toBeVisible()
await expect(one.getByRole("button", { name: "Удалить клиента" })).toBeDisabled()
await expect(add).toBeDisabled()
phase = 4
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(add).toBeEnabled()
await expect(two.getByRole("button", { name: "Удалить клиента" })).toBeEnabled()
expect(writes).toBe(0)
})