Skip to content

Commit 5f97dd5

Browse files
committed
Add test for replacing reference links within a doc
1 parent 3976dd5 commit 5f97dd5

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
id: doc3
3+
title: Document 3
4+
---
5+
6+
### Existing Docs
7+
8+
- [doc1][doc1]
9+
- [doc2][doc2]
10+
11+
### Non-existing Docs
12+
13+
- [hahaha][hahaha]
14+
15+
## Repeating Docs
16+
17+
- [doc1][doc1]
18+
- [doc2][doc2]
19+
20+
## Do not replace this
21+
```md
22+
![image1][image1]
23+
```
24+
25+
```js
26+
const doc1 = foo();
27+
console.log("[image2][image2]");
28+
const testStr = `![image3][image3]`;
29+
```
30+
31+
[doc1]: doc1.md
32+
[doc2]: ./doc2.md
33+
[hahaha]: hahaha.md
34+
[image1]: assets/image1.png
35+
[image2]: assets/image2.jpg
36+
[image3]: assets/image3.gif

v1/lib/server/__tests__/__snapshots__/docs.test.js.snap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,42 @@ const testStr = \`![image3](assets/image3.gif)\`;
4848
\`\`\`"
4949
`;
5050

51+
exports[`mdToHtmlify transforms reference links 1`] = `
52+
"
53+
### Existing Docs
54+
55+
- [doc1][doc1]
56+
- [doc2][doc2]
57+
58+
### Non-existing Docs
59+
60+
- [hahaha][hahaha]
61+
62+
## Repeating Docs
63+
64+
- [doc1][doc1]
65+
- [doc2][doc2]
66+
67+
## Do not replace this
68+
\`\`\`md
69+
![image1][image1]
70+
\`\`\`
71+
72+
\`\`\`js
73+
const doc1 = foo();
74+
console.log(\\"[image2][image2]\\");
75+
const testStr = \`![image3][image3]\`;
76+
\`\`\`
77+
78+
[doc1]: /docs/en/next/doc1
79+
[doc2]: /docs/en/next/doc2
80+
[hahaha]: hahaha.md
81+
[image1]: assets/image1.png
82+
[image2]: assets/image2.jpg
83+
[image3]: assets/image3.gif
84+
"
85+
`;
86+
5187
exports[`replaceAssetsLink does not transform document without valid assets link 1`] = `
5288
"
5389
### Existing Docs

v1/lib/server/__tests__/docs.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ const doc2 = fs.readFileSync(
5050
'utf8',
5151
);
5252

53+
const doc3 = fs.readFileSync(
54+
path.join(__dirname, '__fixtures__', 'doc3.md'),
55+
'utf8',
56+
);
57+
5358
const rawContent1 = metadataUtils.extractMetadata(doc1).rawContent;
5459
const rawContent2 = metadataUtils.extractMetadata(doc2).rawContent;
60+
const rawContent3 = metadataUtils.extractMetadata(doc3).rawContent;
5561

5662
describe('mdToHtmlify', () => {
5763
const mdToHtml = metadataUtils.mdToHtml(Metadata, '/');
@@ -77,6 +83,17 @@ describe('mdToHtmlify', () => {
7783
expect(content2).toMatchSnapshot();
7884
expect(content2).not.toEqual(rawContent2);
7985
});
86+
87+
test('transforms reference links', () => {
88+
const content3 = docs.mdToHtmlify(
89+
rawContent3,
90+
mdToHtml,
91+
Metadata['en-doc3'],
92+
);
93+
expect(content3).toContain('/docs/en/next/');
94+
expect(content3).toMatchSnapshot();
95+
expect(content3).not.toEqual(rawContent3);
96+
})
8097
});
8198

8299
describe('getFile', () => {

0 commit comments

Comments
 (0)