Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

2.8 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { locales } from "@/i18n";
import azTranslation from "@/locales/az.json";
import enTranslation from "@/locales/en.json";
import heTranslation from "@/locales/he.json";
import { getLocaleSearchLabels, localeMatchesSearch, normalizeLocaleSearchText } from "@/utils/i18n";

const flattenTranslationKeys = (value: unknown, prefix = ""): string[] => {
  if (value && typeof value === "object" && !Array.isArray(value)) {
    return Object.entries(value).flatMap(([key, child]) => flattenTranslationKeys(child, prefix ? `${prefix}.${key}` : key));
  }

  return [prefix];
};

describe("locale search helpers", () => {
  it("normalizes case and diacritics for locale search", () => {
    expect(normalizeLocaleSearchText("Português")).toBe("portugues");
  });

  it("includes locale code, native name, and English name", () => {
    const labels = getLocaleSearchLabels("ja", "en");

    expect(labels).toContain("ja");
    expect(labels).toContain("日本語");
    expect(labels).toContain("Japanese");
  });

  it("matches by code, native display name, English display name, and accent-free text", () => {
    expect(localeMatchesSearch("pt-PT", "pt", "en")).toBe(true);
    expect(localeMatchesSearch("ja", "日本", "en")).toBe(true);
    expect(localeMatchesSearch("de", "german", "en")).toBe(true);
    expect(localeMatchesSearch("pt-PT", "portugues", "en")).toBe(true);
    expect(localeMatchesSearch("ja", "romanian", "en")).toBe(false);
  });

  it("includes Hebrew in the supported locale list", () => {
    expect(locales).toContain("he");
    expect(localeMatchesSearch("he", "hebrew", "en")).toBe(true);
  });

  it("keeps Hebrew keys within the current English catalog", () => {
    expect(flattenTranslationKeys(enTranslation).sort()).toEqual(expect.arrayContaining(flattenTranslationKeys(heTranslation).sort()));
    expect(heTranslation.setting).toHaveProperty("ai");
    expect(heTranslation.setting).toHaveProperty("notification");
    expect(heTranslation.auth).not.toHaveProperty("host-tip");
  });

  it("includes Azerbaijani in the supported locale list", () => {
    expect(locales).toContain("az");
    expect(localeMatchesSearch("az", "azerbaijani", "en")).toBe(true);
  });

  it("keeps the Azerbaijani catalog aligned with the English one", () => {
    expect(flattenTranslationKeys(azTranslation).sort()).toEqual(flattenTranslationKeys(enTranslation).sort());
  });

  it("uses future-oriented wording for expiring Hebrew links and tokens", () => {
    expect(heTranslation.memo.share["expires-on"]).toBe("יפוג תוקף בתאריך {{date}}");
    expect(heTranslation.setting["access-token"].expires).toBe("יפוג תוקף");
    expect(heTranslation.setting["access-token"]["guideline-expiration"]).toContain("שתוקפם יפוג");
  });
});