Files

31 lines
6.0 KiB
TypeScript

import {test,expect} from "@playwright/test"
for(const [name,width] of [["desktop",1440],["mobile",390],["narrow",320]] as const)test("Диагностика: адаптивность и длинный вывод "+name,async({page})=>{
await page.setViewportSize({width,height:900});const device={id:1,name:"Очень длинное имя устройства диагностики для проверки мобильной кнопки",host:"192.0.2.1",country:"RU",enabled:true,status:null,type:"exit-node"}
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/servers"?[device]:p==="/api/auth/config"?{required:false}:p.endsWith("/ros-src-address")?{host:"192.0.2.1",ipv4:"192.0.2.1"}:{tunnels:[]}})})
const output=Array.from({length:1200},(_,i)=>"строка-"+i+" "+"x".repeat(160)).join("\n")
await page.route("**/api/servers/1/probes/run",r=>r.fulfill({json:{output}}));await page.goto("/probes?server=1");await expect(page.getByRole("button",{name:"Запустить",exact:true})).toBeEnabled();await expect(page.getByRole("status").filter({hasText:"IPv4 для preview:"})).toBeVisible()
await page.getByRole("button",{name:"DNS",exact:true}).click();await expect(page.getByRole("button",{name:"DNS",exact:true})).toHaveAttribute("aria-pressed","true");await page.getByRole("button",{name:"CNAME",exact:true}).click();await expect(page.getByRole("button",{name:"CNAME",exact:true})).toHaveAttribute("aria-pressed","true");await page.getByRole("button",{name:"Ping",exact:true}).click()
expect(await page.evaluate(()=>document.documentElement.scrollWidth<=window.innerWidth)).toBe(true)
if(width<768){const button=page.getByRole("button",{name:"Серверы",exact:true});const box=await button.boundingBox();expect(box&&box.x+box.width<=width).toBe(true);await button.click();await page.keyboard.press("Escape");await expect(button).toBeFocused()}
await page.screenshot({path:"docs/ux-ui/screens/probes-ready-"+name+".png",fullPage:true})
await page.getByRole("button",{name:"Запустить",exact:true}).click();const region=page.getByRole("region",{name:/^Вывод Ping/});await expect(region).toContainText("строка-1199");await expect(region).toContainText("Показаны последние 1000 строк");await expect(region).not.toContainText("строка-199 ");await region.scrollIntoViewIfNeeded();await region.focus()
expect(await region.evaluate(el=>el.clientHeight>100&&el.scrollHeight>el.clientHeight&&el.scrollWidth<=el.clientWidth+1)).toBe(true);expect(await page.evaluate(()=>document.documentElement.scrollWidth<=window.innerWidth)).toBe(true)
await page.screenshot({path:"docs/ux-ui/screens/probes-output-"+name+".png",fullPage:true})
await page.getByRole("button",{name:/^Удалить результат/}).click();await expect(region).toHaveCount(0);await expect(page.getByRole("button",{name:"Запустить",exact:true})).toBeFocused()
})
test("Диагностика: недоступный clipboard сохраняет вывод и сообщает ошибку",async({page})=>{
await page.route("**/health",r=>r.fulfill({json:{ok:true}}));await page.route("**/api/**",r=>r.fulfill({json:new URL(r.request().url()).pathname==="/api/servers"?[{id:1,name:"Тест",host:"192.0.2.1",enabled:true,status:null,type:"exit-node"}]:new URL(r.request().url()).pathname==="/api/auth/config"?{required:false}:{tunnels:[]}}))
await page.addInitScript(()=>Object.defineProperty(navigator,"clipboard",{value:{writeText:()=>Promise.reject(new Error("permission denied"))},configurable:true}))
await page.goto("/probes?server=1");await page.getByRole("button",{name:"Скопировать параметры диагностики"}).click();await expect(page.getByText(/Не удалось скопировать/)).toBeVisible();await expect(page.getByRole("textbox",{name:"Цель диагностики"})).toHaveValue("8.8.8.8")
})
test("Диагностика: клавиатура, подтверждённый clipboard и место DNS",async({page})=>{
await page.route("**/health",r=>r.fulfill({json:{ok:true}}));await page.route("**/api/**",r=>r.fulfill({json:new URL(r.request().url()).pathname==="/api/servers"?[{id:1,name:"Устройство",host:"192.0.2.1",enabled:true,status:null,type:"exit-node"}]:new URL(r.request().url()).pathname==="/api/auth/config"?{required:false}:{tunnels:[]}}))
await page.addInitScript(()=>Object.defineProperty(navigator,"clipboard",{value:{writeText:async(text:string)=>{sessionStorage.setItem("test-clipboard",text)}},configurable:true}))
await page.route("**/api/servers/1/probes/run",r=>r.fulfill({json:{output:"example.test. IN CNAME target.test."}}))
await page.goto("/probes?server=1");const dns=page.getByRole("button",{name:"DNS",exact:true});await dns.focus();await page.keyboard.press("Enter");const cname=page.getByRole("button",{name:"CNAME",exact:true});await cname.focus();await page.keyboard.press("Space");await expect(cname).toHaveAttribute("aria-pressed","true")
const target=page.getByRole("textbox",{name:"Домен"});await target.fill("example.test");await target.press("Enter");const region=page.getByRole("region",{name:/^Вывод DNS/});await expect(region).toContainText("example.test. IN CNAME target.test.");await expect(target).toBeFocused();await expect(page.getByText("DNS приложения",{exact:true})).toBeVisible()
const copy=page.getByRole("button",{name:/^Скопировать показанный вывод/});await copy.focus();await page.keyboard.press("Enter");await expect(page.getByText("Скопировано.",{exact:true})).toBeVisible();expect(await page.evaluate(()=>sessionStorage.getItem("test-clipboard"))).toBe("example.test. IN CNAME target.test.")
const remove=page.getByRole("button",{name:/^Удалить результат/});await remove.focus();await page.keyboard.press("Enter");await expect(region).toHaveCount(0);await expect(page.getByRole("button",{name:"Запустить",exact:true})).toBeFocused()
})