forked from patternfly/patternfly-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.searchPatternFlyDocs.test.ts
More file actions
114 lines (103 loc) · 3 KB
/
tool.searchPatternFlyDocs.test.ts
File metadata and controls
114 lines (103 loc) · 3 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
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
import { McpError } from '@modelcontextprotocol/sdk/types.js';
import { searchPatternFlyDocsTool } from '../tool.searchPatternFlyDocs';
import { isPlainObject } from '../server.helpers';
// Mock dependencies
jest.mock('../server.caching', () => ({
memo: jest.fn(fn => fn)
}));
describe('searchPatternFlyDocsTool', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should have a consistent return structure', () => {
const tool = searchPatternFlyDocsTool();
expect({
name: tool[0],
schema: isPlainObject(tool[1]),
callback: tool[2]
}).toMatchSnapshot('structure');
});
});
describe('searchPatternFlyDocsTool, callback', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it.each([
{
description: 'default',
searchQuery: 'Button'
},
{
description: 'with trimmed componentName',
searchQuery: ' Button '
},
{
description: 'with lower case componentName',
searchQuery: 'button'
},
{
description: 'with upper case componentName',
searchQuery: 'BUTTON'
},
{
description: 'with explicit valid version',
searchQuery: 'Button',
version: 'v6'
},
{
description: 'with partial componentName',
searchQuery: 'ton'
},
{
description: 'with multiple words',
searchQuery: 'Button Card Table'
},
{
description: 'with made up componentName',
searchQuery: 'lorem ipsum dolor sit amet'
},
{
description: 'with "*" searchQuery all',
searchQuery: '*'
},
{
description: 'with "all" searchQuery all',
searchQuery: 'ALL'
}
])('should parse parameters, $description', async ({ searchQuery }) => {
const [_name, _schema, callback] = searchPatternFlyDocsTool();
const result = await callback({ searchQuery });
expect(result.content[0].text.split('\n')[0]).toMatchSnapshot('search');
});
it.each([
{
description: 'with empty searchQuery',
error: '"searchQuery" must be a string from',
searchQuery: ''
},
{
description: 'with missing or undefined searchQuery',
error: '"searchQuery" must be a string from',
searchQuery: undefined
},
{
description: 'with null searchQuery',
error: '"searchQuery" must be a string from',
searchQuery: null
},
{
description: 'with non-string searchQuery',
error: '"searchQuery" must be a string from',
searchQuery: 123
}
])('should handle errors, $description', async ({ error, searchQuery }) => {
const [_name, _schema, callback] = searchPatternFlyDocsTool();
await expect(callback({ searchQuery })).rejects.toThrow(McpError);
await expect(callback({ searchQuery })).rejects.toThrow(error);
});
it('should have a specific markdown format', async () => {
const [_name, _schema, callback] = searchPatternFlyDocsTool();
const result = await callback({ searchQuery: 'button' });
expect(result.content).toMatchSnapshot('tooltip');
});
});