Files
OmniRoute/tests/unit/turkishText.test.ts
Oğuzhan Sert 8dc93ade6d fix(i18n): Turkish locale-aware search and sorting (#3115)
* feat(i18n): add Turkish locale-aware text helpers (search/sort)

* test(i18n): cover null/whitespace edges + document compareTr/normalize contract

* fix(i18n): route dashboard search through Turkish-safe matchesSearch

* fix(i18n): sort user-visible lists with Turkish collation (compareTr)

* fix(i18n): keep providerId tiebreaker as ASCII sort (technical id)

* docs(i18n): document intentional lang=en in global-error boundary

* chore(lint): guard against locale-unsafe toLowerCase().includes search

* fix(i18n): migrate missed provider-name search + harden lint disable placement

* fix(i18n): downgrade no-restricted-syntax to warn (incremental adoption)

The rule errored on ~19 pre-existing toLowerCase().includes() call-sites in
src/app accumulated since this PR's base. Keep it as a warning so the guard-rail
guides future code without breaking the 0-errors lint gate (project policy:
0 errors, warnings tolerated).

---------

Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
2026-06-03 18:58:01 -03:00

76 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from "node:test";
import assert from "node:assert/strict";
import {
normalizeForSearch,
matchesSearch,
compareTr,
} from "../../src/shared/utils/turkishText.ts";
test("normalizeForSearch: İ combining-dot üretmez (i'ye katlanır)", () => {
const out = normalizeForSearch("İ");
assert.equal(out, "i");
assert.ok(!out.includes("̇"), "combining dot above bulunmamalı");
});
test("normalizeForSearch: I (dotless) → i", () => {
assert.equal(normalizeForSearch("IĞDIR"), "igdir");
});
test("normalizeForSearch: aksanları katlar (şğüöç)", () => {
assert.equal(normalizeForSearch("Şarj Çözüm Güven"), "sarj cozum guven");
});
test("matchesSearch: İstanbul'u 'istanbul' sorgusuyla bulur", () => {
assert.equal(matchesSearch("İstanbul", "istanbul"), true);
});
test("matchesSearch: Latin 'Istanbul' sorgusu (noktasız I) dotted İ metnini bulur", () => {
// Real-world: data has the dotted Turkish İ, the user types a Latin capital I
// (no dot) from a non-Turkish keyboard. Both must fold to "istanbul".
assert.equal(matchesSearch("İstanbul", "Istanbul"), true);
assert.equal(matchesSearch("Istanbul", "İstanbul"), true);
});
test("matchesSearch: aksan-duyarsız (Şarj İstasyonu ↔ 'sarj')", () => {
assert.equal(matchesSearch("Şarj İstasyonu", "sarj"), true);
});
test("matchesSearch: eşleşmeyen sorgu false döner", () => {
assert.equal(matchesSearch("OpenAI", "anthropic"), false);
});
test("matchesSearch: boş sorgu her şeyi eşler", () => {
assert.equal(matchesSearch("herhangi", ""), true);
});
test("compareTr: Türkçe alfabede ç, c'den sonra gelir", () => {
assert.deepEqual(["d", "ç", "c", "b"].sort(compareTr), ["b", "c", "ç", "d"]);
});
test("compareTr: ı, i'den önce gelir (Türkçe)", () => {
assert.equal(compareTr("ı", "i") < 0, true);
});
test("compareTr: sayısal-duyarlı (item2 < item10)", () => {
assert.equal(compareTr("item2", "item10") < 0, true);
});
test("normalizeForSearch: null/undefined boş string döner", () => {
assert.equal(normalizeForSearch(null), "");
assert.equal(normalizeForSearch(undefined), "");
});
test("normalizeForSearch: yalnızca boşluk → boş string", () => {
assert.equal(normalizeForSearch(" "), "");
});
test("matchesSearch: yalnızca boşluk sorgusu her şeyi eşler", () => {
assert.equal(matchesSearch("herhangi", " "), true);
});
test("compareTr: null/undefined argümanları güvenli (?? '' guard)", () => {
assert.equal(compareTr(null, "a") < 0, true);
assert.equal(compareTr("a", null) > 0, true);
assert.equal(compareTr(null, undefined), 0);
});