Files
MikrotikManager/tests/e2e/terminal-layout.spec.ts

19 lines
2.7 KiB
TypeScript

import {test,expect} from "@playwright/test"
for(const width of [1440,390,320])test("Терминал: адаптивный вывод, поле и быстрые команды "+width,async({page})=>{
const row={id:1,name:"Домашний роутер с длинным названием и описанием устройства",host:"192.0.2.1",country:"RU",enabled:true,status:null,os:null}
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"?[row]:p==="/api/auth/config"?{required:false}:p.endsWith("/exec")?{output:Array.from({length:1200},(_,i)=>"Строка "+i+" "+"x".repeat(160)).join("\n")}:{}})})
await page.setViewportSize({width,height:900});await page.goto("/terminal?server=1")
const input=page.getByRole("textbox",{name:/^Команда ·/}),output=page.getByRole("region",{name:"Вывод терминала"})
await expect(input).toBeEnabled();await expect(output).not.toContainText("Connected")
expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true)
if(width<768){const control=(await page.getByRole("button",{name:"Серверы",exact:true}).boundingBox())!;expect(control.x+control.width).toBeLessThanOrEqual(width)}
await page.screenshot({path:"docs/ux-ui/screens/terminal-ready-"+(width===1440?"desktop":width===390?"mobile":"narrow")+".png"})
await page.getByRole("combobox",{name:"Быстрая команда"}).selectOption("interface print");await input.press("Enter")
await expect(input).toHaveValue("");await expect(output).toContainText("Показаны последние 1000 строк");await expect(output).toContainText("Строка 1199");await expect(output).not.toContainText("Строка 0 ")
expect(await output.evaluate(e=>e.scrollHeight>e.clientHeight)).toBe(true);expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true)
const box=(await input.boundingBox())!;expect(box.width).toBeGreaterThan(100);expect(box.y+box.height).toBeLessThanOrEqual(900)
await page.screenshot({path:"docs/ux-ui/screens/terminal-output-"+(width===1440?"desktop":width===390?"mobile":"narrow")+".png"})
await page.getByRole("button",{name:"Очистить вывод терминала"}).click();await expect(output).toContainText("Вывод очищен.")
if(width<768){await page.getByRole("button",{name:"Серверы",exact:true}).click();const dialog=page.getByRole("dialog");await expect(dialog).toBeVisible();await page.keyboard.press("Escape");await expect(dialog).toHaveCount(0);await expect(page.getByRole("button",{name:"Серверы",exact:true})).toBeFocused()}
})