|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen, fireEvent } from '@testing-library/react'; |
| 3 | +import '@testing-library/jest-dom'; |
| 4 | +import App from '../src/App'; |
| 5 | + |
| 6 | +describe('App Component', () => { |
| 7 | + it('renders without crashing', () => { |
| 8 | + render(<App />); |
| 9 | + expect(screen.getByRole('button', { name: /dark mode/i })).toBeInTheDocument(); |
| 10 | + }); |
| 11 | + |
| 12 | + it('renders the MultiLevelTable component', () => { |
| 13 | + render(<App />); |
| 14 | + // Check for table headers |
| 15 | + expect(screen.getByText('Name')).toBeInTheDocument(); |
| 16 | + expect(screen.getByText('Value')).toBeInTheDocument(); |
| 17 | + expect(screen.getByText('Status')).toBeInTheDocument(); |
| 18 | + }); |
| 19 | + |
| 20 | + it('toggles theme when theme button is clicked', () => { |
| 21 | + render(<App />); |
| 22 | + const themeButton = screen.getByRole('button', { name: /dark mode/i }); |
| 23 | + const appDiv = screen.getByTestId('app-container'); |
| 24 | + |
| 25 | + // Initial state should be light theme |
| 26 | + expect(appDiv).toHaveStyle({ backgroundColor: '#ffffff' }); |
| 27 | + |
| 28 | + // Click to toggle to dark theme |
| 29 | + fireEvent.click(themeButton); |
| 30 | + expect(appDiv).toHaveStyle({ backgroundColor: '#212529' }); |
| 31 | + |
| 32 | + // Click again to toggle back to light theme |
| 33 | + fireEvent.click(themeButton); |
| 34 | + expect(appDiv).toHaveStyle({ backgroundColor: '#ffffff' }); |
| 35 | + }); |
| 36 | + |
| 37 | + it('renders parent items correctly', () => { |
| 38 | + render(<App />); |
| 39 | + // Check for some parent items |
| 40 | + expect(screen.getByText('Parent 1')).toBeInTheDocument(); |
| 41 | + expect(screen.getByText('Parent 2')).toBeInTheDocument(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('renders status cells with correct colors', () => { |
| 45 | + render(<App />); |
| 46 | + const activeStatus = screen.getAllByText('Active')[0]; |
| 47 | + const inactiveStatus = screen.getAllByText('Inactive')[0]; |
| 48 | + const pendingStatus = screen.getAllByText('Pending')[0]; |
| 49 | + |
| 50 | + expect(activeStatus).toHaveStyle({ color: '#2ecc71' }); |
| 51 | + expect(inactiveStatus).toHaveStyle({ color: '#e74c3c' }); |
| 52 | + expect(pendingStatus).toHaveStyle({ color: '#f1c40f' }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments