52 lines
3.0 KiB
TypeScript
52 lines
3.0 KiB
TypeScript
import { test, expect } from "@playwright/test"
|
|
|
|
test("GRE: удаление сохраняет диалог и требует подтверждения", async ({ page }) => {
|
|
let attempts = 0
|
|
let release: (() => void) | undefined
|
|
const gate = new Promise<void>(resolve => { release = resolve })
|
|
const tunnel = { id: "*T/1", name: "gre-test", serverId: "1", localAddress: "192.0.2.1", remoteAddress: "192.0.2.2", localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "pool", ipsec: null, mtu: 1476, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: true, comment: "", enabled: true, status: "up" }
|
|
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 (route.request().method() === "DELETE") {
|
|
attempts++
|
|
expect(path).toBe("/api/gre/tunnels")
|
|
expect(route.request().postDataJSON()).toEqual({ serverId: "1", rosId: "*T/1", name: "gre-test" })
|
|
if (attempts === 1) { await gate; return route.fulfill({ status: 403, json: { error: "Удаление запрещено тест" } }) }
|
|
if (attempts === 2) return route.fulfill({ json: {} })
|
|
if (attempts === 3) return route.fulfill({ json: { ok: false } })
|
|
return route.fulfill({ json: { ok: true } })
|
|
}
|
|
return route.fulfill({ json: path === "/api/auth/config" ? { required: false }
|
|
: path === "/api/gre/tunnels" ? { tunnels: [tunnel] }
|
|
: path === "/api/servers" ? [{ id: 1, name: "Роутер", host: "192.0.2.1", enabled: true, type: "exit-node", country: "RU", status: "online" }] : {} })
|
|
})
|
|
await page.goto("/gre")
|
|
const open = async () => {
|
|
await page.getByRole("button", { name: "Действия: gre-test" }).click()
|
|
await page.getByRole("menuitem", { name: "Удалить туннель" }).click()
|
|
}
|
|
await open()
|
|
const dialog = page.getByRole("alertdialog")
|
|
const remove = dialog.getByRole("button", { name: "Удалить", exact: true })
|
|
await remove.evaluate(button => { (button as HTMLButtonElement).click(); (button as HTMLButtonElement).click() })
|
|
await expect.poll(() => attempts).toBe(1)
|
|
await expect(dialog.getByRole("status")).toContainText("Ожидание результата")
|
|
await expect(dialog.getByRole("button", { name: "Отмена" })).toBeDisabled()
|
|
await page.keyboard.press("Escape")
|
|
await expect(dialog).toBeVisible()
|
|
release!()
|
|
await expect(dialog.getByRole("alert")).toContainText("Удаление запрещено тест")
|
|
for (let i = 2; i <= 3; i++) {
|
|
await remove.click()
|
|
await expect.poll(() => attempts).toBe(i)
|
|
await expect(dialog.getByRole("alert")).toContainText("Сервер не подтвердил удаление туннеля")
|
|
await expect(page.getByText("Удалён gre-test", { exact: true })).toHaveCount(0)
|
|
}
|
|
await remove.click()
|
|
await expect(dialog).toHaveCount(0)
|
|
expect(attempts).toBe(4)
|
|
await open()
|
|
await expect(dialog.getByRole("alert")).toHaveCount(0)
|
|
})
|