Feat/frontend tests (#62)

* 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>
This commit is contained in:
Daniel Volz
2026-01-22 10:25:11 +01:00
committed by GitHub
parent 8718311876
commit fd055a3a2a
36 changed files with 7602 additions and 3 deletions
@@ -0,0 +1,81 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import ExportModal from '../../components/ExportModal';
describe('ExportModal', () => {
const defaultProps = {
isOpen: true,
onClose: vi.fn(),
onExport: vi.fn(),
exporting: false
};
beforeEach(() => {
vi.clearAllMocks();
});
it('returns null when not open', () => {
const { container } = render(<ExportModal {...defaultProps} isOpen={false} />);
expect(container.firstChild).toBeNull();
});
it('renders when open', () => {
render(<ExportModal {...defaultProps} />);
expect(screen.getByText(/exportImport\.exportOptions/i)).toBeInTheDocument();
});
it('calls onClose when close button is clicked', () => {
render(<ExportModal {...defaultProps} />);
fireEvent.click(screen.getByText('×'));
expect(defaultProps.onClose).toHaveBeenCalled();
});
it('calls onClose when overlay is clicked', () => {
const { container } = render(<ExportModal {...defaultProps} />);
const overlay = container.querySelector('.modal-overlay');
fireEvent.click(overlay!);
expect(defaultProps.onClose).toHaveBeenCalled();
});
it('renders export options', () => {
const { container } = render(<ExportModal {...defaultProps} />);
// Should have action card buttons
const actionCards = container.querySelectorAll('.action-card');
expect(actionCards.length).toBe(2);
});
it('calls onExport with true when export with images button clicked', () => {
const { container } = render(<ExportModal {...defaultProps} />);
const actionCards = container.querySelectorAll('.action-card');
fireEvent.click(actionCards[0]);
expect(defaultProps.onClose).toHaveBeenCalled();
expect(defaultProps.onExport).toHaveBeenCalledWith(true);
});
it('calls onExport with false when export data only button clicked', () => {
const { container } = render(<ExportModal {...defaultProps} />);
const actionCards = container.querySelectorAll('.action-card');
fireEvent.click(actionCards[1]);
expect(defaultProps.onClose).toHaveBeenCalled();
expect(defaultProps.onExport).toHaveBeenCalledWith(false);
});
it('disables buttons when exporting', () => {
const { container } = render(<ExportModal {...defaultProps} exporting={true} />);
const actionCards = container.querySelectorAll('.action-card');
actionCards.forEach(card => {
expect(card).toBeDisabled();
});
});
it('renders cancel button', () => {
render(<ExportModal {...defaultProps} />);
expect(screen.getByText(/exportImport\.cancelButton/i)).toBeInTheDocument();
});
it('calls onClose when cancel button is clicked', () => {
render(<ExportModal {...defaultProps} />);
fireEvent.click(screen.getByText(/exportImport\.cancelButton/i));
expect(defaultProps.onClose).toHaveBeenCalled();
});
});