-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathSearchIndexTool.test.tsx
More file actions
90 lines (77 loc) · 2.63 KB
/
SearchIndexTool.test.tsx
File metadata and controls
90 lines (77 loc) · 2.63 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
/**
* @jest-environment @instantsearch/testutils/jest-environment-jsdom.ts
*/
import { render, screen } from '@testing-library/react';
import React from 'react';
import { createCarouselTool } from '../SearchIndexTool';
import type { ClientSideToolComponentProps } from 'instantsearch-ui-components';
type TestHit = {
objectID: string;
name: string;
__position: number;
};
const mockItemComponent = ({ item }: { item: TestHit }) => (
<div data-testid={`item-${item.objectID}`}>{item.name}</div>
);
describe('createCarouselTool', () => {
describe('SearchLayoutComponent', () => {
test('renders Agent Studio search tool calls', () => {
const tool = createCarouselTool<TestHit>(false, mockItemComponent);
const LayoutComponent = tool.layoutComponent!;
const message: ClientSideToolComponentProps['message'] = {
type: 'tool-algolia_search_index',
state: 'output-available',
toolCallId: 'test-call-id',
input: { query: 'test', number_of_results: 3 },
output: {
hits: [
{ objectID: '1', name: 'Product 1', __position: 1 },
{ objectID: '2', name: 'Product 2', __position: 2 },
],
nbHits: 100,
},
};
render(
<LayoutComponent
message={message}
applyFilters={jest.fn()}
onClose={jest.fn()}
indexUiState={{}}
addToolResult={jest.fn()}
setIndexUiState={jest.fn()}
/>
);
expect(screen.getByText('Product 1')).toBeInTheDocument();
expect(screen.getByText('Product 2')).toBeInTheDocument();
});
test('renders Algolia MCP Server search tool calls', () => {
const tool = createCarouselTool<TestHit>(false, mockItemComponent);
const LayoutComponent = tool.layoutComponent!;
const message: ClientSideToolComponentProps['message'] = {
type: 'tool-algolia_search_index_products',
state: 'output-available',
toolCallId: 'test-call-id',
input: { query: 'test' },
output: {
hits: [
{ objectID: '1', name: 'MCP Product 1', __position: 1 },
{ objectID: '2', name: 'MCP Product 2', __position: 2 },
],
nbHits: 50,
},
};
render(
<LayoutComponent
message={message}
applyFilters={jest.fn()}
onClose={jest.fn()}
indexUiState={{}}
addToolResult={jest.fn()}
setIndexUiState={jest.fn()}
/>
);
expect(screen.getByText('MCP Product 1')).toBeInTheDocument();
expect(screen.getByText('MCP Product 2')).toBeInTheDocument();
});
});
});