Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

2.5 KB
Raw Blame
import { readSettingsSource } from "./helpers/source-contracts.mjs";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { loadStyles } from "./helpers/styles.mjs";

const rowSource = await readFile(
  new URL("../src/components/settings/LanguageRow.tsx", import.meta.url),
  "utf8",
);
const settingsPageSource = await readSettingsSource();
const styles = await loadStyles();

/** Grouped language/theme rules put a sibling selector before `{`. */
function pickerRule(selector, body = "") {
  const grouped = `${selector}[^{]*\\{`;
  return body ? new RegExp(`${grouped}[^}]*${body}`, "s") : new RegExp(grouped);
}

test("language picker uses an anchored menu so the settings card cannot clip it", () => {
  assert.match(rowSource, /AnchoredMenu/);
  assert.match(rowSource, /menuClassName="settings-language-menu"/);
  assert.match(styles, pickerRule("\\.settings-language-menu", "position:\\s*fixed;"));
  assert.match(styles, pickerRule("\\.settings-language-menu\\.is-open"));
});

test("language options come from the shipped locale registry, not a hard-coded trio of cards", () => {
  assert.match(rowSource, /listedLocales\(\)/);
  assert.match(rowSource, /id: "auto"/);
  assert.match(rowSource, /saveSettings\(\{ language: id \}\)/);
  assert.match(settingsPageSource, /<LanguageRow /);
  assert.doesNotMatch(settingsPageSource, /settings-theme-card[\s\S]*lang/);
  assert.doesNotMatch(settingsPageSource, /\(\["auto", "zh-CN", "en"\] as const\)/);
});

test("native language names stay in the registry rather than the catalog", () => {
  assert.match(rowSource, /locale\.nativeName/);
  assert.doesNotMatch(rowSource, /settings\.languageZh/);
  assert.doesNotMatch(rowSource, /settings\.languageEn/);
});

test("the Auto row shows the OS-detected native name", () => {
  assert.match(rowSource, /resolveAppLanguage\("auto"\)/);
  assert.match(rowSource, /settings\.languageAutoDesc/);
  assert.match(rowSource, /detectedInfo\.nativeName/);
  assert.doesNotMatch(rowSource, /autoLabel} · \$\{detectedInfo/);
});

test("the language trigger hugs the current label without a native field chrome", () => {
  assert.match(styles, pickerRule("\\.settings-language-anchor", "width:\\s*max-content;"));
  assert.match(styles, pickerRule("\\.settings-language-trigger", "width:\\s*max-content;"));
  assert.match(styles, pickerRule("\\.settings-language-search input", "outline:\\s*none;"));
  assert.match(styles, pickerRule("\\.settings-language-search input", "padding:\\s*0;"));
});