import {test,expect} from "@playwright/test" import {mkdirSync} from "node:fs" for(const [device,width,height] of [["desktop",1440,1000],["mobile",390,844],["narrow",320,700]] as const)test("Оптимизатор: layout/keyboard "+device,async({page})=>{ await page.setViewportSize({width,height});await page.emulateMedia({reducedMotion:"reduce"}) const item={id:"i",interface:"ether1",currentCost:10,optimalCost:20,score:50,pingMs:0,dlMbps:0,ulMbps:0} await page.route("**/health",r=>r.fulfill({json:{ok:true}})) await page.route("**/api/**",r=>{const p=new URL(r.request().url()).pathname;return r.fulfill({json:p==="/api/auth/config"?{required:false}:p==="/api/servers"?["home-router","jump-host","exit-node"].map((type,index)=>({id:index+1,name:"Роутер "+(index+1),host:"192.0.2."+(index+1),country:"RU",type,enabled:true,status:null,latency:null,...(index===0?{wanUplinks:[{id:"w",name:"WAN1",iface:"ether1",ip:"198.51.100.1",isp:"ISP",maxDl:100,maxUl:100}]}:{})})):p==="/api/filters/rules"?{rulesets:[{serverId:"1",rules:[{id:"r",community:"65001:1",communityName:"Сервис",gateway:"192.0.2.2",gatewayTunnelId:"",description:""}]}]}:p==="/api/uptime/speed-probes"?{probes:[]}:p==="/api/ospf/catalog"?{interfaces:[],instances:[],neighbors:[],bfdSessions:[],routes:[],failures:[]}:p.endsWith("/preview")?{serverId:1,serverName:"Роутер 1",pingWeight:60,interfacesTotal:1,changedCount:1,unchangedCount:0,interfaces:[item],changes:[item]}:{}})}) await page.goto("/route-optimizer") await expect(page.getByRole("table").filter({hasText:"Speed (dl/ul)"}).locator("tr[data-row-id]")).toHaveCount(1) expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true) await expect(page.getByLabel("Сводка оптимизатора").getByText("Home",{exact:true})).toBeVisible(); await page.addStyleTag({content:"nextjs-portal {display:none!important}"});mkdirSync("docs/ux-ui/screens",{recursive:true}) await page.screenshot({path:"docs/ux-ui/screens/route-optimizer-overview-"+device+".png",animations:"disabled"}) const settings=page.getByRole("button",{name:"Настройки оптимизатора",exact:true}) await settings.focus();await page.keyboard.press("Enter");await expect(settings).toHaveAttribute("aria-expanded","true") await expect(page.getByRole("spinbutton",{name:"Вес задержки",exact:true})).toBeVisible() expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true) await page.getByRole("spinbutton",{name:"Вес задержки",exact:true}).scrollIntoViewIfNeeded(); await page.screenshot({path:"docs/ux-ui/screens/route-optimizer-settings-"+device+".png",animations:"disabled"}) await settings.focus();await page.keyboard.press(" ");await expect(settings).toHaveAttribute("aria-expanded","false") const slider=page.getByRole("slider",{name:"Максимальное число путей ECMP",exact:true});await expect(slider).toBeDisabled() const toggle=page.getByRole("switch",{name:"Черновик ECMP",exact:true});await toggle.focus();await page.keyboard.press(" ");await expect(toggle).toHaveAttribute("aria-checked","true");await expect(slider).toBeEnabled() const community=page.getByRole("button",{name:"BGP community (1)",exact:true});await community.focus();await page.keyboard.press("Enter");await expect(community).toHaveAttribute("aria-pressed","true") const grid=page.getByRole("table").filter({hasText:"Community"});await expect(grid.locator("tr[data-row-id]")).toHaveCount(1) expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true) await grid.scrollIntoViewIfNeeded(); await page.screenshot({path:"docs/ux-ui/screens/route-optimizer-community-"+device+".png",animations:"disabled"}) })