-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathlink.spec.js
77 lines (60 loc) · 1.77 KB
/
link.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Md } from './util'
import link from '@/markdown/link.js'
import { dataReturnable } from '@/markdown/index.js'
const mdL = Md().use(link, {
target: '_blank',
rel: 'noopener noreferrer'
})
dataReturnable(mdL)
const internalLinkAsserts = {
// START abosolute path usage
'/': '/',
'/foo/': '/foo/',
'/foo/#hash': '/foo/#hash',
'/foo/two.md': '/foo/two.html',
'/foo/two.html': '/foo/two.html',
// END abosolute path usage
// START relative path usage
'README.md': './',
'./README.md': './',
'index.md': './',
'./index.md': './',
'one.md': './one.html',
'./one.md': './one.html',
'foo/README.md': './foo/',
'./foo/README.md': './foo/',
'foo/README.md#hash': './foo/#hash',
'./foo/README.md#hash': './foo/#hash',
'../README.md': './../',
'../README.md#hash': './../#hash',
'../foo.md': './../foo.html',
'../foo.md#hash': './../foo.html#hash',
'../foo/one.md': './../foo/one.html',
'../foo/one.md#hash': './../foo/one.html#hash'
// END relative path usage
}
const externalLinks = [
'[vue](https://vuejs.org/)',
'[vue](http://vuejs.org/)',
'[some **link** with `code`](https://google.com)' // #496
]
describe('link', () => {
test('should convert internal links to router links correctly', () => {
for (const before in internalLinkAsserts) {
const input = `[${before}](${before})`
const output = mdL.render(input)
const after = getCompiledLink(output)
expect(after).toBe(internalLinkAsserts[before])
}
})
test('should render external links correctly', () => {
for (const link of externalLinks) {
const { html } = mdL.render(link)
expect(html).toMatchSnapshot()
}
})
})
function getCompiledLink (output) {
const { data: { routerLinks }} = output
return routerLinks[0]
}