24 lines
3.3 KiB
TypeScript
24 lines
3.3 KiB
TypeScript
import { test, expect } from "@playwright/test"
|
|
import { server } from "./fixtures/users"
|
|
const headers = { "access-control-allow-origin":"*", "access-control-allow-methods":"GET,PUT,POST,OPTIONS", "access-control-allow-headers":"Content-Type,Authorization" }
|
|
const probe = { id:"probe-1", srcServerId:"1", dstServerId:"2", srcInterface:"ether1", dstInterface:"ether1", protocol:"tcp", direction:"both", durationSec:"10", enabled:true,lastRunAt:null,lastTxAvgMbps:null,lastRxAvgMbps:0,lastStatus:null,lastError:null }
|
|
const run = {id:"run-1",srcServerId:"1",dstServerId:"2",srcInterface:"ether1",dstInterface:"ether1",protocol:"tcp",direction:"both",durationSec:10,txAvgMbps:42,rxAvgMbps:0,status:"done",error:null,createdAt:"2026-10-04T00:00:00Z"}
|
|
for (const change of ["backend","mode"] as const) for (const resource of ["probes","history"] as const) for (const failure of [false,true]) test("Uptime speed context/"+change+"/"+resource+"/"+failure,async({page})=>{
|
|
let hold=false,started=false,completed=false;let release!:()=>void;const gate=new Promise<void>(resolve=>release=resolve)
|
|
const target=resource === "probes" ? "/api/uptime/speed-probes" : "/api/uptime/speed-test/runs"
|
|
await page.route("**/health",r=>r.fulfill({headers,json:{ok:true}}))
|
|
await page.route("**/api/**",async r=>{
|
|
const url=new URL(r.request().url()),path=url.pathname,old=url.port === "8000"
|
|
const body=path === "/api/auth/config" ? {required:false} : path === "/api/servers" ? [{...server,name:old ? "Старый источник" : "Новый источник"}] : path === "/api/uptime/overview" ? {probes:[],resources:[]} : path === "/api/uptime/speed-probes" ? {probes:[{...probe,id:old ? "old-probe" : "new-probe"}]} : path === "/api/uptime/speed-test/runs" ? {runs:[{...run,id:old ? "old-run" : "new-run"}]} : {}
|
|
if(path === target && old && hold){started=true;await gate;try{await r.fulfill(failure ? {headers,status:503,json:{error:"СТАРАЯ ОШИБКА СКОРОСТИ"}} : {headers,json:body})}catch{}finally{completed=true};return}
|
|
return r.fulfill({headers,json:body})
|
|
})
|
|
await page.goto("/uptime?tab=speed");await expect(page.locator('tr[data-row-id="old-run"]')).toBeVisible();await page.getByRole("button",{name:"Пауза",exact:true}).click();hold=true;await page.getByRole("button",{name:"Обновить",exact:true}).click();await expect.poll(()=>started).toBe(true)
|
|
await page.goto("/settings")
|
|
if(change === "backend"){const input=page.getByPlaceholder("http://localhost:8000");await input.fill("http://localhost:8101");await input.press("Enter")}else await page.getByRole("button",{name:"Моковые",exact:true}).click()
|
|
await page.goto("/uptime?tab=speed")
|
|
if(change === "backend"){await expect(page.locator('tr[data-row-id="new-run"]')).toBeVisible();await expect(page.getByText("Новый источник",{exact:true}).first()).toBeVisible()}else await expect(page.getByRole("button",{name:"Сбросить",exact:true})).toBeVisible()
|
|
release();await expect.poll(()=>completed).toBe(true);await expect(page.locator('tr[data-row-id="old-run"]')).toHaveCount(0);await expect(page.getByText("СТАРАЯ ОШИБКА СКОРОСТИ",{exact:true})).toHaveCount(0)
|
|
if(change === "mode"){await expect(page.getByText(/^Speed-пробы: получено/)).toHaveCount(0);await expect(page.getByRole("alert",{name:"Чтение скорости: probes",exact:true})).toHaveCount(0)}
|
|
})
|