AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { formatProviderOrdinal, isLegacyProviderDisplayName, trimAiText } from "./ai-provider-options.ts";
describe("AI provider display names", () => {
test("formats sequential Chinese provider names", () => {
expect([1, 2, 10, 11, 20, 21].map((position) => formatProviderOrdinal(position, "zh-CN")))
.toEqual(["一", "二", "十", "十一", "二十", "二十一"]);
expect(formatProviderOrdinal(2, "en-US")).toBe("2");
});
test("recognizes names generated by the legacy protocol defaults", () => {
expect(isLegacyProviderDisplayName("OpenAI-compatible", "openai-compatible")).toBe(true);
expect(isLegacyProviderDisplayName("OpenRouter", "openai-compatible")).toBe(false);
});
test("treats missing provider names as not legacy instead of throwing", () => {
expect(trimAiText(undefined)).toBe("");
expect(trimAiText(null)).toBe("");
expect(trimAiText(" custom ")).toBe("custom");
expect(isLegacyProviderDisplayName(undefined, "openai-compatible")).toBe(false);
expect(isLegacyProviderDisplayName(null, "anthropic")).toBe(false);
expect(isLegacyProviderDisplayName(" ", "google")).toBe(false);
});
});
describe("AI settings cards tolerate missing text fields", () => {
test("provider cards trim optional names and URLs through the shared helper", () => {
const providerCard = readFileSync(new URL("./AiProviderCard.tsx", import.meta.url), "utf8");
const modelCard = readFileSync(new URL("./AiModelCard.tsx", import.meta.url), "utf8");
expect(providerCard).toContain("saved.baseUrl ?? \"\"");
expect(providerCard).toContain("trimAiText(displayName)");
expect(providerCard).toContain("trimAiText(baseUrl)");
expect(modelCard).toContain("!item.displayName");
expect(modelCard).toContain("canAddProvider");
expect(modelCard).toContain("addDisabledReason");
expect(modelCard).toContain("savedCredentialsUnavailable");
expect(modelCard).not.toContain("aiStreamingTitle");
expect(modelCard).not.toContain("readAiStreamingPreference");
});
});