Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/app/solve/accept-intent.integration.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { OpenIntent } from "@/lib/types";

const { fetcherMock, acceptIntentMock } = vi.hoisted(() => ({
fetcherMock: vi.fn(),
acceptIntentMock: vi.fn(),
}));
vi.mock("@/lib/api", () => ({
fetcher: fetcherMock,
acceptIntent: acceptIntentMock,
}));

import { useWalletStore } from "@/store/wallet";
import { ToastViewport } from "@/components/ToastViewport";
import SolvePage from "./page";

const openIntent: OpenIntent = {
id: "a1b2",
srcChain: "ethereum",
srcToken: "USDC",
srcAmount: "500",
dstToken: "USDC",
minOut: "495",
deadline: new Date(Date.now() + 18 * 60_000).toISOString(),
};

const initialWalletState = useWalletStore.getState();

function renderSolvePage() {
return render(
<>
<SolvePage />
<ToastViewport />
</>
);
}

describe("solve page accept-intent flow (integration)", () => {
beforeEach(() => {
useWalletStore.setState({ ...initialWalletState, isConnected: true, address: "GABC123" }, true);
});

afterEach(() => {
useWalletStore.setState(initialWalletState, true);
vi.clearAllMocks();
});

it("lists an open intent, accepts it, shows a success toast, and removes it from the feed", async () => {
fetcherMock.mockImplementation(async (path: string) => {
if (path === "/solvers") return [];
if (path === "/intents/open") {
return acceptIntentMock.mock.calls.length > 0 ? [] : [openIntent];
}
throw new Error(`Unexpected fetch: ${path}`);
});
acceptIntentMock.mockResolvedValue({ intentId: "a1b2", status: "accepted" });

const user = userEvent.setup();
renderSolvePage();

await user.click(screen.getByRole("tab", { name: "intents" }));
await waitFor(() => expect(screen.getByText("500 USDC on ethereum")).toBeInTheDocument());

await user.click(screen.getByText("Accept Intent →"));

await waitFor(() => {
expect(screen.getByText("Intent accepted — you have exclusive fill rights.")).toBeInTheDocument();
});
expect(acceptIntentMock).toHaveBeenCalledWith("a1b2", "GABC123");

await waitFor(() => {
expect(screen.getByText(/No open intents right now/)).toBeInTheDocument();
});
});
});