forked from docsifyjs/docsify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.test.js
142 lines (124 loc) Β· 4.21 KB
/
example.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
133
134
135
136
137
138
139
140
141
142
import { waitForFunction, waitForText } from '../helpers/wait-for.js';
import docsifyInit from '../helpers/docsify-init.js';
describe('Creating a Docsify site (integration tests in Jest)', function () {
test('Docsify /docs/ site using docsifyInit()', async () => {
await docsifyInit({
// _logHTML: true,
});
// Verify config options
expect(typeof window.$docsify).toBe('object');
// Verify options.markdown content was rendered
expect(document.querySelector('#main').textContent).toContain(
'A magical documentation site generator',
);
});
test('kitchen sink docsify site using docsifyInit()', async () => {
const docsifyInitConfig = {
config: {
name: 'Docsify Name',
themeColor: 'red',
},
markdown: {
coverpage: `
# Docsify Test
> Testing a magical documentation site generator
[GitHub](https://github.com/docsifyjs/docsify/)
`,
homepage: `
# Hello World
This is the homepage.
`,
navbar: `
- [docsify.js.org](https://docsify.js.org/#/)
`,
sidebar: `
- [Test Page](test)
`,
},
routes: {
'test.md': `
# Test Page
This is a custom route.
`,
'data-test-scripturls.js': `
document.body.setAttribute('data-test-scripturls', 'pass');
`,
},
script: `
document.body.setAttribute('data-test-script', 'pass');
`,
scriptURLs: [
// docsifyInit() route
'data-test-scripturls.js',
// Server route
'/dist/plugins/search.js',
],
style: `
body {
background: red !important;
}
`,
styleURLs: ['/dist/themes/core.css'],
};
await docsifyInit({
...docsifyInitConfig,
// _logHTML: true,
});
// Verify config options
expect(typeof window.$docsify).toBe('object');
expect(window.$docsify).toHaveProperty('themeColor', 'red');
expect(document.querySelector('.app-name').textContent).toContain(
'Docsify Name',
);
// Verify docsifyInitConfig.markdown content was rendered
Object.entries({
'section.cover': 'Docsify Test', // Coverpage
'nav.app-nav': 'docsify.js.org', // Navbar
'aside.sidebar': 'Test Page', // Sidebar
'#main': 'This is the homepage', // Homepage
}).forEach(([selector, content]) => {
expect(document.querySelector(selector).textContent).toContain(content);
});
// Verify docsifyInitConfig.scriptURLs were added to the DOM
for (const scriptURL of docsifyInitConfig.scriptURLs) {
const matchElm = document.querySelector(
`script[data-src$="${scriptURL}"]`,
);
expect(matchElm).toBeTruthy();
}
// Verify docsifyInitConfig.scriptURLs were executed
expect(document.body.hasAttribute('data-test-scripturls')).toBe(true);
expect(document.querySelector('.search input[type="search"]')).toBeTruthy();
// Verify docsifyInitConfig.script was added to the DOM
expect(
[...document.querySelectorAll('script')].some(
elm =>
elm.textContent.replace(/\s+/g, '') ===
docsifyInitConfig.script.replace(/\s+/g, ''),
),
).toBe(true);
// Verify docsifyInitConfig.script was executed
expect(document.body.hasAttribute('data-test-script')).toBe(true);
// Verify docsifyInitConfig.styleURLs were added to the DOM
for (const styleURL of docsifyInitConfig.styleURLs) {
const matchElm = document.querySelector(
`link[rel*="stylesheet"][href$="${styleURL}"]`,
);
expect(matchElm).toBeTruthy();
}
// Verify docsifyInitConfig.style was added to the DOM
expect(
[...document.querySelectorAll('style')].some(
elm =>
elm.textContent.replace(/\s+/g, '') ===
docsifyInitConfig.style.replace(/\s+/g, ''),
),
).toBe(true);
// Verify docsify navigation and docsifyInitConfig.routes
document.querySelector('a[href="#/test"]').click();
expect(
await waitForFunction(() => /#\/test$/.test(window.location.href)),
).toBeTruthy();
expect(await waitForText('#main', 'This is a custom route')).toBeTruthy();
});
});