| 1 | // Run: tsx src/__tests__/settings-navigation-contract.test.ts |
| 2 | |
| 3 | import { readFileSync } from "node:fs"; |
| 4 | import { dirname, resolve } from "node:path"; |
| 5 | import { fileURLToPath } from "node:url"; |
| 6 | |
| 7 | const testDir = dirname(fileURLToPath(import.meta.url)); |
| 8 | const panel = readFileSync(resolve(testDir, "../components/SettingsPanel.tsx"), "utf8"); |
| 9 | const navigation = readFileSync(resolve(testDir, "../components/SettingsNavigation.tsx"), "utf8"); |
| 10 | |
| 11 | let passed = 0; |
| 12 | let failed = 0; |
| 13 | |
| 14 | function ok(condition: boolean, label: string) { |
| 15 | if (condition) { |
| 16 | process.stdout.write(` PASS ${label}\n`); |
| 17 | passed += 1; |
| 18 | } else { |
| 19 | process.stdout.write(` FAIL ${label}\n`); |
| 20 | failed += 1; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | console.log("\nsettings navigation contract"); |
| 25 | |
| 26 | ok(!panel.includes("settings.desktopLayoutStyle"), "desktop settings no longer offer a layout-style switch"); |
| 27 | ok(!panel.includes('["workbench", "classic", "creation"] as const'), "desktop settings no longer offer classic"); |
| 28 | ok(/useEffect\(\(\) => \{[\s\S]*?content\.scrollTop = 0;[\s\S]*?content\.scrollLeft = 0;[\s\S]*?\}, \[tab\]\);/.test(panel), "switching settings pages resets both content scroll axes"); |
| 29 | ok(navigation.includes('aria-current={activeTab === id ? "page" : undefined}'), "the active settings page is exposed semantically"); |
| 30 | ok(navigation.includes('item.meta && query.trim()'), "navigation metadata appears only in search results"); |
| 31 | |
| 32 | ok(navigation.includes('tabs: ["models", "providers", "model-stats"]'), "model pages share one dedicated navigation group"); |
| 33 | ok(panel.includes('key="model-pages"'), "model page navigation retains shared editor ownership"); |
| 34 | ok(panel.includes('hidden={subtab !== "access"}'), "leaving model services hides rather than unmounts its drafts"); |
| 35 | ok(!panel.includes('setSubtab('), "model page routing has one navigation owner"); |
| 36 | |
| 37 | console.log(`\n${passed} passed, ${failed} failed, ${passed + failed} total`); |
| 38 | if (failed > 0) process.exit(1); |
| 39 |