-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
Copy pathsearch.test.js
336 lines (276 loc) · 9.54 KB
/
search.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
import docsifyInit from '../helpers/docsify-init.js';
import { test, expect } from './fixtures/docsify-init-fixture.js';
test.describe('Search Plugin Tests', () => {
test('search readme', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
This is the homepage.
`,
sidebar: `
- [Test Page](test)
`,
},
routes: {
'/test.md': `
# Test Page
This is a custom route.
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .title');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('hello');
await expect(resultsHeadingElm).toHaveText('Hello World');
await page.click('.clear-button');
await searchFieldElm.fill('test');
await expect(resultsHeadingElm).toHaveText('Test Page');
});
test('search ignore title', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
This is the homepage.
`,
sidebar: `
- [Home page](/)
- [GitHub Pages](github)
`,
},
routes: {
'/github.md': `
# GitHub Pages
This is the GitHub Pages.
## GitHub Pages ignore1 <!-- {docsify-ignore} -->
There're three places to populate your docs for your Github repository1.
## GitHub Pages ignore2 {docsify-ignore}
There're three places to populate your docs for your Github repository2.
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .title');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('repository1');
await expect(resultsHeadingElm).toHaveText('GitHub Pages ignore1');
await page.click('.clear-button');
await searchFieldElm.fill('repository2');
await expect(resultsHeadingElm).toHaveText('GitHub Pages ignore2');
});
test('search only one homepage', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
sidebar: `
- [README](README)
- [Test Page](test)
`,
},
routes: {
'/README.md': `
# Hello World
This is the homepage.
`,
'/test.md': `
# Test Page
This is a custom route.
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .title');
const resultElm = page.locator('.matching-post');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('hello');
await expect(resultElm).toHaveCount(1);
await expect(resultsHeadingElm).toHaveText('Hello World');
await page.click('.clear-button');
await searchFieldElm.fill('test');
await expect(resultsHeadingElm).toHaveText('Test Page');
});
test('search ignore diacritical marks', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Qué es
docsify genera su sitio web de documentación sobre la marcha. A diferencia de GitBook, no genera archivos estáticos html. En cambio, carga y analiza de forma inteligente sus archivos de Markdown y los muestra como sitio web. Todo lo que necesita hacer es crear un index.html para comenzar y desplegarlo en GitHub Pages.
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .title');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('documentacion');
await expect(resultsHeadingElm).toHaveText('Que es');
await page.click('.clear-button');
await searchFieldElm.fill('estáticos');
await expect(resultsHeadingElm).toHaveText('Que es');
});
test('search when there is no title', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
This is some description. We assume autoHeader added the # Title. A long paragraph.
`,
sidebar: `
- [Changelog](changelog)
`,
},
routes: {
'/changelog.md': `
feat: Support search when there is no title
## Changelog Title
hello, this is a changelog
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .title');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('paragraph');
await expect(resultsHeadingElm).toHaveText('Home Page');
await page.click('.clear-button');
await searchFieldElm.fill('Support');
await expect(resultsHeadingElm).toHaveText('changelog');
await page.click('.clear-button');
await searchFieldElm.fill('hello');
await expect(resultsHeadingElm).toHaveText('Changelog Title');
});
test('search when there is no body', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# EmptyContent
---
---
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .title');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('empty');
await expect(resultsHeadingElm).toHaveText('EmptyContent');
});
test('handles default focusSearch binding', async ({ page }) => {
const docsifyInitConfig = {
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type="search"]');
await docsifyInit(docsifyInitConfig);
await expect(searchFieldElm).not.toBeFocused();
await page.keyboard.press('/');
await expect(searchFieldElm).toBeFocused();
});
test('handles custom focusSearch binding', async ({ page }) => {
const docsifyInitConfig = {
config: {
search: {
keyBindings: ['z'],
},
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type="search"]');
await docsifyInit(docsifyInitConfig);
await expect(searchFieldElm).not.toBeFocused();
await page.keyboard.press('/');
await expect(searchFieldElm).not.toBeFocused();
await page.keyboard.press('z');
await expect(searchFieldElm).toBeFocused();
});
test('search result should remove markdown code block', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
searchHere
\`\`\`js
console.log('Hello World');
\`\`\`
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .content');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('searchHere');
// there is a newline after searchHere and the markdown part ```js ``` it should be removed
expect(await resultsHeadingElm.textContent()).toContain(
"...searchHere\nconsole.log('Hello World');...",
);
});
test('search result should remove file markdown and keep href attribution for files', async ({
page,
}) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World

`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .content');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('filename');
expect(await resultsHeadingElm.textContent()).toContain(
'...filename _media/example.js :include :type=code :fragment=demo...',
);
});
test('search result should remove checkbox markdown and keep related values', async ({
page,
}) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
- [ ] Task 1
- [x] SearchHere
- [ ] Task 3
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .content');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('SearchHere');
// remove the checkbox markdown and keep the related values
expect(await resultsHeadingElm.textContent()).toContain(
'...Task 1 SearchHere Task 3...',
);
});
test('search result should remove docsify self helper markdown and keep related values', async ({
page,
}) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
!> SearchHere to check it!
`,
},
scriptURLs: ['/dist/plugins/search.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel .content');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('SearchHere');
// remove the helper markdown and keep the related values
expect(await resultsHeadingElm.textContent()).toContain(
'...SearchHere to check it!...',
);
});
});