-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathChatRow.mcp-server-response.spec.tsx
More file actions
106 lines (90 loc) · 2.9 KB
/
Copy pathChatRow.mcp-server-response.spec.tsx
File metadata and controls
106 lines (90 loc) · 2.9 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
import React from "react"
import { render, screen } from "@/utils/test-utils"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext"
import { ChatRowContent } from "../ChatRow"
// Mock i18n
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => key,
i18n: {
exists: () => false,
},
}),
Trans: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
initReactI18next: { type: "3rdParty", init: () => {} },
}))
const queryClient = new QueryClient()
function renderChatRow(message: any) {
return render(
<ExtensionStateContextProvider>
<QueryClientProvider client={queryClient}>
<ChatRowContent
message={message}
isExpanded={false}
isLast={false}
isStreaming={false}
onToggleExpand={() => {}}
onSuggestionClick={() => {}}
onBatchFileResponse={() => {}}
onFollowUpUnmount={() => {}}
isFollowUpAnswered={false}
/>
</QueryClientProvider>
</ExtensionStateContextProvider>,
)
}
describe("ChatRow - mcp_server_response", () => {
it("renders images attached to the MCP server response", () => {
const message: any = {
type: "say",
say: "mcp_server_response",
ts: Date.now(),
partial: false,
text: "Screenshot captured: 1152x648",
images: ["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ"],
}
renderChatRow(message)
const img = screen.getByRole("img")
expect(img).toHaveAttribute("src", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ")
})
it("renders multiple images attached to the MCP server response", () => {
const message: any = {
type: "say",
say: "mcp_server_response",
ts: Date.now(),
partial: false,
text: "[2 image(s) received]",
images: ["data:image/png;base64,image1data", "data:image/png;base64,image2data"],
}
renderChatRow(message)
const imgs = screen.getAllByRole("img")
expect(imgs).toHaveLength(2)
expect(imgs[0]).toHaveAttribute("src", "data:image/png;base64,image1data")
expect(imgs[1]).toHaveAttribute("src", "data:image/png;base64,image2data")
})
it("renders only the text when the MCP server response has no images", () => {
const message: any = {
type: "say",
say: "mcp_server_response",
ts: Date.now(),
partial: false,
text: "Plain text result",
}
renderChatRow(message)
expect(screen.queryByRole("img")).toBeNull()
})
it("renders attached images for say types that use the default renderer", () => {
const message: any = {
type: "say",
say: "command_output",
ts: Date.now(),
partial: false,
text: "Some output",
images: ["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ"],
}
renderChatRow(message)
const img = screen.getByRole("img")
expect(img).toHaveAttribute("src", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ")
})
})