|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import React, { act } from "react"; |
| 3 | +import { createRoot } from "react-dom/client"; |
| 4 | + |
| 5 | +vi.mock("@churchapps/helpers", async (importOriginal) => { |
| 6 | + const actual: any = await importOriginal(); |
| 7 | + const notifications = [{ id: "n1", churchId: "c1", contentType: "task", contentId: "TSK1", message: "New task", timeSent: new Date(), isNew: true }]; |
| 8 | + return { ...actual, ApiHelper: { ...actual.ApiHelper, get: vi.fn().mockResolvedValue(notifications) } }; |
| 9 | +}); |
| 10 | + |
| 11 | +import { Notifications } from "../Notifications"; |
| 12 | + |
| 13 | +(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true; |
| 14 | + |
| 15 | +describe("Notifications click", () => { |
| 16 | + it("sends a task notification to the B1Admin serving task page", async () => { |
| 17 | + const onNavigate = vi.fn(); |
| 18 | + const container = document.createElement("div"); |
| 19 | + document.body.appendChild(container); |
| 20 | + const root = createRoot(container); |
| 21 | + const context: any = { userChurch: { church: { id: "c1", subDomain: "grace" } } }; |
| 22 | + |
| 23 | + await act(async () => { |
| 24 | + root.render(<Notifications appName="B1Admin" context={context} onNavigate={onNavigate} onUpdate={() => {}} />); |
| 25 | + }); |
| 26 | + |
| 27 | + const item = container.querySelector("#notification-item-n1") as HTMLElement; |
| 28 | + expect(item).not.toBeNull(); |
| 29 | + await act(async () => { item.click(); }); |
| 30 | + |
| 31 | + expect(onNavigate).toHaveBeenCalledWith("/serving/tasks/TSK1"); |
| 32 | + act(() => root.unmount()); |
| 33 | + container.remove(); |
| 34 | + }); |
| 35 | +}); |
0 commit comments