| 1 | import { readFileSync } from "node:fs"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import { |
| 4 | buildBreadcrumbListJsonLd, |
| 5 | resolveDocsBreadcrumbs, |
| 6 | resolveDocsTopic, |
| 7 | } from "./docs-breadcrumbs"; |
| 8 | import { SITE_URL } from "./page-meta"; |
| 9 | |
| 10 | describe("docs breadcrumbs", () => { |
| 11 | it("stops the hub trail at Docs", () => { |
| 12 | expect(resolveDocsBreadcrumbs("en", "/en/docs")).toEqual([ |
| 13 | { name: "Home", href: "/en" }, |
| 14 | { name: "Docs" }, |
| 15 | ]); |
| 16 | expect(resolveDocsBreadcrumbs("zh", "/zh/docs/")).toEqual([ |
| 17 | { name: "首页", href: "/zh" }, |
| 18 | { name: "文档" }, |
| 19 | ]); |
| 20 | }); |
| 21 | |
| 22 | it("names the category and topic on a first-party docs page", () => { |
| 23 | expect(resolveDocsBreadcrumbs("en", "/en/docs/mcp")).toEqual([ |
| 24 | { name: "Home", href: "/en" }, |
| 25 | { name: "Docs", href: "/en/docs" }, |
| 26 | { name: "Extending" }, |
| 27 | { name: "MCP" }, |
| 28 | ]); |
| 29 | expect(resolveDocsBreadcrumbs("zh", "/zh/docs/modes/")).toEqual([ |
| 30 | { name: "首页", href: "/zh" }, |
| 31 | { name: "文档", href: "/zh/docs" }, |
| 32 | { name: "核心概念" }, |
| 33 | { name: "模式" }, |
| 34 | ]); |
| 35 | expect(resolveDocsTopic("en", "/en/docs/guide")?.id).toBe("guide"); |
| 36 | }); |
| 37 | |
| 38 | it("emits BreadcrumbList with absolute Home → Docs → topic URLs", () => { |
| 39 | const schema = buildBreadcrumbListJsonLd("en", "/en/docs/sandbox"); |
| 40 | expect(schema["@type"]).toBe("BreadcrumbList"); |
| 41 | expect(schema.itemListElement).toEqual([ |
| 42 | { |
| 43 | "@type": "ListItem", |
| 44 | position: 1, |
| 45 | name: "Home", |
| 46 | item: `${SITE_URL}/en`, |
| 47 | }, |
| 48 | { |
| 49 | "@type": "ListItem", |
| 50 | position: 2, |
| 51 | name: "Docs", |
| 52 | item: `${SITE_URL}/en/docs`, |
| 53 | }, |
| 54 | { |
| 55 | "@type": "ListItem", |
| 56 | position: 3, |
| 57 | name: "Sandbox & Approval", |
| 58 | item: `${SITE_URL}/en/docs/sandbox`, |
| 59 | }, |
| 60 | ]); |
| 61 | }); |
| 62 | |
| 63 | it("renders the trail from the docs shell", () => { |
| 64 | const layout = readFileSync(new URL("../app/[locale]/docs/layout.tsx", import.meta.url), "utf8"); |
| 65 | expect(layout).toContain("<DocsBreadcrumb locale={locale} />"); |
| 66 | expect(layout).toContain('import { DocsBreadcrumb } from "@/components/docs-breadcrumb"'); |
| 67 | }); |
| 68 | }); |
| 69 |