import { cleanup, render, screen } from "@testing-library/react"; import { afterEach, describe, expect, test, vi } from "vitest"; import { TUser } from "@formbricks/types/user"; import { IntercomClientWrapper } from "./IntercomClientWrapper"; vi.mock("@/lib/constants", () => ({ IS_INTERCOM_CONFIGURED: true, INTERCOM_APP_ID: "mock-intercom-app-id", INTERCOM_SECRET_KEY: "mock-intercom-secret-key", })); // Mock the crypto createHmac function to return a fake hash. // Vite global setup doesn't work here due to Intercom probably using crypto themselves. vi.mock("crypto", () => ({ default: { createHmac: vi.fn(() => ({ update: vi.fn().mockReturnThis(), digest: vi.fn().mockReturnValue("fake-hash"), })), }, })); vi.mock("./IntercomClient", () => ({ IntercomClient: (props: any) => (
), })); describe("IntercomClientWrapper", () => { afterEach(() => { cleanup(); }); test("renders IntercomClient with computed user hash when user is provided", () => { const testUser = { id: "user-123", name: "Test User", email: "test@example.com" } as TUser; render(