fix(ui): подтверждать создание интерфейса и пира WireGuard

This commit is contained in:
Denozordec committed 2026-09-29 08:30:07 +07:00
1 parent ec6ec52965
commit 8fff3d7fff
8 files changed
+166 -52

No files matched your search

+63
View File
@@ -251,3 +251,66 @@ test("WireGuard: импорт удерживает форму до ответа
await page.keyboard.press("Escape")
await expect(dialog).toHaveCount(0)
})
for (const kind of ["interface", "interface-dto", "peer"] as const) {
test("WireGuard: создание сохраняет форму и ждёт подтверждения " + kind, async ({ page }) => {
await setup(page, "/wireguard?server=1&interface=*%2F2")
const peer = kind === "peer"
let attempts = 0
let release: (() => void) | undefined
const gate = new Promise<void>(resolve => { release = resolve })
await page.route("**/api/wireguard/" + (peer ? "peers" : "interfaces"), async route => {
const body = route.request().postDataJSON()
expect(body.serverId).toBe("1")
expect(body[peer ? "interfaceName" : "name"]).toBe(peer ? "wg-same" : "wg-new")
if (peer) {
expect(body.publicKey).toBe("fixture-public-key")
expect(body.allowedAddresses).toEqual(["10.0.3.1/32"])
}
attempts++
if (attempts === 1) {
await gate
return route.fulfill({ status: 403, json: { error: "Создание запрещено тест" } })
}
if (attempts === 2) return route.fulfill({ json: {} })
const dto = wgListResponseSchema.parse({ interfaces: [{ id: "new", rosId: "*N", serverId: "1", serverName: "Источник", name: "wg-new", listenPort: 13231, mtu: 1420, comment: "", enabled: true, status: "down", peers: [] }] }).interfaces[0]
return route.fulfill({ status: 201, json: kind === "interface-dto" ? dto : peer ? { ok: true } : { ok: true, name: "wg-new" } })
})
const open = async () => {
if (peer) {
await page.getByRole("button", { name: "Действия: wg-same" }).click()
await page.getByRole("menuitem", { name: "Добавить пира" }).click()
} else await page.getByRole("button", { name: "Новый интерфейс", exact: true }).click()
}
await expect(page.locator("tr[data-row-id]")).toHaveCount(1)
await open()
const dialog = page.getByRole("dialog", { name: peer ? "Добавить пира" : "Быстрый туннель WireGuard" })
const input = dialog.getByRole("textbox", { name: peer ? "Public key" : "Имя интерфейса", exact: true })
await input.fill(peer ? "fixture-public-key" : "wg-new")
if (peer) await dialog.getByRole("textbox", { name: "Allowed IPs", exact: true }).fill("10.0.3.1/32")
const submit = dialog.getByRole("button", { name: peer ? "Добавить" : "Создать туннель", exact: true })
await submit.evaluate(button => { (button as HTMLButtonElement).click(); (button as HTMLButtonElement).click() })
await expect.poll(() => attempts).toBe(1)
await expect(input).toBeDisabled()
if (!peer) await expect(dialog.getByRole("switch", { name: "Интерфейс включён" })).toBeDisabled()
await expect(dialog.getByRole("status")).toContainText("Ожидание подтверждения")
await expect(dialog.getByRole("button", { name: "Отмена" })).toBeDisabled()
await expect(dialog.getByRole("button", { name: "Закрыть", exact: true })).toHaveCount(0)
await page.keyboard.press("Escape")
await page.mouse.click(10, 300)
await expect(dialog).toBeVisible()
release!()
await expect(dialog.getByRole("alert")).toHaveText("Создание запрещено тест")
await expect(input).toHaveValue(peer ? "fixture-public-key" : "wg-new")
await submit.click()
await expect(dialog.getByRole("alert")).toContainText("Сервер не подтвердил создание")
await submit.click()
await expect(dialog).toHaveCount(0)
expect(attempts).toBe(3)
await open()
await expect(dialog.getByRole("alert")).toHaveCount(0)
await expect(input).toHaveValue("")
await page.keyboard.press("Escape")
await expect(dialog).toHaveCount(0)
})
}