Files
MikrotikManager/tests/e2e/large-optimizer-homes.spec.ts

55 lines
5.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect } from "@playwright/test"
import { writeFileSync } from "node:fs"
import axe from "axe-core"
import { optimizerServersSchema } from "../../lib/route-optimizer-response"
test("Оптимизатор1000 домашних устройств: профиль полного экрана", async ({ page }, info) => {
test.setTimeout(90000)
let servers = optimizerServersSchema.parse(Array.from({ length: 1000 }, (_, i) => ({ id: i+1, name: `Домашний роутер ${i+1}`, host: `10.${Math.floor(i/256)}.${i%256}.1`, type: "home-router", country: "RU", site: "MSK", enabled: true, status: null })))
let failed = false
const writes: string[] = []
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" && !path.endsWith("/preview")) writes.push(path)
if (path === "/api/servers" && failed) return r.fulfill({ status: 503, json: { error: "Каталог домашних устройств недоступен" } })
return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? servers : path === "/api/filters/rules" ? { rulesets: [] } : path === "/api/uptime/speed-probes" ? { probes: [] } : path === "/api/ospf/catalog" ? { interfaces: [], instances: [], neighbors: [], bfdSessions: [], routes: [], failures: [] } : path.endsWith("/ospf/optimize/preview") ? { serverId: 1, serverName: servers[0].name, pingWeight: 60, interfacesTotal: 0, changedCount: 0, unchangedCount: 0, interfaces: [], changes: [] } : {} })
})
const start = Date.now(); await page.goto("/route-optimizer?server=1&keep=1&home_page=200")
const cards = page.getByRole("button", { name: "WAN × JH (0×0)", exact: true })
await expect(cards).toHaveCount(5)
const scope = page.getByRole("region", { name: "Домашние устройства оптимизатора" })
await expect(scope.getByRole("status")).toContainText("996–1000 из 1000")
await expect(scope.getByText("Домашний роутер 996", { exact: true })).toBeVisible()
const profile = { servers: servers.length, bytes: Buffer.byteLength(JSON.stringify(servers)), homeCards: await cards.count(), pageNodes: await page.locator("*").count(), readyMs: Date.now()-start }
console.log("Optimizer homes pages", JSON.stringify(profile)); writeFileSync(info.outputPath("optimizer-homes-profile.json"), JSON.stringify(profile, null, 2))
await scope.getByRole("button", { name: "Предыдущая страница домашних устройств" }).click()
await expect(scope.getByRole("status")).toContainText("991–995 из 1000")
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(scope.getByRole("status")).toContainText("991–995 из 1000")
const search = scope.getByRole("textbox", { name: "Поиск домашних устройств оптимизатора" })
await search.fill("Домашний роутер 1000"); await expect(cards).toHaveCount(1)
await expect(scope.getByText("Домашний роутер 1000", { exact: true })).toBeVisible()
await page.reload(); await expect(cards).toHaveCount(1); await expect(search).toHaveValue("Домашний роутер 1000")
await expect(page).toHaveURL(url => url.searchParams.get("keep") === "1" && url.searchParams.get("server") === "1")
await search.fill(""); await expect(cards).toHaveCount(5)
await expect(scope.getByText("Домашний роутер 1", { exact: true })).toBeVisible()
await page.goBack(); await expect(scope.getByRole("status")).toContainText("996–1000 из 1000")
failed = true; await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByRole("alert").filter({ hasText: "Последний полный снимок" })).toBeVisible()
await expect(scope.getByRole("status")).toContainText("996–1000 из 1000")
await page.addStyleTag({ content: "nextjs-portal{display:none!important}" })
await page.setViewportSize({ width: 320, height: 1000 })
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(320)
await scope.evaluate(el => el.scrollIntoView({ block: "start" }))
await page.screenshot({ path: info.outputPath("optimizer-homes-pages-320.png"), animations: "disabled" })
await page.addScriptTag({ content: axe.source })
expect((await page.evaluate(async () => (window as unknown as { axe: typeof axe }).axe.run(document.querySelector('[aria-label="Домашние устройства оптимизатора"]')!, { runOnly: { type: "tag", values: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"] } }))).violations.map(v => ({ id: v.id, nodes: v.nodes.map(n => n.target) }))).toEqual([])
for (const name of ["Предыдущая страница домашних устройств", "Следующая страница домашних устройств"]) expect((await scope.getByRole("button", { name }).boundingBox())!.height).toBeGreaterThanOrEqual(44)
failed = false; servers = servers.slice(0, 1)
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(cards).toHaveCount(1); await expect(scope.getByText("Домашний роутер 1", { exact: true })).toBeVisible()
await expect(page).toHaveURL(url => !url.searchParams.has("home_page") && url.searchParams.get("server") === "1" && url.searchParams.get("keep") === "1")
expect(writes).toEqual([])
})