veza/apps/web/src/components/ui/Toast.test.tsx
senke 3fb12b2ce2 aesthetic-improvements: automated replacement of decorative cyan with steel (80/20 rule, Action 11.3.1.3)
- Created automated script (scripts/replace-decorative-cyan.py) to systematically replace decorative/informational kodo-cyan instances with kodo-steel variants
- Script intelligently preserves active/functional states, design system variants, semantic indicators, and interactive states
- Modified 85 files, replaced 145 decorative instances, preserved 47 functional instances
- No linter errors, type safety maintained
- Action 11.3.1.3 significantly advanced (total: ~302 instances replaced across ~229 files including previous batches)
2026-01-16 11:40:13 +01:00

87 lines
2.4 KiB
TypeScript

import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { Toast } from './Toast';
describe('Toast Component', () => {
const mockOnClose = vi.fn();
beforeEach(() => {
vi.clearAllMocks();
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it('renders toast with message', () => {
render(
<Toast id="1" type="info" message="Test message" onClose={mockOnClose} />,
);
expect(screen.getByText('Test message')).toBeInTheDocument();
});
it('renders success toast', () => {
render(
<Toast id="1" type="success" message="Success!" onClose={mockOnClose} />,
);
expect(screen.getByText('Success!')).toBeInTheDocument();
});
it('renders error toast', () => {
render(
<Toast id="1" type="error" message="Error!" onClose={mockOnClose} />,
);
expect(screen.getByText('Error!')).toBeInTheDocument();
});
it('calls onClose when close button is clicked', () => {
render(<Toast id="1" type="info" message="Test" onClose={mockOnClose} />);
const closeButton = screen.getByRole('button');
fireEvent.click(closeButton);
expect(mockOnClose).toHaveBeenCalledWith('1');
});
it('calls onClose automatically after 4 seconds', async () => {
render(<Toast id="1" type="info" message="Test" onClose={mockOnClose} />);
vi.advanceTimersByTime(4000);
// With fake timers, we need to flush pending timers
await vi.runAllTimersAsync();
expect(mockOnClose).toHaveBeenCalledWith('1');
});
it('applies correct styles for success variant', () => {
const { container } = render(
<Toast id="1" type="success" message="Test" onClose={mockOnClose} />,
);
const toast = container.firstChild as HTMLElement;
expect(toast.className).toContain('border-kodo-lime');
});
it('applies correct styles for error variant', () => {
const { container } = render(
<Toast id="1" type="error" message="Test" onClose={mockOnClose} />,
);
const toast = container.firstChild as HTMLElement;
expect(toast.className).toContain('border-kodo-red');
});
it('applies correct styles for info variant', () => {
const { container } = render(
<Toast id="1" type="info" message="Test" onClose={mockOnClose} />,
);
const toast = container.firstChild as HTMLElement;
expect(toast.className).toContain('border-kodo-steel');
});
});