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 errors:string[]=[];page.on("pageerror",error=>errors.push(error.message)) const item={id:"r",dstAddress:"10.0.0.0/24",gateway:"192.0.2.1%bridge1",distance:0,scope:0,targetScope:null,routingTable:"main",checkGateway:"none",comment:"Резервный маршрут",disabled:true,country:""} 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"?[{id:1,name:"Роутер с длинным названием",host:"192.0.2.1",country:"RU",enabled:true,status:null}]:p==="/api/recursive-routes/catalog"?{serverId:1,routes:[item],live:true,stale:false}:p==="/api/recursive-routes/gateways/catalog"?{serverId:1,gateways:[{id:"g",ip:"192.0.2.1",name:"bridge1",status:"unknown"}]}:{}})}) await page.goto("/recursive-routes?server=1") const open=page.getByRole("button",{name:"Раскрыть маршрут 10.0.0.0/24 · main",exact:true}) await expect(open).toBeVisible();await expect(page.getByText("EN",{exact:true})).toHaveCount(0) expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true) await open.focus();await page.keyboard.press("Enter");await expect(open).toHaveAttribute("aria-expanded","true") await expect(page.getByText("scope: 0",{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/recursive-routes-detail-"+device+".png",animations:"disabled"}) await open.focus();await page.keyboard.press(" ");await expect(open).toHaveAttribute("aria-expanded","false") const edit=page.getByRole("button",{name:"Редактировать маршрут 10.0.0.0/24 · main",exact:true}) await edit.focus();await page.keyboard.press("Enter") const sheet=page.getByRole("dialog");await expect(sheet).toBeVisible() await expect(sheet.getByRole("textbox",{name:"Адрес назначения",exact:true})).toHaveValue("10.0.0.0/24") await expect(sheet.getByRole("textbox",{name:"Шлюз",exact:true})).toHaveValue("192.0.2.1%bridge1") await expect(sheet.getByRole("spinbutton",{name:"Distance (приоритет)",exact:true})).toHaveValue("0") await sheet.getByRole("textbox",{name:"Комментарий",exact:true}).scrollIntoViewIfNeeded() expect(await sheet.evaluate(el=>el.scrollWidth<=el.clientWidth)).toBe(true) const save=sheet.getByRole("button",{name:"Сохранить",exact:true});await expect(save).toBeInViewport() await save.focus();await page.keyboard.press("Tab") expect(await sheet.evaluate(el=>el.contains(document.activeElement))).toBe(true) await page.screenshot({path:"docs/ux-ui/screens/recursive-routes-form-"+device+".png",animations:"disabled"}) await page.keyboard.press("Escape");await expect(sheet).toHaveCount(0);await expect(edit).toBeFocused() expect(errors).toEqual([]) })