test: improve frontend test coverage (#163)

- Export DashboardPage helper functions for testability
- Add new test files: App, SharedSchedule, AppContext, UnsavedChangesContext, useUnsavedChangesWarning
- Expand existing test coverage for Auth, MedDetailModal, MobileEditModal, DashboardPage, MedicationsPage, PlannerPage, and more
- Add edge case and error handling tests across components, hooks, and pages
This commit is contained in:
Daniel Volz
2026-02-13 18:34:19 +01:00
committed by GitHub
parent 0b0472f2f5
commit 5c09f97cb3
24 changed files with 4482 additions and 45 deletions
@@ -38,6 +38,8 @@ describe("useMedications", () => {
result.current.loadMeds();
});
expect(result.current.loading).toBe(true);
await waitFor(() => {
expect(result.current.meds).toEqual(mockMeds);
});
@@ -108,6 +110,23 @@ describe("useMedications", () => {
expect(mockResetForm).toHaveBeenCalled();
});
it("still reloads medications when delete request fails", async () => {
(global.fetch as ReturnType<typeof vi.fn>)
.mockRejectedValueOnce(new Error("Delete failed"))
.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve([]) });
const mockResetForm = vi.fn();
const { result } = renderHook(() => useMedications());
await act(async () => {
await result.current.deleteMed(5, 5, mockResetForm);
});
expect(fetch).toHaveBeenCalledWith("/api/medications/5", { method: "DELETE", credentials: "include" });
expect(fetch).toHaveBeenCalledWith("/api/medications", { credentials: "include" });
expect(mockResetForm).toHaveBeenCalled();
});
it("does not call resetForm if editingId does not match", async () => {
(global.fetch as ReturnType<typeof vi.fn>)
.mockResolvedValueOnce({ ok: true })