|
| 1 | +import { act } from "react"; |
| 2 | +import { createRoot } from "react-dom/client"; |
| 3 | +import { afterEach, describe, expect, it } from "vitest"; |
| 4 | +import { FundDonation } from "../components/FundDonation"; |
| 5 | + |
| 6 | +(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true; |
| 7 | + |
| 8 | +const funds: any[] = [ |
| 9 | + { id: "F1", name: "Building", description: "New roof and <b>parking</b> lot" }, |
| 10 | + { id: "F2", name: "General" } |
| 11 | +]; |
| 12 | + |
| 13 | +let root: ReturnType<typeof createRoot> | null = null; |
| 14 | +const render = (fundId: string, hideFundSelect = false) => { |
| 15 | + const container = document.createElement("div"); |
| 16 | + root = createRoot(container); |
| 17 | + act(() => { |
| 18 | + root!.render(<FundDonation fundDonation={{ fundId, amount: 25 }} funds={funds} index={0} updatedFunction={() => {}} hideFundSelect={hideFundSelect} />); |
| 19 | + }); |
| 20 | + return container; |
| 21 | +}; |
| 22 | + |
| 23 | +describe("Fund description on the giving form", () => { |
| 24 | + afterEach(() => { act(() => root?.unmount()); root = null; }); |
| 25 | + |
| 26 | + it("shows the selected fund's description as plain text", () => { |
| 27 | + const el = render("F1").querySelector("[data-testid='fund-description']"); |
| 28 | + expect(el?.textContent).toBe("New roof and <b>parking</b> lot"); |
| 29 | + expect(el?.querySelector("b")).toBeNull(); |
| 30 | + }); |
| 31 | + |
| 32 | + it("shows it on a fund giving link, where the fund select is hidden", () => { |
| 33 | + expect(render("F1", true).querySelector("[data-testid='fund-description']")?.textContent).toContain("New roof"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("shows nothing for a fund without a description", () => { |
| 37 | + expect(render("F2").querySelector("[data-testid='fund-description']")).toBeNull(); |
| 38 | + }); |
| 39 | +}); |
0 commit comments