diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx index 223b777c..afc4b3ee 100644 --- a/src/components/AppLayout.tsx +++ b/src/components/AppLayout.tsx @@ -4,7 +4,7 @@ import { type Project } from '@/lib/ProjectsManager'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { Button } from '@/components/ui/button'; -import { Menu, Columns2 } from 'lucide-react'; +import { Menu } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; interface AppLayoutProps { @@ -129,6 +129,7 @@ export function AppLayout({ selectedProject={selectedProject} onSelectProject={handleProjectSelect} className="h-screen sticky top-0" + onToggleSidebar={() => setIsSidebarVisible(false)} /> )} @@ -136,16 +137,16 @@ export function AppLayout({ {/* Main Content Area */}
- {/* Toggle Button - positioned absolutely in top-left corner */} - {showSidebar && ( + {/* Show open button when sidebar is collapsed */} + {showSidebar && !isSidebarVisible && ( )} diff --git a/src/components/ProjectSidebar.test.tsx b/src/components/ProjectSidebar.test.tsx new file mode 100644 index 00000000..be2ff20f --- /dev/null +++ b/src/components/ProjectSidebar.test.tsx @@ -0,0 +1,105 @@ +import { render, screen, fireEvent } from '@testing-library/react'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { ProjectSidebar } from './ProjectSidebar'; +import { useProjects } from '@/hooks/useProjects'; +import { useLocalStorage } from '@/hooks/useLocalStorage'; + +// Mock the hooks +vi.mock('@/hooks/useProjects'); +vi.mock('@/hooks/useLocalStorage'); +vi.mock('@/hooks/useProjectSessionStatus', () => ({ + useProjectSessionStatus: () => ({ hasRunningSessions: false }) +})); +vi.mock('react-router-dom', () => ({ + useNavigate: () => vi.fn() +})); +vi.mock('@tanstack/react-query', () => ({ + useQueryClient: () => ({ + invalidateQueries: vi.fn() + }) +})); + +// Mock the LoginArea component +vi.mock('@/components/auth/LoginArea', () => ({ + LoginArea: ({ className }: { className?: string }) => ( +
Login Area
+ ) +})); + +const mockUseProjects = vi.mocked(useProjects); +const mockUseLocalStorage = vi.mocked(useLocalStorage); + +describe('ProjectSidebar', () => { + beforeEach(() => { + mockUseProjects.mockReturnValue({ + data: [], + isLoading: false, + error: null + } as unknown as ReturnType); + + mockUseLocalStorage.mockReturnValue([[], vi.fn()]); + }); + + it('renders sidebar header with logo', () => { + render( + + ); + + expect(screen.getByText('🎭')).toBeInTheDocument(); + expect(screen.getByText('Shakespeare')).toBeInTheDocument(); + }); + + it('shows collapse button when onToggleSidebar is provided', () => { + const mockToggle = vi.fn(); + + render( + + ); + + const collapseButton = screen.getByLabelText('Collapse sidebar'); + expect(collapseButton).toBeInTheDocument(); + + fireEvent.click(collapseButton); + expect(mockToggle).toHaveBeenCalledTimes(1); + }); + + it('does not show collapse button when onToggleSidebar is not provided', () => { + render( + + ); + + expect(screen.queryByLabelText('Collapse sidebar')).not.toBeInTheDocument(); + }); + + it('renders login area at the bottom', () => { + render( + + ); + + expect(screen.getByTestId('login-area')).toBeInTheDocument(); + }); + + it('shows new project button', () => { + render( + + ); + + expect(screen.getByText('New Project')).toBeInTheDocument(); + }); +}); \ No newline at end of file diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx index 43784ce6..0b8b62c6 100644 --- a/src/components/ProjectSidebar.tsx +++ b/src/components/ProjectSidebar.tsx @@ -1,6 +1,7 @@ import React, { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; -import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star } from 'lucide-react'; +import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2 } from 'lucide-react'; +import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; import { LoginArea } from '@/components/auth/LoginArea'; @@ -75,12 +76,14 @@ interface ProjectSidebarProps { selectedProject: Project | null; onSelectProject: (project: Project | null) => void; className?: string; + onToggleSidebar?: () => void; } export function ProjectSidebar({ selectedProject, onSelectProject, - className + className, + onToggleSidebar }: ProjectSidebarProps) { const queryClient = useQueryClient(); const { data: projects = [], isLoading, error } = useProjects(); @@ -115,6 +118,19 @@ export function ProjectSidebar({ Shakespeare + {onToggleSidebar && ( +
+ +
+ )}