import { describe, it, expect } from "vitest"; import { render, screen, fireEvent } from "@testing-library/react"; import { Command, CommandInput, CommandList, CommandItem } from "./command"; const HAM = "Hamilton Backpack For Cabrio Car Seat HAM-001"; const ISA = "Isa Uchi Hands Free Breast Pump Bra YELLOW-001"; const MOM = "Momcozy Official Washing Block MOM-001"; function setup(props: React.ComponentProps = {}) { render( {HAM} {ISA} {MOM} , ); } const type = (v: string) => fireEvent.change(screen.getByPlaceholderText("search"), { target: { value: v } }); describe("Command default filter", () => { it("typing a SKU renders only the item containing it", () => { setup(); type("HAM-001"); expect(screen.getByText(HAM)).toBeInTheDocument(); expect(screen.queryByText(ISA)).not.toBeInTheDocument(); expect(screen.queryByText(MOM)).not.toBeInTheDocument(); }); it("ignores surrounding spaces in the search", () => { setup(); type(" HAM-001 "); expect(screen.getByText(HAM)).toBeInTheDocument(); expect(screen.queryByText(ISA)).not.toBeInTheDocument(); expect(screen.queryByText(MOM)).not.toBeInTheDocument(); }); it("matches case-insensitively", () => { setup(); type("ham"); expect(screen.getByText(HAM)).toBeInTheDocument(); expect(screen.queryByText(ISA)).not.toBeInTheDocument(); }); it("an explicit filter prop still wins", () => { setup({ filter: (value: string) => (value.includes("MOM-001") ? 1 : 0) }); type("anything"); expect(screen.getByText(MOM)).toBeInTheDocument(); expect(screen.queryByText(HAM)).not.toBeInTheDocument(); }); });