theo-agent-dashboard

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

Sidebar.test.tsx (1675B)


      1 import { describe, it, expect, vi, beforeEach } from "vitest";
      2 import { render, screen, fireEvent } from "@testing-library/react";
      3 import { Sidebar } from "./Sidebar";
      4 
      5 vi.mock("./TopicList", () => ({
      6   TopicList: () => <div data-testid="topic-list">TopicList</div>,
      7 }));
      8 
      9 vi.mock("./SessionList", () => ({
     10   SessionList: ({ onSelectSession }: { onSelectSession?: (id: string) => void }) => (
     11     <div data-testid="session-list" onClick={() => onSelectSession?.("s1")}>
     12       SessionList
     13     </div>
     14   ),
     15 }));
     16 
     17 beforeEach(() => {
     18   vi.restoreAllMocks();
     19   vi.stubGlobal("fetch", vi.fn().mockResolvedValue({
     20     ok: true,
     21     json: async () => ({}),
     22   }));
     23 });
     24 
     25 describe("Sidebar", () => {
     26   it("renders Theo Dashboard heading", () => {
     27     render(<Sidebar />);
     28     expect(screen.getByText("Theo Dashboard")).toBeInTheDocument();
     29   });
     30 
     31   it("renders TopicList", () => {
     32     render(<Sidebar />);
     33     expect(screen.getByTestId("topic-list")).toBeInTheDocument();
     34   });
     35 
     36   it("renders SessionList", () => {
     37     render(<Sidebar />);
     38     expect(screen.getByTestId("session-list")).toBeInTheDocument();
     39   });
     40 
     41   it("passes onSelectSession to SessionList", () => {
     42     const onSelectSession = vi.fn();
     43     render(<Sidebar onSelectSession={onSelectSession} />);
     44     fireEvent.click(screen.getByTestId("session-list"));
     45     expect(onSelectSession).toHaveBeenCalledWith("s1");
     46   });
     47 
     48   it("renders with proper layout classes", () => {
     49     const { container } = render(<Sidebar />);
     50     const aside = container.querySelector("aside");
     51     expect(aside).toBeInTheDocument();
     52     expect(aside?.className).toContain("w-64");
     53     expect(aside?.className).toContain("bg-gray-900");
     54   });
     55 });