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

9 lines
3.0 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 {bgpSession} from "./fixtures/bgp"
test("large BGP bounds DOM, preserves page on refresh and restores linked session",async({page},info)=>{
test.setTimeout(90000);const sessions=Array.from({length:1000},(_,i)=>({...bgpSession(1,i),id:"*"+(i+1),name:"Large peer "+String(i+1).padStart(4,"0"),remoteAs:65000+i,capabilities:["route-refresh"]}));let calls=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(path==="/api/bgp/catalog")calls++;return r.fulfill({json:path==="/api/auth/config"?{required:false}:path==="/api/servers"?[{id:1,name:"BGP node",host:"192.0.2.1",country:"RU",enabled:true,status:"online"}]:path==="/api/bgp/catalog"?{sessions,failures:[]}:{}})})
const start=Date.now();await page.goto("/bgp?server=1");await expect(page.getByText("Large peer 0001",{exact:true})).toBeVisible({timeout:60000});const sample={fixtureRows:1000,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-bgp-metrics",{body:JSON.stringify(sample),contentType:"application/json"});expect(sample.renderedRows).toBe(50);expect(sample.domNodes).toBeLessThan(3500)
await page.getByRole("button",{name:"Следующая страница",exact:true}).click();await expect(page.getByText("Large peer 0051",{exact:true})).toBeVisible();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();await page.getByPlaceholder("IP, AS, описание…").fill("Large peer 1000");await expect(page.locator("tr[data-row-id]")).toHaveCount(1);await expect(page.getByText("Large peer 1000",{exact:true})).toBeVisible();await page.goto("/bgp?server=1&session=1-%2A1000");await expect(page.getByText("Large peer 1000",{exact:true})).toBeVisible();await expect(page.getByText("route-refresh",{exact:true})).toBeVisible();await expect(page.getByText("951–1000 из 1000",{exact:true})).toBeVisible();await page.getByRole("button",{name:"Предыдущая страница",exact:true}).click();await expect(page.getByText("901–950 из 1000",{exact:true})).toBeVisible();const linkedBefore=calls;await page.getByRole("button",{name:"Обновить",exact:true}).click();await expect.poll(()=>calls).toBeGreaterThan(linkedBefore);await expect(page.getByRole("button",{name:"Обновить",exact:true})).toBeEnabled();await expect(page.getByText("901–950 из 1000",{exact:true})).toBeVisible();await page.reload();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)
})