b7f52be4c9
CI / Run CI (push) Has been cancelled
CI / check-backend (push) Has been cancelled
CI / check-frontend (push) Has been cancelled
CI / tests (push) Has been cancelled
CI / e2e-tests (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { render } from '@testing-library/react';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
import Icon from '@/components/Icon';
|
|
|
|
describe('Icon component', () => {
|
|
it('renders icon with kebab-case name', () => {
|
|
const { container } = render(<Icon name="chevron-right" />);
|
|
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders icon with lowercase name', () => {
|
|
const { container } = render(<Icon name="plus" />);
|
|
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders icon with PascalCase name', () => {
|
|
const { container } = render(<Icon name="ChevronRight" />);
|
|
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders icon with all uppercase name', () => {
|
|
const { container } = render(<Icon name="PLUS" />);
|
|
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders icon with mixed case name', () => {
|
|
const { container } = render(<Icon name="ChEvRoN-rIgHt" />);
|
|
expect(container.querySelector('svg')).toBeInTheDocument();
|
|
});
|
|
|
|
it('returns null and warns for invalid icon name', () => {
|
|
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
const { container } = render(<Icon name="invalid-icon-name" />);
|
|
|
|
expect(container.firstChild).toBeNull();
|
|
expect(consoleSpy).toHaveBeenCalledWith(
|
|
'Icon "invalid-icon-name" not found in Lucide icons'
|
|
);
|
|
|
|
consoleSpy.mockRestore();
|
|
});
|
|
|
|
it('passes props to the icon component', () => {
|
|
const { container } = render(
|
|
<Icon name="home" size={24} color="red" className="test-class" />
|
|
);
|
|
const svg = container.querySelector('svg');
|
|
|
|
expect(svg).toBeInTheDocument();
|
|
expect(svg).toHaveClass('test-class');
|
|
});
|
|
});
|