53 lines
4.7 KiB
TypeScript
53 lines
4.7 KiB
TypeScript
import { test, expect } from "@playwright/test"
|
||
import axe from "axe-core"
|
||
import { mkdirSync } from "node:fs"
|
||
|
||
test("Speed history200: DOM, сортировка, refresh, уменьшение и320px", async ({ page }, info) => {
|
||
const servers = [1, 2].map(id => ({ id, name: id === 1 ? "Источник" : "Назначение", host: "192.0.2." + id, type: "exit-node", enabled: true, country: "RU", site: "TEST", sessions: 0, status: "online", wanUplinks: [] }))
|
||
let runs = Array.from({ length: 200 }, (_, i) => ({ id: String(i + 1), srcServerId: "1", dstServerId: "2", srcInterface: "ether1", dstInterface: "ether1", srcInterfaceAddress: "10.0.0.1", dstInterfaceAddress: "10.0.0.2", protocol: "tcp", direction: "both", durationSec: 10, txAvgMbps: 200 - i, rxAvgMbps: i, status: "done", error: null, afterBtPing: { rttMs: 0, lossPct: 0, error: null }, createdAt: new Date(Date.parse("2026-10-03T00:00:00Z") + i * 60000).toISOString() }))
|
||
let calls = 0; 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") writes.push(path)
|
||
if (path === "/api/uptime/speed-test/runs") calls++
|
||
return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/servers" ? servers : path === "/api/uptime/overview" ? { probes: [], resources: [] } : path === "/api/uptime/speed-probes" ? { probes: [] } : path === "/api/uptime/speed-test/runs" ? { runs } : {} })
|
||
})
|
||
const start = Date.now(); await page.goto("/uptime?tab=speed")
|
||
const rows = page.locator("tr[data-row-id]")
|
||
await expect(page.locator('tr[data-row-id="200"]')).toBeVisible()
|
||
const sample = { fixtureRows: 200, fixtureBytes: Buffer.byteLength(JSON.stringify(runs)), renderedRows: await rows.count(), domNodes: await page.locator("*").count(), readyMs: Date.now() - start }
|
||
console.log(JSON.stringify(sample)); await info.attach("speed-history-metrics", { body: JSON.stringify(sample), contentType: "application/json" })
|
||
expect(sample.renderedRows).toBe(50); expect(sample.domNodes).toBeLessThan(4000)
|
||
await page.getByRole("button", { name: "Перейти на страницу 4", exact: true }).click()
|
||
await expect(rows.last()).toHaveAttribute("data-row-id", "1")
|
||
await page.getByRole("button", { name: "Перейти на страницу 1", exact: true }).click()
|
||
await page.getByRole("table").getByRole("button", { name: "TX avg", exact: true }).click()
|
||
await expect(rows.first()).toHaveAttribute("data-row-id", "1")
|
||
await page.getByRole("button", { name: "Следующая страница", exact: true }).click()
|
||
await expect(rows.first()).toHaveAttribute("data-row-id", "51")
|
||
const before = calls; await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||
await expect.poll(() => calls).toBeGreaterThan(before)
|
||
await expect(page.getByRole("button", { name: "Обновить", exact: true })).toBeEnabled()
|
||
await expect(page.getByText("51–100 из 200", { exact: true })).toBeVisible()
|
||
await expect(rows.first()).toHaveAttribute("data-row-id", "51")
|
||
await page.setViewportSize({ width: 320, height: 1000 })
|
||
const scroll = page.locator('[data-slot="data-grid"] [data-slot="scroll-area-viewport"]')
|
||
await expect(scroll).toHaveCount(1)
|
||
expect(await scroll.evaluate(el => el.scrollWidth > el.clientWidth)).toBe(true)
|
||
await scroll.evaluate(el => { el.scrollLeft = el.scrollWidth })
|
||
await expect.poll(() => scroll.evaluate(el => el.scrollLeft)).toBeGreaterThan(0)
|
||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
|
||
await page.addScriptTag({ content: axe.source })
|
||
const audit = await page.evaluate(async () => (window as unknown as { axe: typeof axe }).axe.run(document.querySelector('[data-slot="data-grid"]')!, { runOnly: { type: "tag", values: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"] } }))
|
||
expect(audit.violations).toEqual([])
|
||
await page.addStyleTag({ content: "nextjs-portal { display: none !important; }" }); mkdirSync("docs/ux-ui/screens", { recursive: true })
|
||
await page.getByText("История тестов", { exact: true }).scrollIntoViewIfNeeded()
|
||
await page.screenshot({ path: "docs/ux-ui/screens/large-speed-history-320.png", animations: "disabled" })
|
||
runs = [runs[199]]; const previous = calls; await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||
await expect.poll(() => calls).toBeGreaterThan(previous)
|
||
await expect(rows).toHaveCount(1); await expect(rows.first()).toHaveAttribute("data-row-id", "200")
|
||
await expect(page.getByRole("button", { name: "Следующая страница", exact: true })).toHaveCount(0)
|
||
expect(writes).toEqual([])
|
||
})
|