90 lines
2.4 KiB
TypeScript
90 lines
2.4 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { renderWithProviders } from "../utils/testHelpers";
|
|
import { TabloMembersSection } from "./TabloMembersSection";
|
|
|
|
vi.mock("../hooks/tablos", () => ({
|
|
useTabloMembers: () => ({
|
|
data: [
|
|
{
|
|
id: "user-1",
|
|
name: "John Doe",
|
|
email: "john@example.com",
|
|
is_admin: true,
|
|
},
|
|
{
|
|
id: "user-2",
|
|
name: "Jane Smith",
|
|
email: "jane@example.com",
|
|
is_admin: false,
|
|
},
|
|
],
|
|
}),
|
|
}));
|
|
|
|
vi.mock("../hooks/tablo_invites", () => ({
|
|
usePendingTabloInvitesByTablo: () => ({
|
|
data: [],
|
|
}),
|
|
useCancelTabloInvite: () => ({
|
|
mutate: vi.fn(),
|
|
isPending: false,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("../hooks/invite", () => ({
|
|
useInviteUser: () => ({
|
|
mutate: vi.fn(),
|
|
isPending: false,
|
|
}),
|
|
}));
|
|
|
|
describe("TabloMembersSection", () => {
|
|
const mockTablo = {
|
|
id: "test-tablo-id",
|
|
name: "Test Tablo",
|
|
color: "bg-blue-500",
|
|
user_id: "test-user-id",
|
|
access_level: "admin",
|
|
is_admin: true,
|
|
created_at: "2024-01-01T00:00:00Z",
|
|
deleted_at: "2024-01-01T00:00:00Z",
|
|
position: 0,
|
|
status: "active",
|
|
image: null,
|
|
};
|
|
|
|
it("renders without crashing for admin", () => {
|
|
const { container } = renderWithProviders(
|
|
<TabloMembersSection tablo={mockTablo} isAdmin={true} />
|
|
);
|
|
expect(container).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders without crashing for non-admin", () => {
|
|
const { container } = renderWithProviders(
|
|
<TabloMembersSection tablo={mockTablo} isAdmin={false} />
|
|
);
|
|
expect(container).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows invite section for admin", () => {
|
|
const { getByPlaceholderText } = renderWithProviders(
|
|
<TabloMembersSection tablo={mockTablo} isAdmin={true} />
|
|
);
|
|
expect(getByPlaceholderText("Email de l'utilisateur à inviter")).toBeInTheDocument();
|
|
});
|
|
|
|
it("does not show invite section for non-admin", () => {
|
|
const { queryByPlaceholderText } = renderWithProviders(
|
|
<TabloMembersSection tablo={mockTablo} isAdmin={false} />
|
|
);
|
|
expect(queryByPlaceholderText("Email de l'utilisateur à inviter")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("shows members list for all users", () => {
|
|
const { getByText } = renderWithProviders(
|
|
<TabloMembersSection tablo={mockTablo} isAdmin={false} />
|
|
);
|
|
expect(getByText("Membres du tablo")).toBeInTheDocument();
|
|
});
|
|
});
|