1 import { describe, it, expect } from "vitest"
2 import { cleanIntroContent, sliceSection } from "../intro-to-markdown"
3
4 const SAMPLE_MDX = `import Section from "@/components/Section"
5 import { CodeTabs, CodeTab, H1 } from "docs-ui"
6 import { Feedback } from "@/components/Feedback"
7
8 <Section checkActiveOnScroll>
9
10 <SectionContainer noTopPadding={true}>
11
12 <DividedMarkdownLayout>
13
14 <DividedMarkdownContent>
15
16 <H1 id="introduction">Store API Reference</H1>
17
18 Intro paragraph.
19
20 <Feedback question="Was this helpful?" />
21
22 </DividedMarkdownContent>
23
24 </DividedMarkdownLayout>
25
26 </SectionContainer>
27
28 <SectionContainer noTopPadding={true}>
29
30 <DividedMarkdownContent>
31
32 ## Authentication
33
34 Auth intro.
35
36 </DividedMarkdownContent>
37
38 <DividedMarkdownCode>
39
40 \`\`\`bash title="Example"
41 curl example
42 \`\`\`
43
44 </DividedMarkdownCode>
45
46 </SectionContainer>
47
48 </Section>
49 `
50
51 describe("cleanIntroContent", () => {
52 it("unwraps structural components and converts H1 to a heading", async () => {
53 const md = await cleanIntroContent(SAMPLE_MDX)
54 expect(md).toContain("# Store API Reference")
55 expect(md).toContain("Intro paragraph.")
56 expect(md).toContain("## Authentication")
57 expect(md).toContain("Auth intro.")
58 // code block inside DividedMarkdownCode survives
59 expect(md).toContain("curl example")
60 // Feedback and raw wrapper tags are removed
61 expect(md).not.toContain("Feedback")
62 expect(md).not.toContain("DividedMarkdown")
63 expect(md).not.toContain("<H1")
64 })
65
66 it("resolves cross-project (!area!) links to real URLs", async () => {
67 const mdx = `<DividedMarkdownContent>
68
69 See the [JS SDK guide](!resources!/js-sdk#configurations).
70
71 </DividedMarkdownContent>`
72 const md = await cleanIntroContent(mdx)
73 expect(md).not.toContain("!resources!")
74 expect(md).toContain("/resources/js-sdk#configurations")
75 })
76 })
77
78 describe("sliceSection", () => {
79 const content = `# Title
80
81 Intro.
82
83 ## Authentication
84
85 Auth content.
86
87 ### Sub
88
89 more.
90
91 ## Publishable API Key
92
93 Other content.
94 `
95
96 it("extracts a single section up to the next level-2 heading", () => {
97 const section = sliceSection(content, "Authentication")
98 expect(section).toContain("## Authentication")
99 expect(section).toContain("Auth content.")
100 expect(section).toContain("### Sub")
101 expect(section).not.toContain("## Publishable API Key")
102 expect(section).not.toContain("Other content.")
103 })
104
105 it("returns null when the section is missing", () => {
106 expect(sliceSection(content, "Nonexistent")).toBeNull()
107 })
108 })