| 1 | import { existsSync } from "node:fs"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import { DOC_TOPICS, docTopicHref } from "./docs-map"; |
| 4 | import { DOC_TASKS, docTaskHaystack, taskTopic } from "./docs-tasks"; |
| 5 | import { getDocsShell, EN_DOCS_SHELL } from "./i18n/dictionaries"; |
| 6 | |
| 7 | const webRoot = new URL("../", import.meta.url); |
| 8 | |
| 9 | /** Locale-relative route → the app-router page that must exist for it. */ |
| 10 | function pageFileFor(href: string): string { |
| 11 | return `app/[locale]${href}/page.tsx`; |
| 12 | } |
| 13 | |
| 14 | describe("task-based docs index", () => { |
| 15 | it("points every task at a first-party page that exists", () => { |
| 16 | expect(DOC_TASKS.length).toBeGreaterThanOrEqual(12); |
| 17 | for (const task of DOC_TASKS) { |
| 18 | expect(task.href.startsWith("/"), `${task.id} href`).toBe(true); |
| 19 | expect(existsSync(new URL(pageFileFor(task.href), webRoot)), `${task.id}: ${task.href}`).toBe(true); |
| 20 | } |
| 21 | }); |
| 22 | |
| 23 | it("keeps ids unique and every task attached to a registered topic", () => { |
| 24 | const ids = DOC_TASKS.map((t) => t.id); |
| 25 | expect(new Set(ids).size).toBe(ids.length); |
| 26 | for (const task of DOC_TASKS) { |
| 27 | const topic = taskTopic(task); |
| 28 | expect(topic, `${task.id} → ${task.topicId}`).toBeDefined(); |
| 29 | // A task that lives on its topic's own page must agree with docs-map |
| 30 | // about that page's route, so the two registries cannot drift apart. |
| 31 | if (topic && topic.hasPage) { |
| 32 | expect(docTopicHref(topic, "en"), `${task.id} route`).toBe(`/en${task.href}`); |
| 33 | } |
| 34 | } |
| 35 | }); |
| 36 | |
| 37 | it("keeps labels, descriptions, and keywords bilingual", () => { |
| 38 | for (const task of DOC_TASKS) { |
| 39 | for (const pair of [task.label, task.description, task.keywords]) { |
| 40 | expect(pair.en.trim().length, `${task.id} en`).toBeGreaterThan(0); |
| 41 | expect(pair.zh.trim().length, `${task.id} zh`).toBeGreaterThan(0); |
| 42 | } |
| 43 | } |
| 44 | }); |
| 45 | |
| 46 | it("covers the PRD reference set: auth, computers, providers, trust, troubleshooting", () => { |
| 47 | const topicIds = new Set(DOC_TASKS.map((t) => t.topicId)); |
| 48 | for (const id of ["auth", "computers", "providers", "trust", "troubleshooting", "subagents"]) { |
| 49 | expect(topicIds.has(id), id).toBe(true); |
| 50 | expect(DOC_TOPICS.some((t) => t.id === id && t.hasPage), `${id} page`).toBe(true); |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | it("searches across both languages regardless of locale", () => { |
| 55 | const hay = DOC_TASKS.map(docTaskHaystack); |
| 56 | expect(hay.some((h) => h.includes("daytona"))).toBe(true); |
| 57 | expect(hay.some((h) => h.includes("云端"))).toBe(true); |
| 58 | expect(hay.some((h) => h.includes("/docs/trust"))).toBe(true); |
| 59 | }); |
| 60 | |
| 61 | it("keeps the hub search strings dictionary-driven with token parity", () => { |
| 62 | for (const locale of ["en", "zh", "ja", "und"]) { |
| 63 | const t = getDocsShell(locale); |
| 64 | expect(t.searchMatches).toContain("{matched}"); |
| 65 | expect(t.searchMatches).toContain("{total}"); |
| 66 | expect(t.searchMatches).toContain("{query}"); |
| 67 | expect(t.searchNoMatches).toContain("{query}"); |
| 68 | expect(t.helpSource).toContain("{name}"); |
| 69 | expect(t.releasePublished).toContain("{tag}"); |
| 70 | expect(t.releaseCandidate).toContain("{version}"); |
| 71 | } |
| 72 | expect(getDocsShell("zh").tasksHeading).not.toBe(EN_DOCS_SHELL.tasksHeading); |
| 73 | }); |
| 74 | }); |
| 75 |