-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathrender-util.test.js
124 lines (109 loc) Β· 3.97 KB
/
render-util.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
const {
removeAtag,
getAndRemoveConfig,
} = require('../../src/core/render/utils');
const { tree } = require(`../../src/core/render/tpl`);
const { slugify } = require(`../../src/core/render/slugify`);
// Suite
// -----------------------------------------------------------------------------
describe('core/render/utils', () => {
// removeAtag()
// ---------------------------------------------------------------------------
describe('removeAtag()', () => {
test('removeAtag from a link', () => {
const result = removeAtag('<a href="www.example.com">content</a>');
expect(result).toBe('content');
});
});
// getAndRemoveConfig()
// ---------------------------------------------------------------------------
describe('getAndRemoveConfig()', () => {
test('parse simple config', () => {
const result = getAndRemoveConfig(
`[filename](_media/example.md ':include')`
);
expect(result).toMatchObject({
config: {},
str: `[filename](_media/example.md ':include')`,
});
});
test('parse config with arguments', () => {
const result = getAndRemoveConfig(
`[filename](_media/example.md ':include :foo=bar :baz test')`
);
expect(result).toMatchObject({
config: {
foo: 'bar',
baz: true,
},
str: `[filename](_media/example.md ':include test')`,
});
});
test('parse config with double quotes', () => {
const result = getAndRemoveConfig(
`[filename](_media/example.md ":include")`
);
expect(result).toMatchObject({
config: {},
str: `[filename](_media/example.md ":include")`,
});
});
test('parse config with quoted string arguments', () => {
const result = getAndRemoveConfig(
`[filename](_media/example.md ':include :foo="bar :baz test"')`
);
expect(result).toMatchObject({
config: {
foo: 'bar :baz test',
},
str: `[filename](_media/example.md ':include')`,
});
});
});
});
describe('core/render/tpl', () => {
test('remove html tag in tree', () => {
const result = tree([
{
level: 2,
slug: '#/cover?id=basic-usage',
title: '<span style="color:red">Basic usage</span>',
text: '<span style="color:red">Basic usage</span>',
},
{
level: 2,
slug: '#/cover?id=custom-background',
title: 'Custom background',
text: 'Custom background',
},
{
level: 2,
slug: '#/cover?id=test',
title:
'<img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test',
text: '<img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test',
},
{
level: 2,
slug: '#/cover?id=different-title-and-label',
title: 'Long title string',
text: 'Short string',
},
]);
expect(result).toBe(
`<ul class="app-sub-sidebar"><li><a class="section-link" href="#/cover?id=basic-usage" title="Basic usage"><span style="color:red">Basic usage</span></a></li><li><a class="section-link" href="#/cover?id=custom-background" title="Custom background">Custom background</a></li><li><a class="section-link" href="#/cover?id=test" title="Test"><img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test</a></li><li><a class="section-link" href="#/cover?id=different-title-and-label" title="Long title string">Short string</a></li></ul>`
);
});
});
describe('core/render/slugify', () => {
test('slugify()', () => {
const result = slugify(
`Bla bla bla <svg aria-label="broken" class="broken" viewPort="0 0 1 1"><circle cx="0.5" cy="0.5"/></svg>`
);
const result2 = slugify(
`Another <span style="font-size: 1.2em" class="foo bar baz">broken <span class="aaa">example</span></span>`
);
expect(result).toBe(`bla-bla-bla-`);
expect(result2).toBe(`another-broken-example`);
});
});