import { describe, it, expect, vi } from "vitest"; import { render, screen, fireEvent } from "@testing-library/react"; import { ReceiptDialog } from "./ReceiptDialog"; // redesign-pos-sale-flow (BABYBOO-38): after a sale, "Payment complete" with the receipt, the // collection, and Start new sale as the only way out. function renderDialog() { const onNewSale = vi.fn(); render(

receipt lines

, ); return onNewSale; } describe("ReceiptDialog", () => { it("says the payment is complete, with the sale number and total", () => { renderDialog(); expect(screen.getByRole("dialog", { name: "Payment complete" })).toBeInTheDocument(); expect(screen.getByText("Sale IN00000042 · RM 194.00")).toBeInTheDocument(); // A long/UUID document number must wrap inside the narrow dialog (class-level; jsdom has no layout). expect(screen.getByText("Sale IN00000042 · RM 194.00")).toHaveClass("[overflow-wrap:anywhere]"); }); it("shows the collection and the receipt", () => { renderDialog(); expect(screen.getByTestId("receipt-collection")).toHaveTextContent("Pick up at HQ"); expect(screen.getByText("receipt lines")).toBeInTheDocument(); }); it("Start new sale starts the next sale", () => { const onNewSale = renderDialog(); fireEvent.click(screen.getByRole("button", { name: "Start new sale" })); expect(onNewSale).toHaveBeenCalled(); }); it("cannot be dismissed any other way", () => { const onNewSale = renderDialog(); expect(screen.queryByRole("button", { name: "Close" })).not.toBeInTheDocument(); fireEvent.keyDown(screen.getByRole("dialog"), { key: "Escape" }); expect(onNewSale).not.toHaveBeenCalled(); expect(screen.getByRole("dialog", { name: "Payment complete" })).toBeInTheDocument(); }); // BABYBOO-39: a long product name made the grid dialog's content wider than the dialog. jsdom has no layout, // so this pins the classes that fix it (verified visually on dev-adm), not the rendered width. it("lets its children shrink below content width so wide receipts scroll instead of overflowing", () => { renderDialog(); expect(screen.getByRole("dialog").className).toContain("[&>*]:min-w-0"); }); });