Skip to content

Commit 0442922

Browse files
committed
fix: review update
1 parent a06b4a6 commit 0442922

6 files changed

Lines changed: 223 additions & 2 deletions

File tree

src/__tests__/__snapshots__/tool.patternFlyDocs.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports[`usePatternFlyDocsTool, callback should attempt to parse parameters, wit
1919
exports[`usePatternFlyDocsTool, callback should have a specific markdown format: Button 1`] = `
2020
[
2121
{
22-
"text": "# Documentation for Button (v6) [undefined]
22+
"text": "# Documentation for Button (v6) [Documentation]
2323
Source: components/loremButton.md
2424
2525
lorem documentation content

src/__tests__/tool.patternFlyDocs.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { McpError } from '@modelcontextprotocol/sdk/types.js';
22
import { processDocsFunction } from '../server.getResources';
3-
import { getPatternFlyComponentSchema, getPatternFlyMcpResources } from '../patternFly.getResources';
3+
import { getPatternFlyComponentSchema, getPatternFlyMcpResources, setCategoryDisplayLabel } from '../patternFly.getResources';
44
import { searchPatternFly } from '../patternFly.search';
55
import { isPlainObject } from '../server.helpers';
66
import { usePatternFlyDocsTool } from '../tool.patternFlyDocs';
@@ -17,6 +17,7 @@ const mockProcessDocs = processDocsFunction as jest.MockedFunction<typeof proces
1717
const mockComponentSchema = getPatternFlyComponentSchema as jest.MockedFunction<typeof getPatternFlyComponentSchema>;
1818
const mockGetResources = getPatternFlyMcpResources as jest.MockedFunction<typeof getPatternFlyMcpResources>;
1919
const mockSearch = searchPatternFly as jest.MockedFunction<typeof searchPatternFly>;
20+
const mockSetCategoryLabel = setCategoryDisplayLabel as jest.MockedFunction<typeof setCategoryDisplayLabel>;
2021

2122
describe('usePatternFlyDocsTool', () => {
2223
beforeEach(() => {
@@ -50,6 +51,8 @@ describe('usePatternFlyDocsTool, callback', () => {
5051
exactMatches: [{ entries: [{ path: 'components/loremButton.md' }] }],
5152
searchResults: []
5253
} as any);
54+
55+
mockSetCategoryLabel.mockImplementation(entry => entry?.category || 'Documentation');
5356
});
5457

5558
it.each([

tests/e2e/__snapshots__/httpTransport.test.ts.snap

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,41 @@ exports[`Builtin tools, HTTP transport should initialize MCP session over HTTP 1
103103
"version": "2024-11-05",
104104
}
105105
`;
106+
107+
exports[`Builtin tools, HTTP transport should return expected markdown structure for search results: markdown 1`] = `
108+
"# Search results for PatternFly version "v6" and "button". Showing 2 exact matches.
109+
1. **button**:
110+
"usePatternFlyDocs" resource parameter "name" and "URLs"
111+
- **Name**: button
112+
- **URLs**:
113+
- [Button - (v6) - Design Guidelines for the button component.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/components/button/button.md)
114+
- [Button - (v6) - Accessibility for the button component.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/components/accessibility/button/button.md)
115+
- [Button - (v6) - Examples for the button component.](https://raw.githubusercontent.com/patternfly/patternfly-react/476782a298df81cb78de7f3cd804f3ff8f33993c/packages/react-core/src/components/Button/examples/Button.md)
116+
- **Resources**:
117+
- **URI**: patternfly://docs/button?version=v6
118+
- **JSON Schemas**: patternfly://schemas/button?version=v6
119+
120+
2. **patterns**:
121+
"usePatternFlyDocs" resource parameter "name" and "URLs"
122+
- **Name**: patterns
123+
- **URLs**:
124+
- [Actions - (v6) - The best practices for designing processes that a user can trigger by clicking or selecting a UI element, such as a button or link.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/actions/actions.md)
125+
- [Bulk selection - (v6) - A defined method for users to select or deselect multiple items within complex content views or data tables.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/bulk-selection/bulk-selection.md)
126+
- [Card view - (v6) - A structured layout designed to display a grid of cards in a gallery, optimizing for browsing and interaction.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/card-view/card-view.md)
127+
- [Component usage and behavior - (v6) - Guidance on how to choose between similar components and use them appropriately based on specific user contexts and use cases.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/usage-and-behavior.md)
128+
- [Dashboard - (v6) - A highly customizable layout that serves as a high-level overview of key metrics or performance indicators.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/dashboard/dashboard.md)
129+
- [Filters - (v6) - The design rules for implementing filtering mechanisms that allow users to narrow down content from large datasets or complex views.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/filters/filters.md)
130+
- [Primary-detail - (v6) - A two-pane layout that shows a list of items and corresponding details for the currently selected item.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/primary-detail/primary-detail.md)
131+
- [Status and severity - (v6) - Guidance on the consistent and accessible use of color and iconography to communicate status and severity across the UI.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/status-and-severity/status-and-severity.md)
132+
- **Resources**:
133+
- **URI**: patternfly://docs/patterns?version=v6
134+
135+
136+
137+
---
138+
139+
140+
**Important**:
141+
- Use the "usePatternFlyDocs" tool with the above names and URLs to fetch resource content.
142+
- Use a search all ("*") to find all available resources."
143+
`;

tests/e2e/__snapshots__/stdioTransport.test.ts.snap

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,44 @@ exports[`Builtin tools, STDIO should expose expected tools and stable shape 1`]
104104
}
105105
`;
106106
107+
exports[`Builtin tools, STDIO should return expected markdown structure for search results: markdown 1`] = `
108+
"# Search results for PatternFly version "v6" and "button". Showing 2 exact matches.
109+
1. **button**:
110+
"usePatternFlyDocs" resource parameter "name" and "URLs"
111+
- **Name**: button
112+
- **URLs**:
113+
- [Button - (v6) - Design Guidelines for the button component.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/components/button/button.md)
114+
- [Button - (v6) - Accessibility for the button component.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/components/accessibility/button/button.md)
115+
- [Button - (v6) - Examples for the button component.](https://raw.githubusercontent.com/patternfly/patternfly-react/476782a298df81cb78de7f3cd804f3ff8f33993c/packages/react-core/src/components/Button/examples/Button.md)
116+
- **Resources**:
117+
- **URI**: patternfly://docs/button?version=v6
118+
- **JSON Schemas**: patternfly://schemas/button?version=v6
119+
120+
2. **patterns**:
121+
"usePatternFlyDocs" resource parameter "name" and "URLs"
122+
- **Name**: patterns
123+
- **URLs**:
124+
- [Actions - (v6) - The best practices for designing processes that a user can trigger by clicking or selecting a UI element, such as a button or link.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/actions/actions.md)
125+
- [Bulk selection - (v6) - A defined method for users to select or deselect multiple items within complex content views or data tables.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/bulk-selection/bulk-selection.md)
126+
- [Card view - (v6) - A structured layout designed to display a grid of cards in a gallery, optimizing for browsing and interaction.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/card-view/card-view.md)
127+
- [Component usage and behavior - (v6) - Guidance on how to choose between similar components and use them appropriately based on specific user contexts and use cases.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/usage-and-behavior.md)
128+
- [Dashboard - (v6) - A highly customizable layout that serves as a high-level overview of key metrics or performance indicators.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/dashboard/dashboard.md)
129+
- [Filters - (v6) - The design rules for implementing filtering mechanisms that allow users to narrow down content from large datasets or complex views.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/filters/filters.md)
130+
- [Primary-detail - (v6) - A two-pane layout that shows a list of items and corresponding details for the currently selected item.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/primary-detail/primary-detail.md)
131+
- [Status and severity - (v6) - Guidance on the consistent and accessible use of color and iconography to communicate status and severity across the UI.](https://raw.githubusercontent.com/patternfly/patternfly-org/2d5fec39ddb8aa32ce78c9a63cdfc1653692b193/packages/documentation-site/patternfly-docs/content/patterns/status-and-severity/status-and-severity.md)
132+
- **Resources**:
133+
- **URI**: patternfly://docs/patterns?version=v6
134+
135+
136+
137+
---
138+
139+
140+
**Important**:
141+
- Use the "usePatternFlyDocs" tool with the above names and URLs to fetch resource content.
142+
- Use a search all ("*") to find all available resources."
143+
`;
144+
107145
exports[`Logging should allow setting logging options, default 1`] = `[]`;
108146
109147
exports[`Logging should allow setting logging options, stderr 1`] = `

tests/e2e/httpTransport.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,77 @@ describe('Builtin tools, HTTP transport', () => {
129129
expect(text).toMatchSnapshot();
130130
await CLIENT.close();
131131
});
132+
133+
it.each([
134+
{
135+
description: 'exact match for Button',
136+
searchQuery: 'Button',
137+
contains: [
138+
'# Search results for PatternFly version "v6" and "Button". Showing',
139+
'**button**'
140+
]
141+
},
142+
{
143+
description: 'case-insensitive match',
144+
searchQuery: 'button',
145+
contains: [
146+
'# Search results for PatternFly version "v6" and "button". Showing',
147+
'**button**'
148+
]
149+
},
150+
{
151+
description: 'wildcard search',
152+
searchQuery: '*',
153+
contains: [
154+
'# Search results for PatternFly version "v6" and "all" resources. Only showing the first 10 results',
155+
'**accessibility**'
156+
]
157+
},
158+
{
159+
description: 'fuzzy search for partial name',
160+
searchQuery: 'ton',
161+
contains: [
162+
'# Search results for PatternFly version "v6" and "ton". Showing',
163+
'**button**'
164+
]
165+
},
166+
{
167+
description: 'explicit version search',
168+
searchQuery: 'Button',
169+
version: 'v6',
170+
contains: [
171+
'# Search results for PatternFly version "v6" and "Button". Showing',
172+
'**button**'
173+
]
174+
}
175+
])('should perform searchPatternFlyDocs: $description', async ({ searchQuery, version, contains }) => {
176+
const req = {
177+
method: 'tools/call',
178+
params: {
179+
name: 'searchPatternFlyDocs',
180+
arguments: version ? { searchQuery, version } : { searchQuery }
181+
}
182+
};
183+
184+
const response = await CLIENT?.send(req);
185+
const text = response?.result?.content?.[0]?.text || '';
186+
187+
contains.forEach(item => expect(text).toContain(item));
188+
});
189+
190+
it('should return expected markdown structure for search results', async () => {
191+
const response = await CLIENT?.send({
192+
method: 'tools/call',
193+
params: {
194+
name: 'searchPatternFlyDocs',
195+
arguments: { searchQuery: 'button' }
196+
}
197+
});
198+
199+
const text = response?.result?.content?.[0]?.text || '';
200+
201+
expect(text).toMatchSnapshot('markdown');
202+
});
132203
});
133204

134205
describe('Builtin resources, HTTP transport', () => {

tests/e2e/stdioTransport.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,77 @@ describe('Builtin tools, STDIO', () => {
125125
expect(text.includes('This is a generated offline fixture')).toBe(true);
126126
expect(text).toMatchSnapshot();
127127
});
128+
129+
it.each([
130+
{
131+
description: 'exact match for Button',
132+
searchQuery: 'Button',
133+
contains: [
134+
'# Search results for PatternFly version "v6" and "Button". Showing',
135+
'**button**'
136+
]
137+
},
138+
{
139+
description: 'case-insensitive match',
140+
searchQuery: 'button',
141+
contains: [
142+
'# Search results for PatternFly version "v6" and "button". Showing',
143+
'**button**'
144+
]
145+
},
146+
{
147+
description: 'wildcard search',
148+
searchQuery: '*',
149+
contains: [
150+
'# Search results for PatternFly version "v6" and "all" resources. Only showing the first 10 results',
151+
'**accessibility**'
152+
]
153+
},
154+
{
155+
description: 'fuzzy search for partial name',
156+
searchQuery: 'ton',
157+
contains: [
158+
'# Search results for PatternFly version "v6" and "ton". Showing',
159+
'**button**'
160+
]
161+
},
162+
{
163+
description: 'explicit version search',
164+
searchQuery: 'Button',
165+
version: 'v6',
166+
contains: [
167+
'# Search results for PatternFly version "v6" and "Button". Showing',
168+
'**button**'
169+
]
170+
}
171+
])('should perform searchPatternFlyDocs: $description', async ({ searchQuery, version, contains }) => {
172+
const req = {
173+
method: 'tools/call',
174+
params: {
175+
name: 'searchPatternFlyDocs',
176+
arguments: version ? { searchQuery, version } : { searchQuery }
177+
}
178+
};
179+
180+
const response = await CLIENT.send(req);
181+
const text = response?.result?.content?.[0]?.text || '';
182+
183+
contains.forEach(item => expect(text).toContain(item));
184+
});
185+
186+
it('should return expected markdown structure for search results', async () => {
187+
const response = await CLIENT.send({
188+
method: 'tools/call',
189+
params: {
190+
name: 'searchPatternFlyDocs',
191+
arguments: { searchQuery: 'button' }
192+
}
193+
});
194+
195+
const text = response?.result?.content?.[0]?.text || '';
196+
197+
expect(text).toMatchSnapshot('markdown');
198+
});
128199
});
129200

130201
describe('Builtin resources, STDIO', () => {

0 commit comments

Comments
 (0)