|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { type Idol, type Group, search } from "@src/index"; |
| 3 | + |
| 4 | +describe("Fuzzy Search", () => { |
| 5 | + const testJapaneseName = "ステイシー"; |
| 6 | + |
| 7 | + test("should handle null company data", () => { |
| 8 | + const results = search("company"); |
| 9 | + expect(results).toBeDefined(); |
| 10 | + // Should not throw any errors |
| 11 | + }); |
| 12 | + |
| 13 | + test("should search by idol name", () => { |
| 14 | + const results = search("sumin"); |
| 15 | + expect(results.length).toBeGreaterThan(0); |
| 16 | + expect(results.some((r) => r.type === "idol")).toBe(true); |
| 17 | + }); |
| 18 | + |
| 19 | + test("should search by idol name + group", () => { |
| 20 | + const results = search("sumin stayc"); |
| 21 | + expect(results.length).toBeGreaterThan(0); |
| 22 | + expect( |
| 23 | + results.some( |
| 24 | + (r) => |
| 25 | + r.type === "idol" && |
| 26 | + (r.item as Idol).groups?.some((g) => g.name.toLowerCase().includes("fromis")), |
| 27 | + ), |
| 28 | + ).toBe(true); |
| 29 | + }); |
| 30 | + |
| 31 | + test("should search by group name", () => { |
| 32 | + const results = search("stayc"); |
| 33 | + expect(results.length).toBeGreaterThan(0); |
| 34 | + expect(results.some((r) => r.type === "group")).toBe(true); |
| 35 | + }); |
| 36 | + |
| 37 | + test("should handle Korean characters", () => { |
| 38 | + const results = search("스테이씨"); |
| 39 | + expect(results.length).toBeGreaterThan(0); |
| 40 | + }); |
| 41 | + |
| 42 | + test("should handle Japanese characters", () => { |
| 43 | + const results = search(testJapaneseName); |
| 44 | + expect(results.length).toBeGreaterThan(0); |
| 45 | + expect( |
| 46 | + results.some( |
| 47 | + (r) => |
| 48 | + r.type === "group" && |
| 49 | + (r.item as Group).groupInfo?.names?.stage |
| 50 | + ?.toLowerCase() |
| 51 | + .includes("twice"), |
| 52 | + ), |
| 53 | + ).toBe(true); |
| 54 | + }); |
| 55 | + |
| 56 | + test("should handle empty/null values", () => { |
| 57 | + expect(() => search("")).not.toThrow(); |
| 58 | + expect(() => search(" ")).not.toThrow(); |
| 59 | + }); |
| 60 | + |
| 61 | + test("should filter by type", () => { |
| 62 | + const idolResults = search("jin", { type: "idol" }); |
| 63 | + expect(idolResults.every((r) => r.type === "idol")).toBe(true); |
| 64 | + |
| 65 | + const groupResults = search("bts", { type: "group" }); |
| 66 | + expect(groupResults.every((r) => r.type === "group")).toBe(true); |
| 67 | + }); |
| 68 | +}); |
0 commit comments