| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { DOC_TOPICS, docTopicHref, docTopicIsExternal } from "./docs-map"; |
| 3 | import { docsTopicIsCurrent } from "./docs-navigation"; |
| 4 | |
| 5 | function topic(id: string) { |
| 6 | const value = DOC_TOPICS.find((candidate) => candidate.id === id); |
| 7 | if (!value) throw new Error(`missing test topic: ${id}`); |
| 8 | return value; |
| 9 | } |
| 10 | |
| 11 | describe("docsTopicIsCurrent", () => { |
| 12 | it("marks a dedicated docs page current in either website locale", () => { |
| 13 | expect(docsTopicIsCurrent(topic("modes"), "en", "/en/docs/modes")).toBe(true); |
| 14 | expect(docsTopicIsCurrent(topic("tools"), "zh", "/zh/docs/tools/")).toBe(true); |
| 15 | }); |
| 16 | |
| 17 | it("does not mark a different page or the docs hub current", () => { |
| 18 | expect(docsTopicIsCurrent(topic("modes"), "en", "/en/docs/tools")).toBe(false); |
| 19 | expect(docsTopicIsCurrent(topic("modes"), "en", "/en/docs")).toBe(false); |
| 20 | }); |
| 21 | |
| 22 | it("routes install and providers to their existing first-party pages", () => { |
| 23 | expect(docTopicHref(topic("install"), "en")).toBe("/en/install"); |
| 24 | expect(docTopicHref(topic("providers"), "zh")).toBe("/zh/models"); |
| 25 | expect(docsTopicIsCurrent(topic("install"), "en", "/en/install/")).toBe(true); |
| 26 | expect(docsTopicIsCurrent(topic("providers"), "zh", "/zh/models")).toBe(true); |
| 27 | expect(docTopicIsExternal(topic("install"))).toBe(false); |
| 28 | expect(docTopicIsExternal(topic("providers"))).toBe(false); |
| 29 | }); |
| 30 | |
| 31 | it("routes the guide to its dedicated docs page in either locale", () => { |
| 32 | expect(docTopicHref(topic("guide"), "en")).toBe("/en/docs/guide"); |
| 33 | expect(docsTopicIsCurrent(topic("guide"), "en", "/en/docs/guide")).toBe(true); |
| 34 | expect(docsTopicIsCurrent(topic("guide"), "zh", "/zh/docs/guide/")).toBe(true); |
| 35 | expect(docTopicIsExternal(topic("guide"))).toBe(false); |
| 36 | }); |
| 37 | |
| 38 | it("never marks source-document links as local pages", () => { |
| 39 | expect(docsTopicIsCurrent(topic("contribution"), "en", "/en/docs/contribution")).toBe(false); |
| 40 | }); |
| 41 | |
| 42 | it("routes former link-out topics to their dedicated docs pages", () => { |
| 43 | expect(docTopicHref(topic("runtime-api"), "en")).toBe("/en/docs/runtime-api"); |
| 44 | expect(docsTopicIsCurrent(topic("runtime-api"), "en", "/en/docs/runtime-api")).toBe(true); |
| 45 | expect(docTopicIsExternal(topic("runtime-api"))).toBe(false); |
| 46 | }); |
| 47 | }); |
| 48 |