import React from 'react'; import { render, screen, fireEvent } from '@testing-library/react'; import { BrowserRouter } from 'react-router-dom'; import { ThemeProvider } from '@mui/material/styles'; import Layout from '../Layout'; import { AuthProvider } from '../../contexts/AuthContext'; import theme from '../../theme'; import '@testing-library/jest-dom'; // Mock the useAuth hook const mockUser = { id: '1', ugaId: '811123456', firstName: 'John', lastName: 'Doe', email: 'john.doe@uga.edu', role: 'student', classification: 'Senior', major: 'Computer Science', college: 'Franklin College of Arts and Sciences', }; const mockAuthContext = { user: mockUser, isAuthenticated: true, isLoading: false, login: jest.fn(), loginWithMyID: jest.fn(), logout: jest.fn(), updateProfile: jest.fn(), }; jest.mock('../../contexts/AuthContext', () => ({ useAuth: () => mockAuthContext, })); const renderWithProviders = (children: React.ReactNode) => { return render( {children} ); }; describe('Layout Component', () => { test('renders navigation items for student', () => { renderWithProviders(
Test Content
); // Check if navigation items are present expect(screen.getByText('Dashboard')).toBeInTheDocument(); expect(screen.getByText('Chat')).toBeInTheDocument(); expect(screen.getByText('Student Services')).toBeInTheDocument(); expect(screen.getByText('Knowledge Base')).toBeInTheDocument(); expect(screen.getByText('Settings')).toBeInTheDocument(); // Faculty-specific items should not be present for students expect(screen.queryByText('Faculty Dashboard')).not.toBeInTheDocument(); }); test('renders user avatar with initials', () => { renderWithProviders(
Test Content
); // Check for user initials in avatar expect(screen.getByText('JD')).toBeInTheDocument(); }); test('opens profile menu when avatar is clicked', () => { renderWithProviders(
Test Content
); // Click on the user avatar const avatarButton = screen.getByLabelText('account of current user'); fireEvent.click(avatarButton); // Check if profile menu items appear expect(screen.getByText('John Doe')).toBeInTheDocument(); expect(screen.getByText('john.doe@uga.edu')).toBeInTheDocument(); expect(screen.getByText('Logout')).toBeInTheDocument(); }); test('renders mobile menu toggle', () => { renderWithProviders(
Test Content
); const menuButton = screen.getByLabelText('open drawer'); expect(menuButton).toBeInTheDocument(); }); test('renders children content', () => { renderWithProviders(
Test Content
); expect(screen.getByTestId('test-content')).toBeInTheDocument(); }); }); describe('Layout Component for Faculty', () => { beforeEach(() => { // Mock faculty user mockAuthContext.user = { ...mockUser, role: 'faculty', major: undefined, classification: undefined, }; }); test('renders faculty navigation items', () => { renderWithProviders(
Test Content
); // Faculty-specific items should be present expect(screen.getByText('Faculty Dashboard')).toBeInTheDocument(); expect(screen.getByText('Analytics')).toBeInTheDocument(); // Student-specific items should not be present expect(screen.queryByText('Student Services')).not.toBeInTheDocument(); }); });