import { describe, expect, it } from "vitest"; import { matchesCodeOrName } from "./codeOrNameSearch"; // unify-admin-listing-toolbar: "Code or name" search over rows already loaded (Reference data, // Catalogue setup). Part of the code or the name, ignoring case; a blank term matches everything. describe("matchesCodeOrName", () => { const row = { code: "MY", name: "Malaysia" }; it("matches part of the name or the code, ignoring case", () => { expect(matchesCodeOrName(row, "malay")).toBe(true); expect(matchesCodeOrName(row, "LAYS")).toBe(true); expect(matchesCodeOrName(row, "my")).toBe(true); expect(matchesCodeOrName(row, "sing")).toBe(false); }); it("matches everything for a blank or space-only term, and trims the term", () => { expect(matchesCodeOrName(row, "")).toBe(true); expect(matchesCodeOrName(row, " ")).toBe(true); expect(matchesCodeOrName(row, " malay ")).toBe(true); }); it("tolerates a missing name", () => { expect(matchesCodeOrName({ code: "Retail" }, "ret")).toBe(true); expect(matchesCodeOrName({ code: "Retail", name: null }, "x")).toBe(false); }); });