fix(ui): ограничить строки ресурсов мониторинга

This commit is contained in:
Denozordec committed 2026-10-04 02:54:33 +07:00
1 parent 76a5e81fd4
commit 2762f073a0
7 files changed
+93 -13

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
import { test, expect } from "@playwright/test"
test("1000 ресурсов: страницы, поиск, обновление и уменьшение списка", async ({ page }, info) => {
test.setTimeout(90000)
const servers = Array.from({ length: 1000 }, (_, i) => ({ id: i + 1, name: "Ресурс " + String(i + 1).padStart(4, "0"), host: "192.0.2." + (i % 250 + 1), type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "64512", status: "online", latency: 1, os: "7", model: "CHR", sessions: 0, wanUplinks: [] }))
let resources = servers.map(s => ({ serverId: String(s.id), hasData: true, cpu: 10, cpuHistory: [10], ramUsed: 100, ramTotal: 1000, hddUsed: 10, hddTotal: 100, uptimeSeconds: 60, boardName: "CHR" }))
let calls = 0
const writes: string[] = []
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", route => {
const path = new URL(route.request().url()).pathname
if (!["GET", "HEAD"].includes(route.request().method())) writes.push(path)
if (path === "/api/uptime/overview") calls++
return route.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=resources&probe=p1&keep=1")
const rows = page.locator("tr[data-row-id]")
await expect(rows).toHaveCount(50)
const sample = { fixtureRows: 1000, renderedRows: await rows.count(), domNodes: await page.locator("*").count(), readyMs: Date.now() - start }
console.log(JSON.stringify(sample))
await info.attach("large-uptime-resources-metrics", { body: JSON.stringify(sample), contentType: "application/json" })
expect(sample.domNodes).toBeLessThan(4000)
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 из 1000", { exact: true })).toBeVisible()
const search = page.getByPlaceholder("Поиск по имени, площадке…")
await search.fill("Ресурс 1000")
await expect(rows).toHaveCount(1)
await expect(rows.first()).toHaveAttribute("data-row-id", "1000")
await expect(page).toHaveURL(url => url.searchParams.get("rq") === "Ресурс 1000" && url.searchParams.get("probe") === "p1" && url.searchParams.get("keep") === "1")
await page.reload()
await expect(search).toHaveValue("Ресурс 1000")
await expect(rows).toHaveCount(1)
await search.fill("")
await expect(rows).toHaveCount(50)
await page.getByRole("button", { name: "Сервер", exact: true }).click()
await page.getByRole("button", { name: "Сервер", exact: true }).click()
await expect(rows.first()).toHaveAttribute("data-row-id", "1000")
for (let i = 0; i < 3; i++) await page.getByRole("button", { name: "…", exact: true }).last().click()
await page.getByRole("button", { name: "Перейти на страницу 20", exact: true }).click()
await expect(page.getByText("951–1000 из 1000", { exact: true })).toBeVisible()
await page.setViewportSize({ width: 320, height: 900 })
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true)
resources = resources.slice(0, 1)
await page.getByRole("button", { name: "Обновить данные", exact: true }).click()
await expect(rows).toHaveCount(1)
await expect(rows.first()).toHaveAttribute("data-row-id", "1")
expect(writes).toEqual([])
})