Files
multica/packages/views/editor/extensions/pinyin-match.test.ts
LinYushen c628958fdd feat: support pinyin search in @mention suggestions (#2572)
* feat: support pinyin search in @mention suggestions

Add pinyin matching for Chinese names in the mention suggestion popup.
Users can now search by:
- Full pinyin: 'liyunlong' matches '李云龙'
- Initial letters: 'lyl' matches '李云龙'
- Partial/hybrid: 'liyu' or 'liyunl' matches '李云龙'

Implementation:
- New pinyin-match.ts utility using pinyin-pro library
- Integrated into member, agent, and squad filters in mention-suggestion.tsx
- 21 tests passing (9 unit + 12 integration)

Co-authored-by: multica-agent <github@multica.ai>

* fix: normalize ü→v in pinyin matching for names like 吕布

Enable pinyin-pro's v:true option so 吕→lv instead of lü.
Add test case for 吕布/lvbu matching.

Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: multica-agent <github@multica.ai>
2026-05-14 12:44:43 +08:00

50 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { matchesPinyin } from "./pinyin-match";
describe("matchesPinyin", () => {
it("matches full pinyin", () => {
expect(matchesPinyin("李云龙", "liyunlong")).toBe(true);
});
it("matches pinyin initials", () => {
expect(matchesPinyin("李云龙", "lyl")).toBe(true);
});
it("matches partial pinyin prefix", () => {
expect(matchesPinyin("李云龙", "liyu")).toBe(true);
});
it("matches hybrid pinyin (full + initials)", () => {
expect(matchesPinyin("李云龙", "liyunl")).toBe(true);
});
it("does not match unrelated query", () => {
expect(matchesPinyin("李云龙", "zhangsan")).toBe(false);
});
it("returns false for non-Chinese names", () => {
expect(matchesPinyin("Alice", "ali")).toBe(false);
});
it("returns true for empty query", () => {
expect(matchesPinyin("李云龙", "")).toBe(true);
});
it("matches single character pinyin", () => {
expect(matchesPinyin("张大彪", "z")).toBe(true);
expect(matchesPinyin("张大彪", "zdb")).toBe(true);
expect(matchesPinyin("张大彪", "zhangdabiao")).toBe(true);
});
it("matches mixed Chinese/English names", () => {
expect(matchesPinyin("魏和尚", "whs")).toBe(true);
expect(matchesPinyin("魏和尚", "weiheshang")).toBe(true);
});
it("normalizes ü to v for names like 吕布", () => {
expect(matchesPinyin("吕布", "lvbu")).toBe(true);
expect(matchesPinyin("吕布", "lb")).toBe(true);
expect(matchesPinyin("吕布", "lv")).toBe(true);
});
});