This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathErrorRow.spec.tsx
More file actions
82 lines (69 loc) · 2.23 KB
/
Copy pathErrorRow.spec.tsx
File metadata and controls
82 lines (69 loc) · 2.23 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
import React from "react"
import { render, screen, fireEvent } from "@/utils/test-utils"
import { vscode } from "@/utils/vscode"
import { ErrorRow } from "../ErrorRow"
// Mock vscode webview messaging
vi.mock("@/utils/vscode", () => ({
vscode: {
postMessage: vi.fn(),
},
}))
// Mock ExtensionState context
vi.mock("@/context/ExtensionStateContext", () => ({
useExtensionState: () => ({
version: "1.0.0",
apiConfiguration: {},
}),
}))
// Mock selected model hook
vi.mock("@/components/ui/hooks/useSelectedModel", () => ({
useSelectedModel: () => ({
provider: "test-provider",
id: "test-model",
}),
}))
// Mock i18n
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => {
const map: Record<string, string> = {
"chat:error": "Error",
"chat:errorDetails.title": "Error Details",
"chat:errorDetails.copyToClipboard": "Copy to Clipboard",
"chat:errorDetails.copied": "Copied!",
"chat:errorDetails.diagnostics": "Get detailed error info",
}
return map[key] ?? key
},
}),
initReactI18next: {
type: "3rdParty",
init: vi.fn(),
},
}))
describe("ErrorRow diagnostics download", () => {
it("sends downloadErrorDiagnostics message with error metadata", () => {
const mockPostMessage = vi.mocked(vscode.postMessage)
render(<ErrorRow type="error" message="Something went wrong" errorDetails="Detailed error body" />)
// Open the Error Details dialog via the info button
const infoButton = screen.getByRole("button", { name: "Error Details" })
fireEvent.click(infoButton)
// Click the diagnostics button
const downloadButton = screen.getByRole("button", { name: "Get detailed error info" })
fireEvent.click(downloadButton)
expect(mockPostMessage).toHaveBeenCalled()
const call = mockPostMessage.mock.calls.find(([arg]) => arg.type === "downloadErrorDiagnostics")
expect(call).toBeTruthy()
if (!call) return
const payload = call[0] as { type: string; values?: any }
expect(payload.values).toBeTruthy()
if (!payload.values) return
expect(payload.values).toMatchObject({
version: "1.0.0",
provider: "test-provider",
model: "test-model",
})
// Timestamp is generated at runtime, but should be a string
expect(typeof payload.values.timestamp).toBe("string")
})
})