Files
MikrotikManager/tests/e2e/large-statistics.spec.ts
T

10 lines
2.6 KiB
TypeScript
Raw 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 {statisticsDtoSchema} from "../../packages/contracts/src/statistics"
test("large statistics pagination bounds DOM and sorts the whole catalog",async({page},info)=>{
test.setTimeout(90000)
const users=Array.from({length:1000},(_,i)=>({id:String(i+1),label:"Large user "+String(i+1).padStart(4,"0"),bytes:1000,packets:10,bps:100,percent:0.1}))
await page.route("**/health",r=>r.fulfill({json:{ok:true}}));await page.route("**/api/**",r=>{const url=new URL(r.request().url());return r.fulfill({json:url.pathname==="/api/statistics"?statisticsDtoSchema.parse({from:url.searchParams.get("from"),to:url.searchParams.get("to"),grain:"day",kpis:{bytes:1000000,packets:10000,avgBps:100000,users:1000,servers:0,ifaces:0,topCountry:"",topService:""},series:[],servers:[],interfaces:[],countries:[],services:[],asns:[],users}):url.pathname==="/api/auth/config"?{required:false}:url.pathname==="/api/servers"?[]:{}})})
const start=Date.now();await page.goto("/statistics?from=2026-09-01&to=2026-09-03&dim=users");await expect(page.getByText("Large user 0001",{exact:true})).toBeVisible({timeout:60000});const sample={fixtureRows:1000,fixtureBytes:Buffer.byteLength(JSON.stringify(users)),readyMs:Date.now()-start,renderedRows:await page.locator("tr[data-row-id]").count(),domNodes:await page.locator("*").count()};console.log(JSON.stringify(sample));await info.attach("large-statistics-metrics",{body:JSON.stringify(sample),contentType:"application/json"});expect(sample.renderedRows).toBe(50);expect(sample.domNodes).toBeLessThan(2500)
await expect(page.getByText("1–50 из 1000",{exact:true})).toBeVisible();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("Large user 1000",{exact:true})).toBeVisible();await expect(page.getByText("951–1000 из 1000",{exact:true})).toBeVisible();for(let i=0;i<3;i++)await page.getByRole("button",{name:"…",exact:true}).first().click();await page.getByRole("button",{name:"Перейти на страницу 1",exact:true}).click();await page.getByRole("button",{name:"Имя",exact:true}).click();await page.getByRole("button",{name:"Имя",exact:true}).click();await expect(page.locator("tr[data-row-id]").first()).toContainText("Large user 1000");await page.setViewportSize({width:320,height:900});expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true);await expect(page.getByRole("button",{name:"Следующая страница",exact:true})).toBeVisible()
})