import {test,expect} from "@playwright/test" import {alertsWithRule,emptyOutbox} from "./fixtures/alerts" for(const width of [320,1440])test("Alerts rules priority, accessible filters and no overflow/"+width,async({page})=>{ await page.setViewportSize({width,height:900}) await page.route("**/health",r=>r.fulfill({json:{status:"ok"}})) await page.route("**/api/**",r=>{const path=new URL(r.request().url()).pathname;return r.fulfill({json:path==="/api/auth/config"?{required:false}:path==="/api/alerts"?alertsWithRule:path==="/api/alerts/outbox"?emptyOutbox:path==="/api/filters/gre-tunnels"?{tunnels:[],failures:[]}:[]})}) await page.goto("/alerts") const search=page.getByRole("textbox",{name:"Поиск правил",exact:true}) await expect(search).toBeVisible() const critical=page.getByRole("button",{name:"Критических: 1",exact:true}) await critical.focus();await page.keyboard.press("Space");await expect(critical).toHaveAttribute("aria-pressed","true") await search.fill("missing fixture");await expect(page.getByText("Правила не найдены",{exact:true})).toBeVisible() await search.fill("Fixture rule");await expect(page.getByRole("button",{name:"Изменить правило Fixture rule"})).toBeVisible() const name=page.getByText("Fixture rule",{exact:true});await expect(name).toBeVisible();expect((await name.boundingBox())!.width).toBeGreaterThan(100) const position=await search.boundingBox();const catalogs=await page.getByText("Каталоги целей",{exact:true}).boundingBox();const queue=await page.getByRole("region",{name:"Очередь Telegram"}).boundingBox() expect(position!.y).toBeLessThan(catalogs!.y);expect(position!.y).toBeLessThan(queue!.y) if(width===320){const telegram=await page.getByRole("region",{name:"Параметры Telegram"}).boundingBox();expect(queue!.y).toBeLessThan(telegram!.y)}else expect(queue!.y).toBeLessThan(900) await search.scrollIntoViewIfNeeded();await expect(search).toBeInViewport() expect(await page.evaluate(()=>document.documentElement.scrollWidth<=window.innerWidth)).toBe(true) await page.screenshot({path:"docs/ux-ui/screens/alerts-overview-"+width+".png",fullPage:true}) }) test("Alerts queue remains mounted when delayed primary snapshot becomes known",async({page})=>{ let started=false,calls=0,release!:()=>void;const gate=new Promise(resolve=>release=resolve) await page.route("**/health",r=>r.fulfill({json:{status:"ok"}}));await page.route("**/api/**",async r=>{const path=new URL(r.request().url()).pathname;if(path==="/api/alerts"){started=true;await gate;return r.fulfill({json:alertsWithRule})}if(path==="/api/alerts/outbox")calls++;return r.fulfill({json:path==="/api/auth/config"?{required:false}:path==="/api/alerts/outbox"?emptyOutbox:path==="/api/filters/gre-tunnels"?{tunnels:[],failures:[]}:[]})}) try{await page.goto("/alerts");await expect.poll(()=>started).toBe(true);await expect(page.getByRole("region",{name:"Очередь Telegram"})).toBeVisible();await expect.poll(()=>calls).toBe(1);release();await expect(page.getByRole("textbox",{name:"Поиск правил",exact:true})).toBeVisible();expect(calls).toBe(1)}finally{release()} })