import { test, expect } from "@playwright/test" test("IPsec: удаление держит замок до обновления и отделяет ошибку чтения", async ({ page }) => { const client = { id: "1-*1", rosId: "*1", serverId: "1", serverName: "Роутер", name: "Клиент тест", authMethod: "certificate", online: false, disabled: false, managed: true } let reads = 0, writes = 0, release: (() => void) | undefined, phase = 0 const gate = new Promise(resolve => { release = resolve }) await page.route("**/health", r => r.fulfill({ json: { ok: true } })) await page.route("**/api/**", async r => { const path = new URL(r.request().url()).pathname if (r.request().method() === "DELETE") { writes++; await gate; phase = 1; return r.fulfill({ json: { ok: true } }) } if (path === "/api/ipsec") { reads++ return phase === 1 ? r.fulfill({ status: 503, json: { error: "Опрос после удаления недоступен" } }) : r.fulfill({ json: { servers: [], clients: phase === 2 ? [] : [client] } }) } return r.fulfill({ json: path === "/api/servers" ? [{ id: 1, name: "Роутер", host: "192.0.2.1", enabled: true, country: "RU" }] : path === "/api/auth/config" ? { required: false } : {} }) }) await page.goto("/ipsec") const rows = page.locator("tr[data-row-id]") await expect(rows).toHaveCount(1) await page.getByRole("button", { name: "Удалить клиента", exact: true }).click() const dialog = page.getByRole("alertdialog") const submit = dialog.getByRole("button", { name: "Удалить", exact: true }) await submit.evaluate(el => { (el as HTMLButtonElement).click(); (el as HTMLButtonElement).click() }) await expect.poll(() => writes).toBe(1) const before = reads const refresh = page.getByRole("button", { name: "Обновить", exact: true, includeHidden: true }) await expect(refresh).toBeDisabled() await refresh.evaluate(el => (el as HTMLButtonElement).click()) expect(reads).toBe(before) await expect(submit).toBeDisabled() release!() await expect(dialog).toHaveCount(0) await expect(page.getByRole("alert").filter({ hasText: "Не удалось загрузить IPsec" })).toContainText("Опрос после удаления недоступен") await expect(rows).toHaveCount(1) await expect(rows.getByRole("button", { name: "Удалить клиента" })).toBeDisabled() phase = 2 await page.getByRole("button", { name: "Повторить загрузку IPsec" }).click() await expect(rows).toHaveCount(0) await expect(page.getByText("Нет клиентов IKEv2", { exact: true })).toBeVisible() expect(writes).toBe(1) })