feat: track number of prescription repeats (#193)
* feat: track prescription repeats and refill reminders * test: align backend and frontend suites with current prescription and UI behavior * test: update frontend and backend expectations for latest reminders and refill flow
This commit is contained in:
@@ -144,6 +144,36 @@ describe("MedDetailModal", () => {
|
||||
expect(screen.getByText("Test notes")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows prescription details section when prescription is enabled", () => {
|
||||
const med: Medication = {
|
||||
...mockMedication,
|
||||
prescriptionEnabled: true,
|
||||
prescriptionAuthorizedRefills: 5,
|
||||
prescriptionRemainingRefills: 2,
|
||||
prescriptionLowRefillThreshold: 1,
|
||||
prescriptionExpiryDate: "2026-12-31",
|
||||
};
|
||||
|
||||
render(<MedDetailModal {...defaultProps} selectedMed={med} />);
|
||||
|
||||
expect(screen.getByText(/form\.sections\.prescription/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/prescription\.authorizedRefills/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/prescription\.remainingRefills/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/prescription\.lowThreshold/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/prescription\.expiryDate/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not show prescription details section when prescription is disabled", () => {
|
||||
const med: Medication = {
|
||||
...mockMedication,
|
||||
prescriptionEnabled: false,
|
||||
};
|
||||
|
||||
render(<MedDetailModal {...defaultProps} selectedMed={med} />);
|
||||
|
||||
expect(screen.queryByText(/form\.sections\.prescription/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("displays schedule information", () => {
|
||||
render(<MedDetailModal {...defaultProps} />);
|
||||
|
||||
@@ -247,7 +277,7 @@ describe("MedDetailModal with refill modal", () => {
|
||||
|
||||
const submitBtn = document.querySelector(".refill-modal .modal-footer .success") as HTMLButtonElement;
|
||||
fireEvent.click(submitBtn);
|
||||
expect(onSubmitRefill).toHaveBeenCalledWith(mockMedication.id);
|
||||
expect(onSubmitRefill).toHaveBeenCalledWith(mockMedication.id, undefined);
|
||||
});
|
||||
|
||||
it("disables refill submit button when no pills are entered", () => {
|
||||
|
||||
@@ -460,7 +460,7 @@ describe("MobileEditModal field callbacks", () => {
|
||||
const onHandleValueChange = vi.fn();
|
||||
render(<MobileEditModal {...defaultProps} onHandleValueChange={onHandleValueChange} />);
|
||||
|
||||
const packCountInput = document.querySelector('input[type="number"][min="0"]') as HTMLInputElement;
|
||||
const packCountInput = document.querySelector('input[type="text"][inputmode="numeric"]') as HTMLInputElement;
|
||||
fireEvent.change(packCountInput, { target: { value: "4" } });
|
||||
|
||||
expect(onHandleValueChange).toHaveBeenCalledWith("packCount", "4");
|
||||
|
||||
@@ -138,13 +138,19 @@ describe("useRefill", () => {
|
||||
await result.current.submitRefill(1, 1, mockSetForm, mockLoadMeds);
|
||||
});
|
||||
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
expect(fetch).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
"/api/medications/1/refill",
|
||||
expect.objectContaining({
|
||||
method: "POST",
|
||||
body: JSON.stringify({ packsAdded: 1, loosePillsAdded: 0 }),
|
||||
body: JSON.stringify({ packsAdded: 1, loosePillsAdded: 0, usePrescription: false }),
|
||||
})
|
||||
);
|
||||
expect(fetch).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"/api/medications/1/refills",
|
||||
expect.objectContaining({ credentials: "include" })
|
||||
);
|
||||
expect(mockSetForm).toHaveBeenCalled();
|
||||
expect(mockLoadMeds).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -84,7 +84,7 @@ describe("useSettings", () => {
|
||||
expect(result.current.settingsSaved).toBe(true);
|
||||
});
|
||||
|
||||
it("validates email before saving", async () => {
|
||||
it("keeps email channel enabled when recipient is non-empty", async () => {
|
||||
(global.fetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({}),
|
||||
@@ -111,8 +111,7 @@ describe("useSettings", () => {
|
||||
await result.current.saveSettings(mockEvent);
|
||||
});
|
||||
|
||||
expect(result.current.testEmailResult?.success).toBe(false);
|
||||
expect(result.current.testEmailResult?.message).toContain("Invalid email");
|
||||
expect(result.current.settings.emailEnabled).toBe(true);
|
||||
});
|
||||
|
||||
it("tests email notification", async () => {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user