diff --git a/client/src/components/modal/NamedChoiceModal.tsx b/client/src/components/modal/NamedChoiceModal.tsx index 0937e50513..d9c26a8fe5 100644 --- a/client/src/components/modal/NamedChoiceModal.tsx +++ b/client/src/components/modal/NamedChoiceModal.tsx @@ -239,6 +239,8 @@ function ButtonGrid({ data, typeKey }: { data: NamedChoice["data"]; typeKey: str return data.options.filter((option) => option.toLowerCase().includes(lower)); }, [showFilter, query, data.options]); + const isFiltering = showFilter && query.trim() !== ""; + return ( diff --git a/client/src/components/modal/__tests__/NamedChoiceModal.test.tsx b/client/src/components/modal/__tests__/NamedChoiceModal.test.tsx index 2be6af908b..1805d8eadb 100644 --- a/client/src/components/modal/__tests__/NamedChoiceModal.test.tsx +++ b/client/src/components/modal/__tests__/NamedChoiceModal.test.tsx @@ -4,6 +4,62 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import type { WaitingFor } from "../../../adapter/types.ts"; import { NamedChoiceModal } from "../NamedChoiceModal.tsx"; +vi.mock("../ChoiceOverlay.tsx", () => ({ + ChoiceOverlay: ({ + title, + children, + footer, + }: { + title: string; + children: React.ReactNode; + footer?: React.ReactNode; + }) => ( +
+

{title}

+ {children} + {footer} +
+ ), + ConfirmButton: ({ + onClick, + disabled, + label = "Confirm", + }: { + onClick?: () => void; + disabled?: boolean; + label?: string; + }) => ( + + ), +})); + +vi.mock("framer-motion", async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + motion: { + ...actual.motion, + button: ({ + children, + onClick, + className, + style, + }: { + children: React.ReactNode; + onClick?: () => void; + className?: string; + style?: React.CSSProperties; + }) => ( + + ), + }, + }; +}); + const dispatchMock = vi.fn(); vi.mock("../../../hooks/useGameDispatch.ts", () => ({ @@ -38,4 +94,36 @@ describe("NamedChoiceModal", () => { data: { choice: "Blue" }, }); }); + + it("shows filtered creature-type options immediately", () => { + const creatureTypes = [ + "Ape", + "Bear", + "Cat", + "Dog", + "Elf", + "Goblin", + "Human", + "Kithkin", + "Lizard", + "Merfolk", + "Naga", + "Orc", + "Sliver", + ]; + const data: NamedChoiceData = { + player: 0, + choice_type: "CreatureType", + options: creatureTypes, + }; + + render(); + + fireEvent.change(screen.getByPlaceholderText("Filter options..."), { + target: { value: "sliver" }, + }); + + expect(screen.getByRole("button", { name: "Sliver" })).toBeInTheDocument(); + expect(screen.queryByRole("button", { name: "Ape" })).not.toBeInTheDocument(); + }); });