/** * ScoringCard.test.tsx * Unit tests for the ScoringCard component */ import React from 'react'; import { render, screen } from '@testing-library/react'; import ScoringCard from '../../src/components/ScoringCard'; describe('ScoringCard Component', () => { it('should render all three stats', () => { render( ); // Check that all stat cards are rendered expect(screen.getByTestId('scoring-card-gold')).toBeInTheDocument(); expect(screen.getByTestId('scoring-card-quests')).toBeInTheDocument(); expect(screen.getByTestId('scoring-card-savings')).toBeInTheDocument(); }); it('should display correct gold value', () => { render( ); const goldSection = screen.getByTestId('scoring-card-gold'); expect(goldSection).toHaveTextContent('1250'); }); it('should display correct completed quests value', () => { render( ); const questsSection = screen.getByTestId('scoring-card-quests'); expect(questsSection).toHaveTextContent('42'); }); it('should display average savings as percentage', () => { render( ); const savingsSection = screen.getByTestId('scoring-card-savings'); expect(savingsSection).toHaveTextContent('23.46%'); }); it('should display dash when average savings is null', () => { render( ); const savingsSection = screen.getByTestId('scoring-card-savings'); expect(savingsSection).toHaveTextContent('—'); }); it('should display dash when average savings is undefined', () => { render( ); const savingsSection = screen.getByTestId('scoring-card-savings'); expect(savingsSection).toHaveTextContent('—'); }); it('should display all labels correctly', () => { render( ); expect(screen.getByText('Gold in Treasury')).toBeInTheDocument(); expect(screen.getByText('Quests Completed')).toBeInTheDocument(); expect(screen.getByText('Average Savings')).toBeInTheDocument(); }); it('should render the main scoring card container', () => { render( ); expect(screen.getByTestId('scoring-card')).toBeInTheDocument(); }); it('should display icons for each stat', () => { render( ); // Check that the scoring card is rendered and contains all three stat sections const scoringCard = screen.getByTestId('scoring-card'); expect(scoringCard).toBeInTheDocument(); // Verify all stat divs are present expect(screen.getByTestId('scoring-card-gold')).toBeInTheDocument(); expect(screen.getByTestId('scoring-card-quests')).toBeInTheDocument(); expect(screen.getByTestId('scoring-card-savings')).toBeInTheDocument(); }); it('should handle zero values', () => { render( ); const goldSection = screen.getByTestId('scoring-card-gold'); const questsSection = screen.getByTestId('scoring-card-quests'); const savingsSection = screen.getByTestId('scoring-card-savings'); expect(goldSection).toHaveTextContent('0'); expect(questsSection).toHaveTextContent('0'); expect(savingsSection).toHaveTextContent('0.00%'); }); it('should handle large values', () => { render( ); const goldSection = screen.getByTestId('scoring-card-gold'); const questsSection = screen.getByTestId('scoring-card-quests'); const savingsSection = screen.getByTestId('scoring-card-savings'); expect(goldSection).toHaveTextContent('999999'); expect(questsSection).toHaveTextContent('9999'); expect(savingsSection).toHaveTextContent('99.99%'); }); });