Files
medassist-ng/frontend/src/test/components/ProfileModal.test.tsx
T
Daniel Volz f36d56c523 test: update modal tests to reflect global ESC handler
Remove ESC-keydown tests from ProfileModal.test.tsx since the
useEscapeKey hook was removed from individual modals. Escape key
handling is now centralized in App.tsx's global handler, making
per-component ESC tests invalid (the component no longer responds
to ESC in isolation).
2026-02-25 23:54:21 +01:00

73 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 ProfileModal from "../../components/ProfileModal";
// Mock Auth UserProfile component
vi.mock("../../components/Auth", () => ({
UserProfile: ({ onClose: _onClose }: { onClose: () => void }) => (
<div data-testid="user-profile">User Profile Content</div>
),
}));
describe("ProfileModal", () => {
it("renders nothing when not open", () => {
const onClose = vi.fn();
render(<ProfileModal isOpen={false} onClose={onClose} />);
expect(screen.queryByTestId("user-profile")).not.toBeInTheDocument();
});
it("renders modal when open", () => {
const onClose = vi.fn();
render(<ProfileModal isOpen={true} onClose={onClose} />);
expect(screen.getByTestId("user-profile")).toBeInTheDocument();
});
it("renders close button", () => {
const onClose = vi.fn();
render(<ProfileModal isOpen={true} onClose={onClose} />);
const closeBtn = screen.getByText("×");
expect(closeBtn).toBeInTheDocument();
});
it("calls onClose when close button clicked", () => {
const onClose = vi.fn();
render(<ProfileModal isOpen={true} onClose={onClose} />);
const closeBtn = screen.getByText("×");
fireEvent.click(closeBtn);
expect(onClose).toHaveBeenCalledTimes(1);
});
it("calls onClose when overlay clicked", () => {
const onClose = vi.fn();
render(<ProfileModal isOpen={true} onClose={onClose} />);
const overlay = document.querySelector(".modal-overlay");
if (overlay) {
fireEvent.click(overlay);
}
expect(onClose).toHaveBeenCalledTimes(1);
});
it("does not call onClose when modal content clicked", () => {
const onClose = vi.fn();
render(<ProfileModal isOpen={true} onClose={onClose} />);
const content = document.querySelector(".modal-content");
if (content) {
fireEvent.click(content);
}
expect(onClose).not.toHaveBeenCalled();
});
// ESC key handling is tested at the App level — the global handler in
// App.tsx manages Escape for all modals, so per-component ESC tests are
// not applicable here.
});