Files
fast-next-template/frontend/tests/features/issues/components/StatusBadge.test.tsx
Felipe Cardoso 5c35702caf test(frontend): comprehensive test coverage improvements and bug fixes
- Raise coverage thresholds to 90% statements/lines/functions, 85% branches
- Add comprehensive tests for ProjectDashboard, ProjectWizard, and all wizard steps
- Add tests for issue management: IssueDetailPanel, BulkActions, IssueFilters
- Expand IssueTable tests with keyboard navigation, dropdown menu, edge cases
- Add useIssues hook tests covering all mutations and optimistic updates
- Expand eventStore tests with selector hooks and additional scenarios
- Expand useProjectEvents tests with error recovery, ping events, edge cases
- Add PriorityBadge, StatusBadge, SyncStatusIndicator fallback branch tests
- Add constants.test.ts for comprehensive constant validation

Bug fixes:
- Fix false positive rollback test to properly verify onMutate context setup
- Replace deprecated substr() with substring() in mock helpers
- Fix type errors: ProjectComplexity, ClientMode enum values
- Fix unused imports and variables across test files
- Fix @ts-expect-error directives and method override signatures

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 19:53:41 +01:00

72 lines
2.5 KiB
TypeScript

/**
* StatusBadge Component Tests
*/
import { render, screen } from '@testing-library/react';
import { StatusBadge } from '@/features/issues/components/StatusBadge';
import type { IssueStatus } from '@/features/issues/types';
const statusLabels: Record<IssueStatus, string> = {
open: 'Open',
in_progress: 'In Progress',
in_review: 'In Review',
blocked: 'Blocked',
closed: 'Closed',
};
describe('StatusBadge', () => {
const statuses: IssueStatus[] = ['open', 'in_progress', 'in_review', 'blocked', 'closed'];
it.each(statuses)('renders %s status correctly', (status) => {
render(<StatusBadge status={status} />);
// Check that the status text is present - use getAllByText since we have both visible and sr-only
const elements = screen.getAllByText(statusLabels[status]);
expect(elements.length).toBeGreaterThanOrEqual(1);
});
it('hides label when showLabel is false', () => {
render(<StatusBadge status="open" showLabel={false} />);
// The sr-only text should still be present
expect(screen.getByText('Open')).toHaveClass('sr-only');
});
it('applies custom className', () => {
const { container } = render(<StatusBadge status="open" className="custom-class" />);
const wrapper = container.firstChild;
expect(wrapper).toHaveClass('custom-class');
});
it('renders with accessible label', () => {
render(<StatusBadge status="open" showLabel={false} />);
// Should have sr-only text for screen readers
expect(screen.getByText('Open')).toBeInTheDocument();
});
it('falls back to open config for unknown status', () => {
// @ts-expect-error - Testing unknown status value
render(<StatusBadge status="unknown-status" />);
// Should fall back to open config (includes CircleDot icon as default)
const elements = screen.getAllByText('Open');
expect(elements.length).toBeGreaterThanOrEqual(1);
});
it('renders done status correctly', () => {
// Test the 'done' status which has a valid icon mapping
// but STATUS_CONFIG doesn't have 'done', so it falls back to 'open'
// @ts-expect-error - Testing done status (valid icon, fallback config)
const { container } = render(<StatusBadge status="done" />);
// Should have an SVG icon rendered (CheckCircle2 for done)
const svg = container.querySelector('svg');
expect(svg).toBeInTheDocument();
// Config falls back to open, so label shows "Open"
expect(screen.getAllByText('Open').length).toBeGreaterThan(0);
});
});