Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1.7 KB
Raw Blame
import { describe, expect, it, vi } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { MantineProvider } from "@mantine/core";

vi.mock("react-i18next", () => ({
  useTranslation: () => ({
    t: (key: string, fallback?: string, opts?: Record<string, unknown>) => {
      const base = fallback ?? key;
      // Minimal interpolation so {{email}} / {{who}} assertions read naturally.
      return opts
        ? base.replace(/\{\{(\w+)\}\}/g, (_, k) => String(opts[k] ?? ""))
        : base;
    },
  }),
}));

import { PendingInvitations } from "@processor/components/users/PendingInvitations";
import type { PendingInvitation } from "@processor/api/users";

const INVITES: PendingInvitation[] = [
  { id: 101, email: "[email protected]", invitedBy: "[email protected]" },
  { id: 102, email: "[email protected]" },
];

function renderPanel(onCancel = vi.fn()) {
  render(
    <MantineProvider>
      <PendingInvitations invitations={INVITES} onCancel={onCancel} />
    </MantineProvider>,
  );
  return onCancel;
}

describe("PendingInvitations", () => {
  it("lists each pending invite with its email and inviter", () => {
    renderPanel();
    expect(screen.getByText("[email protected]")).toBeInTheDocument();
    expect(screen.getByText("[email protected]")).toBeInTheDocument();
    expect(screen.getByText("Invited by [email protected]")).toBeInTheDocument();
    expect(screen.getByText("Pending invitations")).toBeInTheDocument();
  });

  it("cancelling an invite calls back with that invitation", () => {
    const onCancel = renderPanel();
    const buttons = screen.getAllByText("Cancel");
    fireEvent.click(buttons[0]);
    expect(onCancel).toHaveBeenCalledWith(INVITES[0]);
  });
});