Files
MikrotikManager/tests/e2e/ipsec-layout.spec.ts
T

58 lines
4.9 KiB
TypeScript

import { test, expect } from "@playwright/test"
import { mkdirSync } from "node:fs"
for (const device of ["desktop", "mobile"] as const) {
test(`IPsec: клавиатура, контекст и layout ${device}`, async ({ page }) => {
await page.setViewportSize(device === "desktop" ? { width: 1440, height: 1000 } : { width: 390, height: 844 })
await page.clock.install({ time: new Date("2026-09-30T05:00:00Z") })
const devices = [1, 2].map(id => ({ id, name: id === 1 ? "Основной VPN роутер" : "Резервный VPN роутер", host: "192.0.2." + id, country: "RU", enabled: true, type: "exit-node", status: "online" }))
const clients = ["1", "2"].map(id => ({ id: id + "-*1", rosId: "*1", serverId: id, serverName: devices[Number(id) - 1].name, name: id === "1" ? "Ноутбук инженера" : "Резервный клиент", authMethod: "pre-shared-key", kind: "psk", remoteId: "engineer", peerName: "ikev2-vpn", online: false, disabled: false, managed: true }))
const summaries = ["1", "2"].map(id => ({ serverId: id, serverName: devices[Number(id) - 1].name, initialized: true, ike2Ready: true, serverEndpoint: "vpn.example.test", caCert: { name: "vpn-ca", role: "ca", managed: true, trusted: true }, natRuleManaged: true, clientsTotal: 1, clientsOnline: 0, peers: [{ id: id + "-*p1", rosId: "*p1", serverId: id, serverName: devices[Number(id) - 1].name, name: "ikev2-vpn", passive: true, exchangeMode: "ike2", profile: "vpn-profile", address: "0.0.0.0/0", disabled: false, managed: true }], certs: [{ name: "vpn-ca", role: "ca", managed: true, trusted: true }] }))
let 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() === "PATCH") {
writes++
expect(path).toContain(device === "mobile" ? "/users/2/" : "/users/1/")
expect(r.request().postDataJSON()).toMatchObject({ name: "Проверенный клиент" })
clients[device === "mobile" ? 1 : 0].name = "Проверенный клиент"
return r.fulfill({ json: { ok: true } })
}
return r.fulfill({ json: path === "/api/ipsec" ? { servers: summaries, clients } : path === "/api/servers" ? devices : path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/ipsec")
await expect(page.locator("tr[data-row-id]")).toHaveCount(2)
await expect(page.getByRole("button", { name: "Новый клиент", exact: true })).toBeEnabled()
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
await page.addStyleTag({ content: "nextjs-portal { display: none !important; }" })
mkdirSync("docs/ux-ui/screens", { recursive: true })
await page.screenshot({ path: test.info().outputPath(`ipsec-${device}.png`), animations: "disabled" })
if (device === "mobile") {
await page.getByRole("button", { name: "Серверы", exact: true }).click()
await page.getByRole("dialog").getByRole("option").filter({ hasText: "Резервный VPN роутер" }).click()
await expect(page.getByRole("dialog")).toHaveCount(0)
await expect(page.locator("tr[data-row-id]")).toHaveCount(1)
}
const edit = page.getByRole("button", { name: device === "mobile" ? "Резервный клиент" : "Ноутбук инженера", exact: true })
await edit.focus()
await page.keyboard.press("Enter")
const dialog = page.getByRole("dialog")
await dialog.getByRole("textbox", { name: "Имя клиента" }).fill("Проверенный клиент")
await expect.poll(() => dialog.evaluate(el => el.getBoundingClientRect().left >= 0 && el.getBoundingClientRect().right <= innerWidth)).toBe(true)
await page.screenshot({ path: test.info().outputPath(`ipsec-client-${device}.png`), animations: "disabled" })
await dialog.getByRole("button", { name: "Сохранить", exact: true }).focus()
await page.keyboard.press("Enter")
await expect(dialog).toHaveCount(0)
await expect(page.locator("tr[data-row-id]").filter({ hasText: "Проверенный клиент" })).toHaveCount(1)
expect(writes).toBe(1)
await page.getByRole("tab", { name: "Сервер", exact: true }).click()
await expect(page.getByRole("button", { name: "Переинициализировать", exact: true }).first()).toBeEnabled()
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
await page.clock.fastForward(6000)
await expect(page.getByText("Клиент обновлён", { exact: true })).toHaveCount(0)
if (device === "mobile") await page.getByRole("button", { name: "Переинициализировать", exact: true }).scrollIntoViewIfNeeded()
await page.screenshot({ path: test.info().outputPath(`ipsec-servers-${device}.png`), animations: "disabled" })
})
}