waitlist-modal.test.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { render, screen } from "@testing-library/react";
  2. import { it, describe, expect, vi } from "vitest";
  3. import userEvent from "@testing-library/user-event";
  4. import { WaitlistModal } from "#/components/features/waitlist/waitlist-modal";
  5. import * as CaptureConsent from "#/utils/handle-capture-consent";
  6. describe("WaitlistModal", () => {
  7. it("should render a tos checkbox that is unchecked by default", () => {
  8. render(<WaitlistModal ghToken={null} githubAuthUrl={null} />);
  9. const checkbox = screen.getByRole("checkbox");
  10. expect(checkbox).not.toBeChecked();
  11. });
  12. it("should only enable the GitHub button if the tos checkbox is checked", async () => {
  13. const user = userEvent.setup();
  14. render(<WaitlistModal ghToken={null} githubAuthUrl={null} />);
  15. const checkbox = screen.getByRole("checkbox");
  16. const button = screen.getByRole("button", { name: "Connect to GitHub" });
  17. expect(button).toBeDisabled();
  18. await user.click(checkbox);
  19. expect(button).not.toBeDisabled();
  20. });
  21. it("should set user analytics consent to true when the user checks the tos checkbox", async () => {
  22. const handleCaptureConsentSpy = vi.spyOn(
  23. CaptureConsent,
  24. "handleCaptureConsent",
  25. );
  26. const user = userEvent.setup();
  27. render(<WaitlistModal ghToken={null} githubAuthUrl="mock-url" />);
  28. const checkbox = screen.getByRole("checkbox");
  29. await user.click(checkbox);
  30. const button = screen.getByRole("button", { name: "Connect to GitHub" });
  31. await user.click(button);
  32. expect(handleCaptureConsentSpy).toHaveBeenCalledWith(true);
  33. });
  34. });