diff --git a/__tests__/components/HelpModal.test.tsx b/__tests__/components/HelpModal.test.tsx new file mode 100644 index 0000000..633d127 --- /dev/null +++ b/__tests__/components/HelpModal.test.tsx @@ -0,0 +1,117 @@ +import { render, screen, fireEvent, act } from "@testing-library/react" +import HelpModal from "@/components/HelpModal" + +describe("HelpModal", () => { + it("should not render initially", () => { + render() + expect(screen.queryByText("Welcome to MirrorMatch")).not.toBeInTheDocument() + }) + + it("should open when Shift+? is pressed", () => { + render() + + // Simulate Shift+? (Shift+/) + act(() => { + fireEvent.keyDown(window, { + key: "/", + shiftKey: true, + ctrlKey: false, + metaKey: false, + }) + }) + + expect(screen.getByText("Welcome to MirrorMatch")).toBeInTheDocument() + }) + + it("should close when Escape is pressed", () => { + render() + + // Open modal first + act(() => { + fireEvent.keyDown(window, { + key: "/", + shiftKey: true, + ctrlKey: false, + metaKey: false, + }) + }) + + expect(screen.getByText("Welcome to MirrorMatch")).toBeInTheDocument() + + // Close with Escape + act(() => { + fireEvent.keyDown(window, { + key: "Escape", + }) + }) + + // Modal should close + expect(screen.queryByText("Welcome to MirrorMatch")).not.toBeInTheDocument() + }) + + it("should not open with Ctrl+? (should require Shift only)", () => { + render() + + // Simulate Ctrl+? (Ctrl+Shift+/) + act(() => { + fireEvent.keyDown(window, { + key: "/", + shiftKey: true, + ctrlKey: true, // Should prevent opening + metaKey: false, + }) + }) + + // Modal should not open when Ctrl is also pressed + expect(screen.queryByText("Welcome to MirrorMatch")).not.toBeInTheDocument() + }) + + it("should toggle when Shift+? is pressed multiple times", () => { + render() + + // First press - should open + act(() => { + fireEvent.keyDown(window, { + key: "/", + shiftKey: true, + ctrlKey: false, + metaKey: false, + }) + }) + + expect(screen.getByText("Welcome to MirrorMatch")).toBeInTheDocument() + + // Second press - should close + act(() => { + fireEvent.keyDown(window, { + key: "/", + shiftKey: true, + ctrlKey: false, + metaKey: false, + }) + }) + + expect(screen.queryByText("Welcome to MirrorMatch")).not.toBeInTheDocument() + }) + + it("should display help content when open", () => { + render() + + // Open modal + act(() => { + fireEvent.keyDown(window, { + key: "/", + shiftKey: true, + ctrlKey: false, + metaKey: false, + }) + }) + + // Check for key content sections + expect(screen.getByText("What is MirrorMatch?")).toBeInTheDocument() + expect(screen.getByText("How to Play")).toBeInTheDocument() + expect(screen.getByText("Key Features")).toBeInTheDocument() + expect(screen.getByText("Keyboard Shortcuts")).toBeInTheDocument() + expect(screen.getByText("Tips")).toBeInTheDocument() + }) +}) diff --git a/components/HelpModal.tsx b/components/HelpModal.tsx index 5a13006..bb30cf0 100644 --- a/components/HelpModal.tsx +++ b/components/HelpModal.tsx @@ -127,7 +127,7 @@ export default function HelpModal() {
  • Earn Points: Get points for each correct guess! The more you - guess correctly, the higher you'll climb on the leaderboard. + guess correctly, the higher you'll climb on the leaderboard.
  • Compete: Check the Leaderboard to see how you rank against other @@ -252,16 +252,16 @@ export default function HelpModal() {
    • 💡 - Guesses are case-insensitive, so don't worry about capitalization + Guesses are case-insensitive, so don't worry about capitalization
    • 💡 - You can't guess your own photos, but you can still view them + You can't guess your own photos, but you can still view them
    • 💡 - You'll receive email notifications when other users upload new photos + You'll receive email notifications when other users upload new photos