import { test, expect } from "@playwright/test" for (const state of ["partial", "unknown", "applied"] as const) { test(`IPsec: ${state} сохраняет ввод и предупреждает перед повтором`, async ({ page }) => { await page.setViewportSize({ width: 320, height: 740 }) let attempts = 0 const client = {id:"1:identity:*I",rosId:"identity:*I",serverId:"1",serverName:"CHR",name:"Alice",authMethod:"pre-shared-key",kind:"psk",online:false,disabled:false,managed:true} await page.route("**/health", route => route.fulfill({json:{ok:true}})) await page.route("**/api/**", route => { const path = new URL(route.request().url()).pathname if (route.request().method()==="PATCH" && path.startsWith("/api/ipsec/users")) { attempts++; return route.fulfill({status:502,json:{state,confirmedWrites:state==="unknown"?0:1,error:"Результат операции требует проверки. Обновите данные перед повтором"}}) } return route.fulfill({json:path==="/api/auth/config"?{required:false}:path==="/api/ipsec"?{servers:[],clients:[client]}:path==="/api/servers"?[{id:1,name:"CHR",host:"192.0.2.1",enabled:true,type:"exit-node",country:"RU",status:"online"}]:{}}) }) await page.goto("/ipsec") await page.getByRole("button",{name:"Alice",exact:true}).click() const sheet=page.getByRole("dialog") await sheet.getByLabel("Имя клиента").fill("Changed") await sheet.getByRole("button",{name:"Сохранить",exact:true}).click() await expect(sheet.getByRole("alert")).toContainText("Обновите данные перед повтором") await expect(sheet.getByLabel("Имя клиента")).toHaveValue("Changed") expect(attempts).toBe(1) expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true) }) }