From 367931ce55006dfcd0d4b32f45fcd371d4866ada Mon Sep 17 00:00:00 2001 From: OlolaJaco Date: Fri, 26 Jun 2026 22:52:59 +0100 Subject: [PATCH 1/4] test(faucet): add connected-state render tests with MSW RPC handlers (#214) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renders FaucetPage with a seeded connected wallet and intercepts all simulateTransaction calls via MSW, returning XDR-encoded ScVal responses so useFaucetData runs real — no data-fetching layer is mocked. --- .../components/faucet-page-connected.test.tsx | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 apps/web/src/features/faucet/components/faucet-page-connected.test.tsx diff --git a/apps/web/src/features/faucet/components/faucet-page-connected.test.tsx b/apps/web/src/features/faucet/components/faucet-page-connected.test.tsx new file mode 100644 index 0000000..0f0fd3a --- /dev/null +++ b/apps/web/src/features/faucet/components/faucet-page-connected.test.tsx @@ -0,0 +1,171 @@ +import { describe, it, expect, beforeEach, afterEach, vi } from "vitest" +import { render, screen, waitFor } from "@testing-library/react" +import { QueryClient, QueryClientProvider } from "@tanstack/react-query" +import { HttpResponse, http } from "msw" +import { Account, Networks, TransactionBuilder, nativeToScVal, rpc } from "@stellar/stellar-sdk" +import { useWalletStore } from "@/features/wallet/store/wallet-store" +import { server } from "@/test/msw/server" +import { fakeWalletAddress } from "@/test/fakes/wallet" +import { FaucetPage } from "./faucet-page" + +// ── Fixed seed values ───────────────────────────────────────────────────────── +// fromContractAmount divides raw bigint by 1e7 +// 10_000_000n / 1e7 = 1 → formatToken → "1 TUSDC" +// 50_000_000n / 1e7 = 5 → formatToken → "5 TUSDC" +const CLAIM_AMOUNT_RAW = 10_000_000n +const BALANCE_RAW = 50_000_000n +const COOLDOWN_LEDGERS = 100 +const LAST_CLAIM_LEDGER = 999 + +// ── UI and claim mocks ──────────────────────────────────────────────────────── +// useClaim is stubbed because it transitively imports @/lib/contracts.ts, which +// instantiates contract clients at module-load time with test contract IDs that +// fail Stellar strkey validation in bun's test runner. The data-fetching path +// (useFaucetData / lib/clients / data/tokens) is left completely real. +vi.mock("../hooks/useClaim", () => ({ + useClaim: () => ({ + claimOne: vi.fn(), + claimAll: vi.fn(), + pendingTokens: new Set(), + isBulkPending: false, + }), +})) +vi.mock("@/ui/Navbar", () => ({ Navbar: () =>