Files
medassist-ng/frontend/src/test/components/Lightbox.test.tsx
T
Daniel Volz 9a2d42b8b9 fix: stabilize dashboard modal and image click behavior (#267)
* feat: make medication names clickable in Dashboard dose schedule

Add click handlers to med-name-stack divs in all three dose schedule
sections (past, current/overdue, future) on DashboardPage, opening the
MedDetail modal on click.

Add early-return guards to all four modal openers in AppContext
(openMedDetail, openImageLightbox, openScheduleLightbox, openUserFilter)
to prevent duplicate pushState entries on double-click, which caused
unexpected navigation to the Medications page.

Closes #266

* fix: stabilize dashboard modal and image click handling

* fix: close medication detail on first backdrop click
2026-02-22 10:50:58 +01:00

76 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { Lightbox } from "../../components/Lightbox";
describe("Lightbox", () => {
const defaultProps = {
src: "/test-image.jpg",
alt: "Test Image",
onClose: vi.fn(),
};
beforeEach(() => {
vi.clearAllMocks();
});
it("renders image with correct src and alt", () => {
render(<Lightbox {...defaultProps} />);
const img = screen.getByAltText("Test Image");
expect(img).toBeInTheDocument();
expect(img).toHaveAttribute("src", "/test-image.jpg");
});
it("renders close button", () => {
render(<Lightbox {...defaultProps} />);
expect(screen.getByText("×")).toBeInTheDocument();
});
it("calls onClose when close button is clicked", () => {
const onClose = vi.fn();
render(<Lightbox {...defaultProps} onClose={onClose} />);
fireEvent.click(screen.getByText("×"));
expect(onClose).toHaveBeenCalled();
});
it("calls onClose when overlay is clicked", () => {
const onClose = vi.fn();
const { container } = render(<Lightbox {...defaultProps} onClose={onClose} />);
const overlay = container.querySelector(".lightbox-overlay");
fireEvent.click(overlay!);
expect(onClose).toHaveBeenCalled();
});
it("calls onClose when Escape key is pressed", () => {
const onClose = vi.fn();
const { container } = render(<Lightbox {...defaultProps} onClose={onClose} />);
const overlay = container.querySelector(".lightbox-overlay");
fireEvent.keyDown(overlay!, { key: "Escape" });
expect(onClose).toHaveBeenCalled();
});
it("does not call onClose when image is clicked", () => {
const onClose = vi.fn();
render(<Lightbox {...defaultProps} onClose={onClose} />);
fireEvent.click(screen.getByAltText("Test Image"));
expect(onClose).not.toHaveBeenCalled();
});
it("applies correct CSS classes", () => {
const { container } = render(<Lightbox {...defaultProps} />);
expect(container.querySelector(".lightbox-overlay")).toBeInTheDocument();
expect(container.querySelector(".lightbox-close")).toBeInTheDocument();
expect(container.querySelector(".lightbox-image")).toBeInTheDocument();
});
});