-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathget_documentation.test.ts
More file actions
68 lines (56 loc) · 2.64 KB
/
Copy pathget_documentation.test.ts
File metadata and controls
68 lines (56 loc) · 2.64 KB
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
import test from 'ava';
import { sliceLines, getDocumentationTool } from './get_documentation.js';
const handler = getDocumentationTool.handler;
function getText(response: ReturnType<typeof handler>): string {
return response.content[0].text;
}
test('sliceLines: returns content unchanged when no line range specified', (t) => {
const content = 'line1\nline2\nline3';
t.is(sliceLines(content), content);
});
test('sliceLines: extracts specific line range (1-based)', (t) => {
const content = 'line1\nline2\nline3\nline4\nline5';
const result = sliceLines(content, 2, 4);
t.true(result.includes('[Lines 2-4 of 5]'));
t.true(result.includes('line2'));
t.true(result.includes('line4'));
t.false(result.includes('line1'));
t.false(result.includes('line5'));
});
test('handler: search query finds matching section', (t) => {
const result = getText(handler({ query: 'styling' }));
t.true(result.includes('Styling'));
});
test('handler: search with no matches returns empty message', (t) => {
const result = getText(handler({ query: 'xyznonexistent_garbage_query' }));
t.true(result.includes('No Documentation Found'));
});
test('handler: section lookup with fetchContent verifies gitignored docs exist', (t) => {
// docs/*.mdx files are gitignored (generated by bundle:docs)
// fetchContent triggers readDocContent which reads from the docs/ directory
const result = getText(handler({ section: 'Getting Started', fetchContent: true }));
t.true(result.includes('Getting Started'));
t.false(result.includes('bundled docs may need to be regenerated'));
});
test('handler: subsection lookup uses "Section > Subsection" format', (t) => {
const result = getText(handler({ section: 'Knowledge Base > Styling' }));
t.true(result.includes('Styling'));
});
test('handler: startLine without fetchContent returns error', (t) => {
const result = getText(handler({ section: 'Getting Started', startLine: 1 }));
t.true(result.includes('fetchContent'));
});
test('handler: section + query together returns error', (t) => {
const result = getText(handler({ section: 'Getting Started', query: 'styling' }));
t.true(result.includes('either'));
});
test('handler: search finds the Testing section', (t) => {
const result = getText(handler({ query: 'testing' }));
t.true(result.includes('Testing'));
});
test('handler: Testing section lookup with fetchContent loads bundled content', (t) => {
// docs/*.mdx files are gitignored (generated by bundle:docs)
const result = getText(handler({ section: 'Knowledge Base > Testing', fetchContent: true }));
t.true(result.includes('Testing'));
t.false(result.includes('bundled docs may need to be regenerated'));
});