fd055a3a2a
* test(frontend): add vitest test infrastructure - Add vitest, testing-library, jsdom dependencies - Configure vitest with jsdom environment - Add test setup with mocks for fetch, localStorage, matchMedia - Set 75% coverage threshold * Add frontend tests (#61) * Initial plan * Add frontend tests - utilities, hooks, and components (21% coverage) Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Add more component tests (Auth, AboutModal, ExportModal) and useRefill hook tests - 30% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Add useMedicationForm utility function tests - 30% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Add AppHeader tests and more schedule.ts tests - 32% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Changes before error encountered Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Fix page tests and add more tests - 326 tests passing, 34% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Add tests for ProfileModal, UserFilterModal, MedDetailModal - 361 tests, 36% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Add SharedSchedule tests - 366 tests, 39% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Expand page tests - 383 tests, 39% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Add MobileEditModal tests - 409 tests, 40% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Expand Dashboard and Schedule page tests - 427 tests, 40% coverage Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> * Fix code review issues - remove invalid remindEnabled property Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
||
import { render, screen, fireEvent } from '@testing-library/react';
|
||
import { Lightbox } from '../../components/Lightbox';
|
||
|
||
describe('Lightbox', () => {
|
||
const defaultProps = {
|
||
src: '/test-image.jpg',
|
||
alt: 'Test Image',
|
||
onClose: vi.fn()
|
||
};
|
||
|
||
beforeEach(() => {
|
||
vi.clearAllMocks();
|
||
});
|
||
|
||
it('renders image with correct src and alt', () => {
|
||
render(<Lightbox {...defaultProps} />);
|
||
|
||
const img = screen.getByAltText('Test Image');
|
||
expect(img).toBeInTheDocument();
|
||
expect(img).toHaveAttribute('src', '/test-image.jpg');
|
||
});
|
||
|
||
it('renders close button', () => {
|
||
render(<Lightbox {...defaultProps} />);
|
||
|
||
expect(screen.getByText('×')).toBeInTheDocument();
|
||
});
|
||
|
||
it('calls onClose when close button is clicked', () => {
|
||
const onClose = vi.fn();
|
||
render(<Lightbox {...defaultProps} onClose={onClose} />);
|
||
|
||
fireEvent.click(screen.getByText('×'));
|
||
|
||
expect(onClose).toHaveBeenCalled();
|
||
});
|
||
|
||
it('calls onClose when overlay is clicked', () => {
|
||
const onClose = vi.fn();
|
||
const { container } = render(<Lightbox {...defaultProps} onClose={onClose} />);
|
||
|
||
const overlay = container.querySelector('.lightbox-overlay');
|
||
fireEvent.click(overlay!);
|
||
|
||
expect(onClose).toHaveBeenCalled();
|
||
});
|
||
|
||
it('does not call onClose when image is clicked', () => {
|
||
const onClose = vi.fn();
|
||
render(<Lightbox {...defaultProps} onClose={onClose} />);
|
||
|
||
fireEvent.click(screen.getByAltText('Test Image'));
|
||
|
||
expect(onClose).not.toHaveBeenCalled();
|
||
});
|
||
|
||
it('applies correct CSS classes', () => {
|
||
const { container } = render(<Lightbox {...defaultProps} />);
|
||
|
||
expect(container.querySelector('.lightbox-overlay')).toBeInTheDocument();
|
||
expect(container.querySelector('.lightbox-close')).toBeInTheDocument();
|
||
expect(container.querySelector('.lightbox-image')).toBeInTheDocument();
|
||
});
|
||
});
|