Spaces:
Sleeping
Sleeping
Download frontend-backup/src/components/__tests__/Layout.test.tsx from edichat/edi.chat.test: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/frontend-backup/src/components/__tests__/Layout.test.tsx
- Command line
-
hf download hf://spaces/edichat/edi.chat.test/frontend-backup/src/components/__tests__/Layout.test.tsx
-
curl -L -o Layout.test.tsx https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/frontend-backup/src/components/__tests__/Layout.test.tsx
3.88 kB
| 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( | |
| <BrowserRouter> | |
| <ThemeProvider theme={theme}> | |
| <AuthProvider> | |
| {children} | |
| </AuthProvider> | |
| </ThemeProvider> | |
| </BrowserRouter> | |
| ); | |
| }; | |
| describe('Layout Component', () => { | |
| test('renders navigation items for student', () => { | |
| renderWithProviders( | |
| <Layout> | |
| <div>Test Content</div> | |
| </Layout> | |
| ); | |
| // 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( | |
| <Layout> | |
| <div>Test Content</div> | |
| </Layout> | |
| ); | |
| // Check for user initials in avatar | |
| expect(screen.getByText('JD')).toBeInTheDocument(); | |
| }); | |
| test('opens profile menu when avatar is clicked', () => { | |
| renderWithProviders( | |
| <Layout> | |
| <div>Test Content</div> | |
| </Layout> | |
| ); | |
| // 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( | |
| <Layout> | |
| <div>Test Content</div> | |
| </Layout> | |
| ); | |
| const menuButton = screen.getByLabelText('open drawer'); | |
| expect(menuButton).toBeInTheDocument(); | |
| }); | |
| test('renders children content', () => { | |
| renderWithProviders( | |
| <Layout> | |
| <div data-testid="test-content">Test Content</div> | |
| </Layout> | |
| ); | |
| 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( | |
| <Layout> | |
| <div>Test Content</div> | |
| </Layout> | |
| ); | |
| // 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(); | |
| }); | |
| }); |