fix(ui): сделать сводки площадок краткими и достоверными
This commit is contained in:
1 parent
52d8a05480
commit
53e36f2a03
9 files changed
+86
-4
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import {test,expect} from "@playwright/test"
|
||||
import axe from "axe-core"
|
||||
import {optimizerServersSchema} from "../../lib/route-optimizer-response"
|
||||
|
||||
for(const type of ["jump-host","exit-node"] as const)test(`Сводка оптимизатора1000: площадки ${type}`,async({page},info)=>{
|
||||
test.setTimeout(90000)
|
||||
const kind=type==="jump-host"?"JumpHost":"Exit Node",other=type==="jump-host"?"Exit Node":"JumpHost"
|
||||
const common={host:"192.0.2.1",enabled:true,status:"online",latency:10,country:"RU",model:"CHR"}
|
||||
let servers=optimizerServersSchema.parse([{...common,id:1,name:"Home",site:"MSK",type:"home-router",wanUplinks:[]},...Array.from({length:1000},(_,i)=>({...common,id:i+2,name:`Node ${i+1}`,site:i<600?"MSK":i<999?"NSK":" ",type}))])
|
||||
let failed=true,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/servers"){reads++;if(failed)return r.fulfill({status:503,json:{error:"Площадки не загружены"}})}
|
||||
if(r.request().method()!=="GET"&&!path.endsWith("/preview"))writes.push(path)
|
||||
return r.fulfill({json:path==="/api/auth/config"?{required:false}:path==="/api/servers"?servers:path==="/api/filters/rules"?{rulesets:[]}:path==="/api/uptime/speed-probes"?{probes:[]}:path==="/api/ospf/catalog"?{interfaces:[],instances:[],neighbors:[],bfdSessions:[],routes:[],failures:[]}:path.endsWith("/ospf/optimize/preview")?{serverId:1,serverName:"Home",pingWeight:60,interfacesTotal:0,changedCount:0,unchangedCount:0,interfaces:[],changes:[]}: {}})
|
||||
})
|
||||
await page.goto("/route-optimizer?server=1")
|
||||
const root=page.locator('[aria-label="Сводка оптимизатора"]')
|
||||
const summary=()=>root.getByRole("group",{name:`Площадки ${kind}`,exact:true})
|
||||
await expect(summary()).toHaveText("Площадки неизвестны")
|
||||
failed=false;await page.getByRole("button",{name:"Обновить",exact:true}).click()
|
||||
await expect(summary()).toContainText("MSK · NSK");await expect(summary()).toContainText("Без площадки: 1")
|
||||
await expect(root.getByText("1000",{exact:true})).toBeVisible();await expect(root.getByRole("group",{name:`Площадки ${other}`,exact:true})).toHaveText("Нет узлов в расчёте")
|
||||
const refresh=async()=>{const before=reads;await page.getByRole("button",{name:"Обновить",exact:true}).click();await expect.poll(()=>reads).toBeGreaterThan(before)}
|
||||
servers=servers.map(row=>row.id===1?row:{...row,site:`SITE-${row.id}`});await refresh();await expect(summary()).toHaveText("Площадки: 1000")
|
||||
servers=servers.map(row=>row.id===1?row:{...row,site:"W".repeat(80)});await refresh();await expect(summary()).toHaveText("Площадки: 1")
|
||||
servers=servers.map(row=>row.id===1?row:{...row,site:""});await refresh();await expect(summary()).toHaveText("Без площадки: 1000")
|
||||
failed=true;await refresh();await expect(page.getByRole("alert").filter({hasText:"Последний полный снимок"})).toBeVisible();await expect(summary()).toHaveText("Без площадки: 1000")
|
||||
await page.setViewportSize({width:320,height:1000});expect(await page.evaluate(()=>document.documentElement.scrollWidth)).toBeLessThanOrEqual(320)
|
||||
const box=await summary().boundingBox();expect(box!.x).toBeGreaterThanOrEqual(0);expect(box!.x+box!.width).toBeLessThanOrEqual(320);expect(box!.height).toBeLessThan(80)
|
||||
await page.addStyleTag({content:"nextjs-portal{display:none!important}"});await root.screenshot({path:info.outputPath(`sites-${type}-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="Сводка оптимизатора"]')!,{runOnly:{type:"tag",values:["wcag2a","wcag2aa","wcag21a","wcag21aa"]}}))).violations.map(v=>({id:v.id,nodes:v.nodes.map(n=>n.target)}))).toEqual([])
|
||||
failed=false;servers=servers.map(row=>row.id===1?row:{...row,status:"offline" as const});await refresh();await expect(summary()).toHaveText("Нет узлов в расчёте")
|
||||
servers=servers.map(row=>row.id===1?row:{...row,status:"online" as const,enabled:false});await refresh();await expect(summary()).toHaveText("Нет узлов в расчёте")
|
||||
servers=servers.slice(0,1);await refresh();await expect(summary()).toHaveText("Нет узлов в расчёте")
|
||||
expect(writes).toEqual([])
|
||||
})
|
||||
Reference in new issue
Block a user