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>
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { defaultForm, defaultBlister } from '../../hooks/useMedicationForm';
|
|
|
|
describe('defaultBlister', () => {
|
|
it('creates a blister with default values', () => {
|
|
const blister = defaultBlister();
|
|
expect(blister.usage).toBe('1');
|
|
expect(blister.every).toBe('1');
|
|
expect(blister.startDate).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
expect(blister.startTime).toMatch(/^\d{2}:\d{2}$/);
|
|
});
|
|
|
|
it('uses current date', () => {
|
|
const before = new Date();
|
|
const blister = defaultBlister();
|
|
const after = new Date();
|
|
|
|
// Date should be between before and after
|
|
const blisterDate = new Date(blister.startDate);
|
|
expect(blisterDate >= new Date(before.toISOString().slice(0, 10))).toBe(true);
|
|
expect(blisterDate <= new Date(after.toISOString().slice(0, 10) + 'T23:59:59')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('defaultForm', () => {
|
|
it('creates a form with default values', () => {
|
|
const form = defaultForm();
|
|
expect(form.name).toBe('');
|
|
expect(form.genericName).toBe('');
|
|
expect(form.takenBy).toEqual([]);
|
|
expect(form.packCount).toBe('1');
|
|
expect(form.blistersPerPack).toBe('1');
|
|
expect(form.pillsPerBlister).toBe('1');
|
|
expect(form.looseTablets).toBe('0');
|
|
expect(form.pillWeightMg).toBe('');
|
|
expect(form.expiryDate).toBe('');
|
|
expect(form.notes).toBe('');
|
|
expect(form.intakeRemindersEnabled).toBe(false);
|
|
expect(form.blisters).toHaveLength(1);
|
|
});
|
|
|
|
it('creates a blister in the form', () => {
|
|
const form = defaultForm();
|
|
expect(form.blisters).toHaveLength(1);
|
|
expect(form.blisters[0].usage).toBe('1');
|
|
expect(form.blisters[0].every).toBe('1');
|
|
});
|
|
|
|
it('creates independent forms', () => {
|
|
const form1 = defaultForm();
|
|
const form2 = defaultForm();
|
|
|
|
form1.name = 'Test';
|
|
expect(form2.name).toBe('');
|
|
});
|
|
|
|
it('creates independent blisters arrays', () => {
|
|
const form1 = defaultForm();
|
|
const form2 = defaultForm();
|
|
|
|
form1.blisters.push(defaultBlister());
|
|
expect(form2.blisters).toHaveLength(1);
|
|
});
|
|
|
|
it('creates independent takenBy arrays', () => {
|
|
const form1 = defaultForm();
|
|
const form2 = defaultForm();
|
|
|
|
form1.takenBy.push('John');
|
|
expect(form2.takenBy).toHaveLength(0);
|
|
});
|
|
});
|