forked from cardosofelipe/fast-next-template
- Remove unused imports (fireEvent, IssueStatus) in issue component tests - Add E2E global type declarations for __TEST_AUTH_STORE__ - Fix toHaveAccessibleName assertion with regex pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
/**
|
|
* StatusWorkflow Component Tests
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { StatusWorkflow } from '@/features/issues/components/StatusWorkflow';
|
|
|
|
describe('StatusWorkflow', () => {
|
|
const mockOnStatusChange = jest.fn();
|
|
|
|
beforeEach(() => {
|
|
mockOnStatusChange.mockClear();
|
|
});
|
|
|
|
it('renders all status options', () => {
|
|
render(
|
|
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} />
|
|
);
|
|
|
|
expect(screen.getByText('Open')).toBeInTheDocument();
|
|
expect(screen.getByText('In Progress')).toBeInTheDocument();
|
|
expect(screen.getByText('In Review')).toBeInTheDocument();
|
|
expect(screen.getByText('Blocked')).toBeInTheDocument();
|
|
expect(screen.getByText('Done')).toBeInTheDocument();
|
|
expect(screen.getByText('Closed')).toBeInTheDocument();
|
|
});
|
|
|
|
it('highlights current status', () => {
|
|
render(
|
|
<StatusWorkflow currentStatus="in_progress" onStatusChange={mockOnStatusChange} />
|
|
);
|
|
|
|
const inProgressButton = screen.getByRole('radio', { name: /in progress/i });
|
|
expect(inProgressButton).toHaveAttribute('aria-checked', 'true');
|
|
});
|
|
|
|
it('calls onStatusChange when status is clicked', async () => {
|
|
const user = userEvent.setup();
|
|
render(
|
|
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} />
|
|
);
|
|
|
|
const inProgressButton = screen.getByRole('radio', { name: /in progress/i });
|
|
await user.click(inProgressButton);
|
|
|
|
expect(mockOnStatusChange).toHaveBeenCalledWith('in_progress');
|
|
});
|
|
|
|
it('disables status buttons when disabled prop is true', async () => {
|
|
const user = userEvent.setup();
|
|
render(
|
|
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} disabled />
|
|
);
|
|
|
|
const inProgressButton = screen.getByRole('radio', { name: /in progress/i });
|
|
expect(inProgressButton).toBeDisabled();
|
|
|
|
await user.click(inProgressButton);
|
|
expect(mockOnStatusChange).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('applies custom className', () => {
|
|
const { container } = render(
|
|
<StatusWorkflow
|
|
currentStatus="open"
|
|
onStatusChange={mockOnStatusChange}
|
|
className="custom-class"
|
|
/>
|
|
);
|
|
|
|
expect(container.firstChild).toHaveClass('custom-class');
|
|
});
|
|
|
|
it('has proper radiogroup role', () => {
|
|
render(
|
|
<StatusWorkflow currentStatus="open" onStatusChange={mockOnStatusChange} />
|
|
);
|
|
|
|
expect(screen.getByRole('radiogroup', { name: /issue status/i })).toBeInTheDocument();
|
|
});
|
|
});
|