Skip to content

Commit

Permalink
Add test for replacing reference links within a doc
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Oct 26, 2018
1 parent 3976dd5 commit 5f97dd5
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
36 changes: 36 additions & 0 deletions v1/lib/server/__tests__/__fixtures__/doc3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
id: doc3
title: Document 3
---

### Existing Docs

- [doc1][doc1]
- [doc2][doc2]

### Non-existing Docs

- [hahaha][hahaha]

## Repeating Docs

- [doc1][doc1]
- [doc2][doc2]

## Do not replace this
```md
![image1][image1]
```

```js
const doc1 = foo();
console.log("[image2][image2]");
const testStr = `![image3][image3]`;
```

[doc1]: doc1.md
[doc2]: ./doc2.md
[hahaha]: hahaha.md
[image1]: assets/image1.png
[image2]: assets/image2.jpg
[image3]: assets/image3.gif
36 changes: 36 additions & 0 deletions v1/lib/server/__tests__/__snapshots__/docs.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,42 @@ const testStr = \`![image3](assets/image3.gif)\`;
\`\`\`"
`;

exports[`mdToHtmlify transforms reference links 1`] = `
"
### Existing Docs
- [doc1][doc1]
- [doc2][doc2]
### Non-existing Docs
- [hahaha][hahaha]
## Repeating Docs
- [doc1][doc1]
- [doc2][doc2]
## Do not replace this
\`\`\`md
![image1][image1]
\`\`\`
\`\`\`js
const doc1 = foo();
console.log(\\"[image2][image2]\\");
const testStr = \`![image3][image3]\`;
\`\`\`
[doc1]: /docs/en/next/doc1
[doc2]: /docs/en/next/doc2
[hahaha]: hahaha.md
[image1]: assets/image1.png
[image2]: assets/image2.jpg
[image3]: assets/image3.gif
"
`;

exports[`replaceAssetsLink does not transform document without valid assets link 1`] = `
"
### Existing Docs
Expand Down
17 changes: 17 additions & 0 deletions v1/lib/server/__tests__/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ const doc2 = fs.readFileSync(
'utf8',
);

const doc3 = fs.readFileSync(
path.join(__dirname, '__fixtures__', 'doc3.md'),
'utf8',
);

const rawContent1 = metadataUtils.extractMetadata(doc1).rawContent;
const rawContent2 = metadataUtils.extractMetadata(doc2).rawContent;
const rawContent3 = metadataUtils.extractMetadata(doc3).rawContent;

describe('mdToHtmlify', () => {
const mdToHtml = metadataUtils.mdToHtml(Metadata, '/');
Expand All @@ -77,6 +83,17 @@ describe('mdToHtmlify', () => {
expect(content2).toMatchSnapshot();
expect(content2).not.toEqual(rawContent2);
});

test('transforms reference links', () => {
const content3 = docs.mdToHtmlify(
rawContent3,
mdToHtml,
Metadata['en-doc3'],
);
expect(content3).toContain('/docs/en/next/');
expect(content3).toMatchSnapshot();
expect(content3).not.toEqual(rawContent3);
})
});

describe('getFile', () => {
Expand Down

0 comments on commit 5f97dd5

Please sign in to comment.