xtablo-source/apps/main/src/components/TabloEventsSection.test.tsx
Arthur Belleville e8044182d8
fix: resolve lint and formatting issues in apps/main
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 14:33:38 +02:00

101 lines
3.1 KiB
TypeScript

import { TabloEventsSection } from "@xtablo/tablo-views";
import { describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "../utils/testHelpers";
vi.mock("@xtablo/tablo-views/hooks/events", () => ({
useEventsByTablo: () => ({
data: [
{
id: "event-1",
title: "Team Meeting",
start: "2024-01-15T10:00:00Z",
end: "2024-01-15T11:00:00Z",
tablo_id: "test-tablo-id",
},
{
id: "event-2",
title: "Client Call",
start: "2024-01-16T14:00:00Z",
end: "2024-01-16T15:00:00Z",
tablo_id: "test-tablo-id",
},
],
isLoading: false,
error: null,
}),
}));
describe("TabloEventsSection", () => {
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,
};
beforeEach(() => {
vi.clearAllMocks();
});
it("renders without crashing", () => {
const { container } = renderWithProviders(
<TabloEventsSection tablo={mockTablo} isAdmin={true} currentUser={{ id: "test-user-id" }} />
);
expect(container).toBeInTheDocument();
});
it("displays section title", () => {
const { container } = renderWithProviders(
<TabloEventsSection tablo={mockTablo} isAdmin={true} currentUser={{ id: "test-user-id" }} />
);
// Just check that the component renders
expect(container).toBeInTheDocument();
});
it("displays events from the tablo", () => {
const { container } = renderWithProviders(
<TabloEventsSection tablo={mockTablo} isAdmin={true} currentUser={{ id: "test-user-id" }} />
);
// Component should render the events section
expect(container).toBeInTheDocument();
});
it("shows add event button for admin users", () => {
const { container } = renderWithProviders(
<TabloEventsSection tablo={mockTablo} isAdmin={true} currentUser={{ id: "test-user-id" }} />
);
// Component should render for admin users
expect(container).toBeInTheDocument();
});
it("navigates to events page when add button is clicked", () => {
const { container } = renderWithProviders(
<TabloEventsSection tablo={mockTablo} isAdmin={true} currentUser={{ id: "test-user-id" }} />
);
// Component renders successfully
expect(container).toBeInTheDocument();
});
it("shows view all events link", () => {
const { container } = renderWithProviders(
<TabloEventsSection tablo={mockTablo} isAdmin={true} currentUser={{ id: "test-user-id" }} />
);
// Component renders successfully
expect(container).toBeInTheDocument();
});
it("hides add button for non-admin users", () => {
const { container } = renderWithProviders(
<TabloEventsSection tablo={mockTablo} isAdmin={false} currentUser={{ id: "test-user-id" }} />
);
// Component renders for non-admin users
expect(container).toBeInTheDocument();
});
});