Files
Netcatty/domain/settingsSearchCatalog.anchors.test.ts
T
陈大猫 1d5cef09ec fix(settings): index later-added settings in search catalog (Fixes #4230) (#4232)
* fix(settings): index later-added settings in search catalog

Fixes #4230

Follow-up after #4231. Settings search still missed later-added
rows such as Appearance "Code font" (代码字体) and System session
log "Add timestamps" (时间戳), which already rendered in their
tabs. Index those destinations and other visible setting rows
that had the same catalog/anchor omission.

* fix(settings): fall back to visible parent when search target is gated
2026-11-14 21:30:27 +08:00

44 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict";
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import test from "node:test";
import { SETTINGS_SEARCH_CATALOG } from "./settingsSearchCatalog.ts";
function collectSourceFiles(root: string): string[] {
const out: string[] = [];
const walk = (dir: string) => {
for (const name of readdirSync(dir)) {
const full = join(dir, name);
const st = statSync(full);
if (st.isDirectory()) {
walk(full);
continue;
}
if (/\.(tsx|ts|jsx|js)$/.test(name) && !name.includes(".test.")) {
out.push(full);
}
}
};
walk(root);
return out;
}
test("every settings search catalog id and fallback is wired as an anchor in components", () => {
const roots = [
join(process.cwd(), "components"),
];
const sources = roots.flatMap((root) => collectSourceFiles(root));
const haystack = sources.map((file) => readFileSync(file, "utf8")).join("\n");
const missing = SETTINGS_SEARCH_CATALOG
.flatMap((entry) => [entry.id, ...(entry.fallbackAnchorId ? [entry.fallbackAnchorId] : [])])
.filter((id) => {
const asProp = `anchorId="${id}"`;
const asPropSingle = `anchorId='${id}'`;
return !haystack.includes(asProp) && !haystack.includes(asPropSingle);
});
assert.deepEqual(missing, [], `Missing anchors for: ${missing.join(", ")}`);
});