-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
132 lines (105 loc) · 4.52 KB
/
index.test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { remark } from 'remark'
import plugin from '.'
const terms = [{ term: 'Lens SDK' }, { term: 'JSON' }]
describe('remark-automatic-glossary-markup', () => {
test('Wraps a glossary term in a link located in a paragraph', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const resultString = processor.processSync(
'The Lens SDK is an easy to use SDK\n',
)
expect(resultString.value).toBe(
'The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK\n',
)
})
test('Wraps a glossary term in a link located in a list item', async () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
processor.processSync()
const resultString = await processor.process(
'- The Lens SDK is an easy to use SDK\n',
)
expect(resultString.value).toBe(
'* The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK\n',
)
})
test('Wraps a glossary term in a link located in a numbered list item', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const resultString = processor.processSync(
'1. The Lens SDK is an easy to use SDK\n',
)
expect(resultString.value).toBe(
'1. The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK\n',
)
})
test('Wraps a multiple terms located in the same paragraph', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const resultString = processor.processSync(
'The Lens SDK is an easy to use SDK and uses JSON\n',
)
expect(resultString.value).toBe(
'The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK and uses [JSON](#glossary-JSON)\n',
)
})
test('Only wraps the first of a specific term that occurs in a single line.', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const resultString = processor.processSync(
'The Lens SDK is an easy to use SDK. It is the only Lens SDK you will ever need.\n',
)
expect(resultString.value).toBe(
'The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK. It is the only Lens SDK you will ever need.\n',
)
})
test('Only wraps the first of a specific term that occurs in multiple lines.', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const resultString = processor.processSync(
'The Lens SDK is an easy to use SDK.\nIt is the only Lens SDK you will ever need.\n',
)
expect(resultString.value).toBe(
'The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK.\nIt is the only Lens SDK you will ever need.\n',
)
})
test('Will not rewrap a term that is already in a link', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const resultString = processor.processSync(
'The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK\n',
)
expect(resultString.value).toBe(
'The [Lens SDK](#glossary-Lens%20SDK) is an easy to use SDK\n',
)
})
test('Will not wrap a term that is in a header', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const markdownHeader = '# The Lens SDK\n'
const resultString = processor.processSync(markdownHeader)
expect(resultString.value).toBe(markdownHeader)
})
test('Will not wrap a term that is code', () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const markdownWithCode =
"Don't wrap a term in a code block `JSON The Lens SDK`\n"
const resultString = processor.processSync(markdownWithCode)
expect(resultString.value).toBe(markdownWithCode)
})
test("Don't add a reference to link", () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const markdownWithCode = '[JSON Website](https://www.json.org/)\n'
const resultString = processor.processSync(markdownWithCode)
expect(resultString.value).toBe(markdownWithCode)
})
test("Don't wrap just part of a word", () => {
// Create our processor with our plugin
const processor = remark().use(plugin, { terms })
const markdownWithCode = 'You can use this JSONIZER to do this work\n'
const resultString = processor.processSync(markdownWithCode)
expect(resultString.value).toBe(markdownWithCode)
})
})