diff --git a/src/components/GovernanceDashboard.test.tsx b/src/components/GovernanceDashboard.test.tsx index a4c9c97..bbdeed8 100644 --- a/src/components/GovernanceDashboard.test.tsx +++ b/src/components/GovernanceDashboard.test.tsx @@ -5,7 +5,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { useSorokit } from "@/context/useSorokit"; import type { InvokeParams, SorokitClient } from "@/lib/client"; -import { GovernanceDashboard, type GovernanceProposal } from "./GovernanceDashboard"; +import { GovernanceDashboard, type GovernanceProposal, isVotingClosed } from "./GovernanceDashboard"; vi.mock("@/context/useSorokit", () => ({ useSorokit: vi.fn(), @@ -485,4 +485,46 @@ describe("GovernanceDashboard", () => { expect(screen.queryByRole("status")).not.toBeInTheDocument(); }); }); + + // ─── Disconnect reset ───────────────────────────────────────────────────── + describe("disconnect reset", () => { + it("clears stale proposals and the delegate when the wallet disconnects", async () => { + const { client } = makeClient({ + proposals: PROPOSALS, + delegate: VALID_ADDRESS, + }); + mockSorokit(client); + + const { rerender } = render(); + + expect(await screen.findByText(PROPOSALS[0].title)).toBeInTheDocument(); + expect(screen.getByTestId("current-delegate")).toHaveAttribute( + "title", + VALID_ADDRESS, + ); + + mockSorokit(client, { isConnected: false }); + rerender(); + + expect(screen.queryByText(PROPOSALS[0].title)).not.toBeInTheDocument(); + expect( + screen.getByText(/connect your wallet to view proposals/i), + ).toBeInTheDocument(); + expect(screen.getByTestId("current-delegate")).toHaveTextContent( + /none/i, + ); + }); + }); + + // ─── isVotingClosed helper ──────────────────────────────────────────────── + describe("isVotingClosed", () => { + it("returns true only for terminal statuses", () => { + expect(isVotingClosed("active")).toBe(false); + expect(isVotingClosed("pending")).toBe(false); + expect(isVotingClosed("closed")).toBe(true); + expect(isVotingClosed("executed")).toBe(true); + expect(isVotingClosed("passed")).toBe(true); + expect(isVotingClosed("rejected")).toBe(true); + }); + }); });