import "@testing-library/jest-dom/vitest"; import { describe, expect, it, vi, beforeEach } from "vitest"; import { fireEvent, waitFor } from "@testing-library/react"; import { renderWithProviders as render, screen, } from "../utils/test-utils"; import HowItWorksShareRow from "../../app/(marketing)/how-it-works/_components/HowItWorksShareRow"; const writeText = vi.fn().mockResolvedValue(undefined); describe("HowItWorksShareRow", () => { beforeEach(() => { writeText.mockReset(); writeText.mockResolvedValue(undefined); Object.defineProperty(window.navigator, "clipboard", { configurable: true, value: { writeText }, }); }); it("copies wiki markdown and prints only the rule card", async () => { const print = vi.spyOn(window, "print").mockImplementation(() => {}); render( , ); expect( screen.getByRole("link", { name: "Send this to your community" }), ).toHaveAttribute("href", "mailto:?subject=Guide"); fireEvent.click( screen.getByRole("button", { name: "Copy into your wiki" }), ); await waitFor(() => { expect(writeText).toHaveBeenCalledWith("[Guide](https://example.com)"); }); expect(screen.getByText("Copied to clipboard")).toBeInTheDocument(); fireEvent.click(screen.getByRole("button", { name: "Print the card" })); expect(print).toHaveBeenCalled(); const printStyle = document.getElementById("how-it-works-card-print"); expect(printStyle?.textContent).toContain("#how-it-works-rule-card"); expect(printStyle?.textContent).toContain("visibility: hidden"); window.dispatchEvent(new Event("afterprint")); expect(document.getElementById("how-it-works-card-print")).toBeNull(); print.mockRestore(); }); });