hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { foldSearchText, matchesSearch, searchMatchRanges } from "@/lib/search-text"; |
| 3 | |
| 4 | describe("foldSearchText", () => { |
| 5 | it("folds Turkish letters onto their ASCII shape", () => { |
| 6 | expect(foldSearchText("Öğretmen ŞİŞLİ çığ")).toBe("ogretmen sisli cig"); |
| 7 | }); |
| 8 | |
| 9 | it("folds the dotted capital I the way a Turkish reader expects", () => { |
| 10 | expect(foldSearchText("İSTANBUL")).toBe("istanbul"); |
| 11 | expect(foldSearchText("Iğdır")).toBe("igdir"); |
| 12 | }); |
| 13 | |
| 14 | it("drops combining marks it has no explicit rule for", () => { |
| 15 | expect(foldSearchText("José Núñez")).toBe("jose nunez"); |
| 16 | }); |
| 17 | |
| 18 | it("drops punctuation so a typed class matches the printed one", () => { |
| 19 | expect(foldSearchText("9-A")).toBe("9a"); |
| 20 | expect(foldSearchText("ali.veli_1")).toBe("aliveli1"); |
| 21 | }); |
| 22 | |
| 23 | it("treats empty input as an empty string", () => { |
| 24 | expect(foldSearchText(null)).toBe(""); |
| 25 | expect(foldSearchText(undefined)).toBe(""); |
| 26 | }); |
| 27 | }); |
| 28 | |
| 29 | describe("matchesSearch", () => { |
| 30 | it("matches across diacritics in both directions", () => { |
| 31 | expect(matchesSearch("ogretmen", "Öğretmen Ayşe")).toBe(true); |
| 32 | expect(matchesSearch("Öğretmen", "ogretmen ayse")).toBe(true); |
| 33 | }); |
| 34 | |
| 35 | it("requires every term but not their order", () => { |
| 36 | expect(matchesSearch("ayse 9a", "Ayşe Yılmaz", "9-A")).toBe(true); |
| 37 | expect(matchesSearch("9a ayse", "Ayşe Yılmaz", "9-A")).toBe(true); |
| 38 | expect(matchesSearch("ayse 10b", "Ayşe Yılmaz", "9-A")).toBe(false); |
| 39 | }); |
| 40 | |
| 41 | it("ignores stray whitespace and empty queries", () => { |
| 42 | expect(matchesSearch(" ", "anything")).toBe(true); |
| 43 | expect(matchesSearch(" ayse yilmaz ", "Ayşe Yılmaz")).toBe(true); |
| 44 | }); |
| 45 | |
| 46 | it("skips fields with no value instead of matching on them", () => { |
| 47 | expect(matchesSearch("ayse", null, undefined, "Ayşe")).toBe(true); |
| 48 | expect(matchesSearch("ayse", null, undefined)).toBe(false); |
| 49 | }); |
| 50 | }); |
| 51 | |
| 52 | describe("searchMatchRanges", () => { |
| 53 | it("keeps original offsets while folding Turkish letters", () => { |
| 54 | expect(searchMatchRanges("Öğretmen Ayşe", "ogretmen")).toEqual([{ start: 0, end: 8 }]); |
| 55 | }); |
| 56 | |
| 57 | it("returns every occurrence in reading order", () => { |
| 58 | expect(searchMatchRanges("Sınav bugün, sınav yarın", "sinav")).toEqual([ |
| 59 | { start: 0, end: 5 }, |
| 60 | { start: 13, end: 18 }, |
| 61 | ]); |
| 62 | }); |
| 63 | }); |