Files
MikrotikManager/tests/e2e/ipsec-gre-tables.spec.ts

68 lines
4.0 KiB
TypeScript

import { test, expect, type Page } from "@playwright/test"
import { ipsecListResponseSchema } from "../../packages/contracts/src/ipsec"
import type { GreTunnel } from "../../lib/data"
const ids = Array.from({ length: 12 }, (_, i) => i + 1)
const ipsec = ipsecListResponseSchema.parse({ servers: [], clients: ids.map(i => ({
id: String(i), rosId: `*${i}`, serverId: "1", serverName: "Тестовый роутер",
name: `Клиент ${i}`, authMethod: "certificate", online: false, disabled: false, managed: true,
})) })
const tunnels: GreTunnel[] = ids.map(i => ({
id: String(i), name: `gre-test-${i}`, serverId: "1", localAddress: "192.0.2.1",
remoteAddress: `192.0.2.${i + 1}`, localInnerIp: `10.0.${i}.1/30`, remoteInnerIp: `10.0.${i}.2/30`,
poolId: `pool-${i}`, ipsec: null, mtu: 1400 + i, keepaliveInterval: 10, keepaliveRetries: 3,
dscp: "inherit", clampTcpMss: true, allowFastPath: true, comment: "Тест", enabled: true, status: "up",
}))
async function setup(page: Page, path: string, empty = false) {
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", route => {
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" ? [{ id: 1, name: "Тестовый роутер", host: "192.0.2.1", enabled: true, country: "RU" }] : {} })
})
await page.goto(path)
}
test("IPsec: 12 клиентов, сортировка, выбор удаления и поиск", async ({ page }) => {
await setup(page, "/ipsec")
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(12)
await page.getByRole("table").getByRole("button", { name: "Клиент", exact: true }).click()
await expect(rows.first()).toContainText("Клиент 1")
await page.getByRole("table").getByRole("button", { name: "Клиент", exact: true }).click()
await expect(rows.first()).toContainText("Клиент 12")
await rows.first().getByRole("button", { name: "Удалить клиента" }).click()
await expect(page.getByRole("alertdialog")).toContainText("Клиент 12")
await page.getByRole("button", { name: "Отмена", exact: true }).click()
await page.getByPlaceholder("Поиск по имени / CN / IP…").fill("Клиент 12")
await expect(rows).toHaveCount(1)
})
test("GRE: 12 туннелей, числовая сортировка и достоверность пулов", async ({ page }) => {
const errors: string[] = []
page.on("pageerror", e => errors.push(e.message))
await setup(page, "/gre")
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(12)
await page.getByRole("button", { name: "MTU", exact: true }).click()
await expect(rows.first()).toContainText("gre-test-12")
await page.getByPlaceholder("Поиск по имени, IP…").fill("gre-test-12")
await expect(rows).toHaveCount(1)
await page.getByPlaceholder("Поиск по имени, IP…").fill("")
await page.getByRole("button", { name: "IP-пулы", exact: true }).click()
await expect(rows).toHaveCount(0)
await expect(page.getByRole("status").filter({ hasText: "Каталог пулов, CIDR и свободная ёмкость не предоставляются" })).toBeVisible()
expect(errors).toEqual([])
})
test("Пустые ответы IPsec и GRE", async ({ page }) => {
await setup(page, "/ipsec", true)
await expect(page.getByText("Нет клиентов IKEv2", { exact: true })).toBeVisible()
await page.goto("/gre")
await expect(page.getByText("Нет GRE-туннелей", { exact: true })).toBeVisible()
await page.getByRole("button", { name: "IP-пулы", exact: true }).click()
await expect(page.getByRole("status").filter({ hasText: "Каталог пулов, CIDR и свободная ёмкость не предоставляются" })).toBeVisible()
})