Files
MikrotikManager/tests/e2e/large-recursive-form.spec.ts

34 lines
4.5 KiB
TypeScript

import { test, expect } from "@playwright/test"
test("Recursive form1000 endpoints/gateways: full draft/payload/error/retry/320px", async ({ page }, info) => {
test.setTimeout(150000)
let routes = Array.from({length:1000},(_,i)=>({id:"r"+(i+1),dstAddress:"203.0.113.0/24",gateway:"192.0.2.1%gw-"+(i+1),distance:1,scope:30,targetScope:10,routingTable:"main",checkGateway:"ping",comment:"Большая группа",disabled:false,country:""}))
const other = {...routes[0],id:"other",dstAddress:"203.0.114.0/24",gateway:"198.51.100.1%other",routingTable:"other"};routes.push(other)
const gateways=Array.from({length:1000},(_,i)=>({id:"g"+(i+1),name:"gw-"+(i+1),ip:"192.0.2.1",status:"unknown"}))
let fail=true,attempts=0,submitted:typeof routes=[]
await page.route("**/health",r=>r.fulfill({json:{ok:true}}))
await page.route("**/api/**",r=>{const p=new URL(r.request().url()).pathname
if(p==="/api/recursive-routes"&&r.request().method()==="PUT"){attempts++;submitted=r.request().postDataJSON().routes;if(fail)return r.fulfill({status:503,json:{error:"Запись недоступна тест"}});routes=submitted;return r.fulfill({json:{ok:true,serverId:1,routes,pushedRoutes:routes.length}})}
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,live:true,stale:false}:p==="/api/recursive-routes/gateways/catalog"?{serverId:1,gateways}:{} })
})
await page.goto("/recursive-routes?server=1")
await page.getByRole("button",{name:"Редактировать маршрут 203.0.113.0/24 · main",exact:true}).click()
const sheet=page.getByRole("dialog"),cards=sheet.locator('[data-recursive-endpoint-form]')
await expect(cards).toHaveCount(10);await expect(sheet.getByRole("button",{name:/^Выбрать шлюз /})).toHaveCount(50)
const profile={endpoints:1000,gateways:1000,cards:await cards.count(),nodes:await sheet.locator("*").count()};console.log("Recursive form profile",JSON.stringify(profile));await info.attach("profile",{body:JSON.stringify(profile),contentType:"application/json"})
await cards.first().getByRole("textbox",{name:"Шлюз",exact:true}).fill("192.0.2.10%edited-first")
const next=sheet.getByRole("button",{name:"Следующие endpoints формы",exact:true});await next.click();await expect(cards.first()).toContainText("Endpoint 11");const jump=sheet.getByRole("spinbutton",{name:"Перейти к endpoint",exact:true});await jump.fill("1000");await jump.press("Enter")
await expect(next).toBeDisabled();await expect(cards.last()).toContainText("Endpoint 1000")
await cards.first().getByRole("textbox",{name:"Поиск шлюза для endpoint 991",exact:true}).fill("gw-1000")
await cards.first().getByRole("button",{name:"Выбрать шлюз 192.0.2.1%gw-1000",exact:true}).click()
await expect(cards.first().getByRole("textbox",{name:"Шлюз",exact:true})).toHaveValue("192.0.2.1%gw-1000")
await cards.last().getByRole("textbox",{name:"Шлюз",exact:true}).fill("")
await sheet.getByRole("button",{name:"Предыдущие endpoints формы",exact:true}).click();await expect(cards.first()).toContainText("Endpoint 981");const save=sheet.getByRole("button",{name:"Сохранить",exact:true});await save.click();await expect(sheet.getByRole("alert")).toContainText("Endpoint 1000");expect(attempts).toBe(0)
await cards.last().getByRole("textbox",{name:"Шлюз",exact:true}).fill("192.0.2.99%edited-last")
await save.click();await expect(sheet.getByRole("alert")).toContainText("Запись недоступна тест");expect(submitted).toHaveLength(1001)
expect(submitted.find(r=>r.gateway==="192.0.2.10%edited-first")).toBeTruthy();expect(submitted.find(r=>r.gateway==="192.0.2.99%edited-last")).toBeTruthy();expect(submitted.find(r=>r.id==="other")).toEqual(other)
await expect(cards.last().getByRole("textbox",{name:"Шлюз",exact:true})).toHaveValue("192.0.2.99%edited-last")
await page.setViewportSize({width:320,height:1000});await cards.first().scrollIntoViewIfNeeded();expect(await sheet.evaluate(el=>el.scrollWidth<=el.clientWidth)).toBe(true)
await page.addStyleTag({content:"nextjs-portal{display:none!important}"});await page.screenshot({path:info.outputPath("recursive-form-320.png"),animations:"disabled"})
fail=false;await save.click();await expect(sheet).toHaveCount(0);expect(attempts).toBe(2);expect(submitted).toHaveLength(1001)
})