fix(ui): учитывать весь каталог Community в оптимизаторе
This commit is contained in:
1 parent
53603f17c1
commit
991f2b3871
9 files changed
+100
-12
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import axe from "axe-core"
|
||||
import { writeFileSync } from "node:fs"
|
||||
import { optimizerServersSchema,optimizerRulesSchema } from "../../lib/route-optimizer-response"
|
||||
|
||||
test("Оптимизатор1000 Community: полный источник",async({page},info)=>{
|
||||
test.setTimeout(90000)
|
||||
const rules=optimizerRulesSchema.parse({rulesets:[{serverId:"1",rules:Array.from({length:1000},(_,i)=>({id:String(i+1),community:`65001:${String(i+1).padStart(4,"0")}`,communityName:`Сервис ${i+1}`,gateway:"192.0.2.2",gatewayTunnelId:"",description:""}))}]})
|
||||
let rules=optimizerRulesSchema.parse({rulesets:[{serverId:"1",rules:Array.from({length:1000},(_,i)=>({id:String(i+1),community:`65001:${String(i+1).padStart(4,"0")}`,communityName:`Сервис ${i+1}`,gateway:"192.0.2.2",gatewayTunnelId:"",description:""}))}]})
|
||||
const common = { host: "192.0.2.1", enabled: true, status: "online", latency: 10, country: "RU", site: "TEST", model: "CHR" }
|
||||
const servers = optimizerServersSchema.parse([
|
||||
{ ...common, id: 1, name: "Домашний роутер", type: "home-router", wanUplinks: Array.from({ length: 1 }, (_, i) => ({ id: `wan${i+1}`, name: `WAN${i+1}`, isp: "ISP", iface: `ether${i+1}`, ip: `198.51.100.${i+1}`, maxDl: 100, maxUl: 100 })) },
|
||||
@@ -12,10 +13,12 @@ test("Оптимизатор1000 Community: полный источник",async
|
||||
])
|
||||
|
||||
|
||||
let reads=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(path==="/api/filters/rules")reads++
|
||||
|
||||
|
||||
if (r.request().method() !== "GET" && !path.endsWith("/preview")) writes.push(path)
|
||||
@@ -24,10 +27,33 @@ test("Оптимизатор1000 Community: полный источник",async
|
||||
|
||||
|
||||
const start=Date.now();await page.goto("/route-optimizer?server=1&keep=1")
|
||||
await page.getByRole("button",{name:"BGP community (24)",exact:true}).click()
|
||||
await page.getByRole("button",{name:"BGP community (1000)",exact:true}).click()
|
||||
const table=page.getByRole("table").filter({hasText:"Community"})
|
||||
await expect(table.locator("tr[data-row-id]")).toHaveCount(24)
|
||||
await expect(table.locator("tr[data-row-id]")).toHaveCount(50)
|
||||
const profile={sourceCount:1000,rendered:await table.locator("tr[data-row-id]").count(),tableNodes:await table.locator("*").count(),pageNodes:await page.locator("*").count(),readyMs:Date.now()-start}
|
||||
console.log("Optimizer Community",JSON.stringify(profile));writeFileSync(info.outputPath("community-profile.json"),JSON.stringify(profile,null,2))
|
||||
const root=page.getByRole("region",{name:"Рекомендации BGP Community"})
|
||||
const rows=table.locator("tr[data-row-id]"),search=root.getByRole("textbox",{name:"Поиск Community",exact:true})
|
||||
const next=root.getByRole("button",{name:"Следующая страница",exact:true})
|
||||
await next.click();await expect(rows.first()).toContainText("65001:0051")
|
||||
const before=reads;await page.getByRole("button",{name:"Обновить",exact:true}).click();await expect.poll(()=>reads).toBeGreaterThan(before);await expect(rows.first()).toContainText("65001:0051")
|
||||
await search.fill("Сервис 1000");await expect(rows).toHaveCount(1);await expect(rows.first()).toContainText("65001:1000")
|
||||
await rows.first().getByRole("button",{name:"Закрепить",exact:true}).click();await expect(rows.first().getByRole("button",{name:"Открепить",exact:true})).toBeVisible()
|
||||
await expect(rows.first().getByRole("cell").nth(3).getByLabel("Индекс неизвестен")).toHaveCount(2)
|
||||
await expect(root.getByRole("button",{name:"Симулировать",exact:true})).toHaveCount(0)
|
||||
await search.fill("no-such-community");await expect(rows).toHaveCount(0);await expect(root).toContainText("Community: 0 из 1000")
|
||||
await search.fill("");for(let i=0;i<19;i++)await next.click()
|
||||
await expect(next).toBeDisabled();await expect(rows.last()).toContainText("65001:1000");await expect(rows.last().getByRole("button",{name:"Открепить",exact:true})).toBeVisible()
|
||||
await search.fill("65001:");await table.getByRole("button",{name:"Community",exact:true}).click();await table.getByRole("button",{name:"Community",exact:true}).click()
|
||||
await expect(rows.first()).toContainText("65001:1000");await expect(rows.first().getByRole("button",{name:"Открепить",exact:true})).toBeVisible()
|
||||
await page.setViewportSize({width:320,height:1000});const scroll=root.locator('[data-slot="scroll-area-viewport"]')
|
||||
await scroll.evaluate(el=>{el.scrollLeft=el.scrollWidth})
|
||||
expect(await rows.first().getByRole("cell").first().evaluate(el=>{const a=el.getBoundingClientRect(),v=el.closest('[data-slot="scroll-area-viewport"]')!.getBoundingClientRect();return a.left>=v.left-1&&a.right<=v.right+1})).toBe(true)
|
||||
expect(await page.evaluate(()=>document.documentElement.scrollWidth)).toBeLessThanOrEqual(320)
|
||||
await scroll.evaluate(el=>{el.scrollLeft=0});await root.evaluate(el=>el.scrollIntoView({block:"start"}));await page.addStyleTag({content:"nextjs-portal{display:none!important}"})
|
||||
await page.screenshot({path:info.outputPath("optimizer-community-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="Рекомендации BGP Community"]')!,{runOnly:{type:"tag",values:["wcag2a","wcag2aa","wcag21a","wcag21aa"]}}))).violations.map(v=>({id:v.id,nodes:v.nodes.map(n=>n.target)}))).toEqual([])
|
||||
await next.click();rules={rulesets:[{serverId:"1",rules:rules.rulesets[0].rules.slice(0,1)}]};await page.getByRole("button",{name:"Обновить",exact:true}).click()
|
||||
await expect(page.getByRole("button",{name:"BGP community (1)",exact:true})).toBeVisible();await expect(rows).toHaveCount(1);await expect(rows.first()).toContainText("65001:0001")
|
||||
expect(writes).toEqual([])
|
||||
})
|
||||
Reference in new issue
Block a user