Files
MikrotikManager/tests/e2e/route-optimizer-trust.spec.ts

36 lines
3.3 KiB
TypeScript

import {test,expect} from "@playwright/test"
const hosts=(["home-router","jump-host","exit-node"] as const).map((type,index)=>({id:index+1,name:"Роутер "+(index+1),host:"192.0.2."+(index+1),type,site:"TEST",country:"RU",enabled:true,status:"online",latency:10,model:"CHR",...(index===0?{wanUplinks:[{id:"wan",name:"WAN",isp:"ISP",iface:"ether1",ip:"198.51.100.1",maxDl:100,maxUl:100}]}:{})}))
test("Оптимизатор: live рекомендации не подтверждают фиктивную запись",async({page})=>{
let writes=0
await page.route("**/health",r=>r.fulfill({json:{ok:true}}))
await page.route("**/api/**",r=>{
const p=new URL(r.request().url()).pathname
if(r.request().method()!=="GET"&&!p.endsWith("/preview"))writes++
return r.fulfill({json:p==="/api/auth/config"?{required:false}:p==="/api/servers"?hosts:p==="/api/filters/rules"?{rulesets:[{serverId:"1",rules:[{id:"r",community:"65001:1",communityName:"Сервис",gateway:"192.0.2.2",gatewayTunnelId:"",description:""}]}]}:p==="/api/uptime/speed-probes"?{probes:[]}:p.endsWith("/preview")?{serverId:1,serverName:"Роутер 1",pingWeight:60,unchangedCount:0,interfaces:[],changes:[],changedCount:0,interfacesTotal:0}:p==="/api/ospf/catalog"?{interfaces:[],instances:[],neighbors:[],bfdSessions:[],routes:[],failures:[]}:{}})
})
await page.goto("/route-optimizer")
await page.getByRole("button",{name:"BGP community (1)",exact:true}).click()
const grid=page.getByRole("table").filter({hasText:"Community"})
await expect(grid.locator("tr[data-row-id]")).toHaveCount(1)
await expect(grid.getByRole("columnheader",{name:"Базовый расчёт (WAN → JH → Exit)",exact:true})).toBeVisible()
await expect(grid.getByRole("button",{name:"Применить",exact:true})).toHaveCount(0)
await expect(grid.getByRole("button",{name:"Симулировать",exact:true})).toHaveCount(0)
await expect(page.getByRole("button",{name:/Симулировать все/})).toHaveCount(0)
await expect(page.getByText("✓ применено",{exact:true})).toHaveCount(0)
await expect(page.getByText(/Применение Community к устройству недоступно/)).toBeVisible()
await page.getByRole("button",{name:/Настройки оптимизатора/}).click()
await expect(page.getByText("Автоприменение Community недоступно",{exact:true})).toBeVisible()
await expect(page.getByText("Применять автоматически",{exact:true})).toHaveCount(0)
expect(writes).toBe(0)
})
test("Оптимизатор: демо подтверждает только симуляцию",async({page})=>{
await page.addInitScript(()=>localStorage.setItem("routerlists:data-source","mock"))
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/auth/config"?{required:false}:{}}))
await page.goto("/route-optimizer")
await page.getByRole("button",{name:/^BGP community/}).last().click()
const simulate=page.getByRole("button",{name:"Симулировать",exact:true}).first()
await expect(simulate).toBeVisible();await simulate.click()
await expect(page.getByText("✓ симуляция завершена",{exact:true}).first()).toBeVisible()
await expect(page.getByText("✓ применено",{exact:true})).toHaveCount(0)
})