|
| 1 | +import React from "react"; |
| 2 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 3 | +import { renderWithProviders, screen } from "@/__tests__/test-utils"; |
| 4 | + |
| 5 | +const TEST_WETH = "0x7b79995e5f793a07bc00c21412e50ecae098e7f9"; |
| 6 | + |
| 7 | +const mockUseGardens = vi.fn(); |
| 8 | +const mockUseGardenVaults = vi.fn(); |
| 9 | +const mockUseMyVaultDeposits = vi.fn(); |
| 10 | +const mockUseVaultPreview = vi.fn(); |
| 11 | + |
| 12 | +vi.mock("@green-goods/shared", async (importOriginal) => { |
| 13 | + const actual = await importOriginal<typeof import("@green-goods/shared")>(); |
| 14 | + return { |
| 15 | + ...actual, |
| 16 | + formatAddress: (value: string) => value.slice(0, 6), |
| 17 | + formatTokenAmount: (value: bigint) => (value === 0n ? "0" : `${Number(value) / 10 ** 18}`), |
| 18 | + getNetDeposited: (deposited: bigint, withdrawn: bigint) => deposited - withdrawn, |
| 19 | + getVaultAssetSymbol: (asset: string) => (asset.toLowerCase() === TEST_WETH ? "WETH" : "DAI"), |
| 20 | + ImageWithFallback: ({ alt }: { alt: string }) => React.createElement("div", null, alt), |
| 21 | + useDebouncedValue: <T,>(value: T) => value, |
| 22 | + useGardens: () => mockUseGardens(), |
| 23 | + useGardenVaults: (...args: unknown[]) => mockUseGardenVaults(...args), |
| 24 | + useMyVaultDeposits: (...args: unknown[]) => mockUseMyVaultDeposits(...args), |
| 25 | + useUser: () => ({ primaryAddress: "0x1111111111111111111111111111111111111111" }), |
| 26 | + useVaultPreview: (...args: unknown[]) => mockUseVaultPreview(...args), |
| 27 | + }; |
| 28 | +}); |
| 29 | + |
| 30 | +vi.mock("react-router-dom", () => ({ |
| 31 | + Link: ({ to, state, children, ...props }: any) => |
| 32 | + React.createElement("a", { href: to, "data-state": JSON.stringify(state), ...props }, children), |
| 33 | +})); |
| 34 | + |
| 35 | +vi.mock("@/components/Layout/PageHeader", () => ({ |
| 36 | + PageHeader: ({ title, description }: { title: string; description?: string }) => |
| 37 | + React.createElement( |
| 38 | + "div", |
| 39 | + { "data-testid": "page-header" }, |
| 40 | + React.createElement("h1", null, title), |
| 41 | + description ? React.createElement("p", null, description) : null |
| 42 | + ), |
| 43 | +})); |
| 44 | + |
| 45 | +vi.mock("@/components/StatCard", () => ({ |
| 46 | + StatCard: ({ label, value }: { label: string; value: React.ReactNode }) => |
| 47 | + React.createElement( |
| 48 | + "div", |
| 49 | + null, |
| 50 | + React.createElement("span", null, label), |
| 51 | + React.createElement("span", null, value) |
| 52 | + ), |
| 53 | +})); |
| 54 | + |
| 55 | +vi.mock("@/components/ui/Card", () => ({ |
| 56 | + Card: ({ children }: { children: React.ReactNode }) => React.createElement("div", null, children), |
| 57 | +})); |
| 58 | + |
| 59 | +vi.mock("@/components/ui/EmptyState", () => ({ |
| 60 | + EmptyState: ({ title, description }: { title: string; description?: string }) => |
| 61 | + React.createElement("div", null, title, description), |
| 62 | +})); |
| 63 | + |
| 64 | +vi.mock("@/components/ui/ListToolbar", () => ({ |
| 65 | + ListToolbar: ({ children }: { children: React.ReactNode }) => |
| 66 | + React.createElement("div", null, children), |
| 67 | +})); |
| 68 | + |
| 69 | +vi.mock("@/components/ui/SortSelect", () => ({ |
| 70 | + SortSelect: () => React.createElement("div", null, "sort"), |
| 71 | +})); |
| 72 | + |
| 73 | +import EndowmentsOverview from "./index"; |
| 74 | + |
| 75 | +describe("EndowmentsOverview", () => { |
| 76 | + beforeEach(() => { |
| 77 | + vi.clearAllMocks(); |
| 78 | + mockUseGardens.mockReturnValue({ |
| 79 | + data: [{ id: "garden-1", name: "Alpha Garden", location: "One" }], |
| 80 | + isLoading: false, |
| 81 | + }); |
| 82 | + mockUseGardenVaults.mockReturnValue({ |
| 83 | + vaults: [ |
| 84 | + { |
| 85 | + id: "vault-1", |
| 86 | + chainId: 11155111, |
| 87 | + garden: "garden-1", |
| 88 | + asset: TEST_WETH, |
| 89 | + vaultAddress: "0x4444444444444444444444444444444444444444", |
| 90 | + totalDeposited: 1_000_000_000_000_000_000n, |
| 91 | + totalWithdrawn: 0n, |
| 92 | + totalHarvestCount: 3, |
| 93 | + }, |
| 94 | + ], |
| 95 | + isLoading: false, |
| 96 | + }); |
| 97 | + mockUseMyVaultDeposits.mockReturnValue({ |
| 98 | + deposits: [], |
| 99 | + isLoading: false, |
| 100 | + }); |
| 101 | + mockUseVaultPreview.mockReturnValue({ |
| 102 | + preview: { previewAssets: 1_000_000_000_000_000_000n }, |
| 103 | + isLoading: false, |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + it("passes endowments return context into the manage vault link", () => { |
| 108 | + renderWithProviders(<EndowmentsOverview />); |
| 109 | + |
| 110 | + expect(screen.getByRole("link", { name: /manage vault/i })).toHaveAttribute( |
| 111 | + "data-state", |
| 112 | + JSON.stringify({ returnTo: "/endowments", returnLabelId: "app.admin.nav.treasury" }) |
| 113 | + ); |
| 114 | + }); |
| 115 | +}); |
0 commit comments