diff --git a/src/app/(app)/quotes/approvals/page.test.tsx b/src/app/(app)/quotes/approvals/page.test.tsx index 849767a..0ba4eb2 100644 --- a/src/app/(app)/quotes/approvals/page.test.tsx +++ b/src/app/(app)/quotes/approvals/page.test.tsx @@ -1,4 +1,5 @@ import { describe, it, expect, beforeEach, vi } from "vitest"; +import * as React from "react"; import { fireEvent, render, screen, waitFor } from "@testing-library/react"; import ApprovalsPage from "./page"; @@ -9,13 +10,11 @@ const { refreshMock, pushMock, captureModalProps, - triggerSend, } = vi.hoisted(() => ({ getListMock: vi.fn(), refreshMock: vi.fn(), pushMock: vi.fn(), captureModalProps: vi.fn(), - triggerSend: vi.fn(), })); // Stub the PocketBase client so we can drive list contents from the test. @@ -29,7 +28,14 @@ vi.mock("@/lib/pocketbase", () => ({ if (name === "quote_items") { return { getFullList: async () => [] }; } - return { getFullList: async () => [], getList: async () => ({ items: [] }) }; + // Defensive fallback for any other collection the page or + // SendQuoteModal may read in Tasks 2-3 (e.g. quote_attachments, + // users). Match the PB envelope shape so code that consumes + // totalItems / totalPages doesn't crash on undefined. + return { + getFullList: async () => [], + getList: async () => ({ items: [], totalItems: 0, totalPages: 1 }), + }; }, }), })); @@ -40,15 +46,16 @@ vi.mock("next/navigation", () => ({ })); // Replace SendQuoteModal with a thin stub. The test grabs the props the -// page passed in via captureModalProps; triggerSend becomes the onSend -// prop, so tests can fire the modal submit callback directly. +// page passed in via captureModalProps; clicking the test's "Submit +// modal" button calls props.onSend directly, which is the page's +// sendApprove callback — so the fetch / refresh / toast assertions +// downstream observe real effects. +type SendQuoteModalProps = React.ComponentProps< + typeof import("@/components/quotes/send-quote-modal").SendQuoteModal +>; + vi.mock("@/components/quotes/send-quote-modal", () => ({ - SendQuoteModal: (props: { - open: boolean; - submitLabel?: string; - onSend: (p: unknown) => Promise; - quote: { id: string }; - }) => { + SendQuoteModal: (props: SendQuoteModalProps) => { captureModalProps(props); if (!props.open) return null; return ( @@ -58,7 +65,7 @@ vi.mock("@/components/quotes/send-quote-modal", () => ({