feat: close modals with browser back button on mobile (#257)
* feat: close modals with browser back button on mobile Create reusable useModalHistory hook that pushes history state when a modal opens and listens for popstate to close it. Apply to ReportModal, ClearMissedConfirm, ExportModal, ImportConfirm, and all modals using ConfirmModal/ShareDialog/Auth/ExportModal base components. Escape key handling was already in place for desktop. Closes #253 * fix: update tests for renamed button labels and missing useModalHistory mock
This commit is contained in:
@@ -556,7 +556,7 @@ describe("UserProfile", () => {
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
const cancelBtn = screen.getByText(/common\.cancel/i);
|
||||
const cancelBtn = screen.getByText(/common\.close/i);
|
||||
fireEvent.click(cancelBtn);
|
||||
});
|
||||
|
||||
|
||||
@@ -70,12 +70,12 @@ describe("ExportModal", () => {
|
||||
|
||||
it("renders cancel button", () => {
|
||||
render(<ExportModal {...defaultProps} />);
|
||||
expect(screen.getByText(/exportImport\.cancelButton/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/common\.close/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calls onClose when cancel button is clicked", () => {
|
||||
render(<ExportModal {...defaultProps} />);
|
||||
fireEvent.click(screen.getByText(/exportImport\.cancelButton/i));
|
||||
fireEvent.click(screen.getByText(/common\.close/i));
|
||||
expect(defaultProps.onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ describe("ReportModal", () => {
|
||||
render(<ReportModal isOpen={true} onClose={onClose} medications={[createMedication()]} />);
|
||||
|
||||
expect(screen.getByText(/report\.title/i)).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: /common\.cancel/i }));
|
||||
fireEvent.click(screen.getByRole("button", { name: /common\.close/i }));
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ describe("ShareDialog", () => {
|
||||
|
||||
it("calls onClose when close button is clicked", () => {
|
||||
render(<ShareDialog {...defaultProps} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: /common\.close/i }));
|
||||
const closeButtons = screen.getAllByRole("button", { name: /common\.close/i });
|
||||
fireEvent.click(closeButtons[closeButtons.length - 1]);
|
||||
expect(defaultProps.onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user