import { describe, expect, it } from "vitest";

import { keywordMatchesSearchResult } from "./search-hit-utils.js";

describe("keywordMatchesSearchResult", () => {
  it("matches Chinese keywords against raw card text when title extraction is incomplete", () => {
    expect(keywordMatchesSearchResult("球墨铸铁井盖", {
      title: "1688结果-1",
      rawCardText: "厂家直供 球墨铸铁井盖加工污水雨水井盖 球墨铸铁 1-80",
      highlightTexts: [],
    })).toBe(true);
  });

  it("matches mixed spec keywords after punctuation normalization", () => {
    expect(keywordMatchesSearchResult("球墨铸铁井盖 Φ700重型", {
      title: "球墨铸铁井盖φ700重型 市政道路井盖",
      rawCardText: "",
      highlightTexts: [],
    })).toBe(true);
  });

  it("uses highlighted fragments as hit evidence", () => {
    expect(keywordMatchesSearchResult("球墨铸铁井盖", {
      title: "圆形井盖井座加工",
      rawCardText: "圆形井盖井座加工",
      highlightTexts: ["球墨铸铁井盖"],
    })).toBe(true);
  });

  it("rejects unrelated titles", () => {
    expect(keywordMatchesSearchResult("球墨铸铁井盖", {
      title: "排水沟盖板下水道篦子",
      rawCardText: "雨水篦子 下水道沟盖板",
      highlightTexts: [],
    })).toBe(false);
  });
});