fix(ui): проверять целостность снимка карты сети

This commit is contained in:
Denozordec committed 2026-10-01 01:33:50 +07:00
1 parent 66fde3fc62
commit 1215cbe8ae
6 files changed
+121 -85

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import {test,expect} from "@playwright/test"
const paths={servers:"/api/servers",gre:"/api/filters/gre-tunnels",probes:"/api/uptime/speed-probes"} as const
const body=(path:string,name="Роутер")=>path===paths.servers?[{id:1,name,host:"192.0.2.1",type:"home-router",country:"RU",enabled:true,status:"online",latency:0}]:path===paths.gre?{tunnels:[],failures:[]}:path===paths.probes?{probes:[]}:path==="/api/auth/config"?{required:false}:{}
for(const part of ["servers","gre","probes"] as const)for(const malformed of [false,true])test("Карта: первоначальный отказ и повтор "+part+"/"+malformed,async({page})=>{
let failing=true
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(failing&&p===paths[part]?(malformed?{json:{}}:{status:403,json:{error:"Нет доступа к данным"}}):{json:body(p)})})
await page.goto("/network-map")
await expect(page.getByRole("alert").filter({hasText:"Первоначальная загрузка"})).toBeVisible()
await expect(page.getByText("Данные карты неизвестны",{exact:true})).toBeVisible()
failing=false;await page.getByRole("button",{name:"Обновить",exact:true}).click()
await expect(page.getByText("Роутер",{exact:true}).first()).toBeVisible()
await expect(page.getByRole("alert").filter({hasText:"Первоначальная загрузка"})).toHaveCount(0)
})
for(const part of ["servers","gre","probes"] as const)test("Карта: частичный отказ сохраняет снимок "+part,async({page})=>{
let failing=false
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(failing&&p===paths[part]?{status:503,json:{error:"Источник недоступен"}}:{json:body(p,failing?"Новый роутер":"Последний роутер")})})
await page.goto("/network-map")
await expect(page.getByText("Последний роутер",{exact:true}).first()).toBeVisible()
failing=true;await page.getByRole("button",{name:"Обновить",exact:true}).click()
await expect(page.getByRole("alert").filter({hasText:"Последний полный снимок"})).toBeVisible()
await expect(page.getByText("Последний роутер",{exact:true}).first()).toBeVisible()
await expect(page.getByText("Новый роутер",{exact:true})).toHaveCount(0)
})