Skip to content

Commit 7ec9381

Browse files
author
Eric Wheeler
committed
test: update CommandExecution tests to use CodeBlock mock
- Replace virtuoso mock with CodeBlock mock to fix shiki import error - Update CodeBlock mock to properly handle source prop - Add proper empty output test case verification - Keep original test values and structure Signed-off-by: Eric Wheeler <[email protected]>
1 parent b342ee4 commit 7ec9381

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
// npx jest src/components/chat/__tests__/CommandExecution.test.tsx
22

33
import React from "react"
4-
import { render, screen } from "@testing-library/react"
4+
import { render, screen, fireEvent } from "@testing-library/react"
55

66
import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext"
77

88
import { CommandExecution } from "../CommandExecution"
99

10+
jest.mock("../../../components/common/CodeBlock")
11+
1012
jest.mock("@src/lib/utils", () => ({
1113
cn: (...inputs: any[]) => inputs.filter(Boolean).join(" "),
1214
}))
1315

14-
jest.mock("lucide-react", () => ({
15-
ChevronDown: () => <div data-testid="chevron-down">ChevronDown</div>,
16-
}))
17-
18-
jest.mock("react-virtuoso", () => ({
19-
Virtuoso: React.forwardRef(({ totalCount, itemContent }: any, ref: any) => (
20-
<div ref={ref} data-testid="virtuoso-container">
21-
{Array.from({ length: totalCount }).map((_, index) => (
22-
<div key={index} data-testid={`virtuoso-item-${index}`}>
23-
{itemContent(index)}
24-
</div>
25-
))}
26-
</div>
27-
)),
28-
VirtuosoHandle: jest.fn(),
29-
}))
30-
3116
describe("CommandExecution", () => {
3217
const renderComponent = (command: string, output: string) => {
3318
return render(
@@ -40,24 +25,34 @@ describe("CommandExecution", () => {
4025
it("renders command output with virtualized list", () => {
4126
const testOutput = "Line 1\nLine 2\nLine 3"
4227
renderComponent("ls", testOutput)
43-
expect(screen.getByTestId("virtuoso-container")).toBeInTheDocument()
44-
expect(screen.getByText("Line 1")).toBeInTheDocument()
45-
expect(screen.getByText("Line 2")).toBeInTheDocument()
46-
expect(screen.getByText("Line 3")).toBeInTheDocument()
28+
const codeBlock = screen.getByTestId("mock-code-block")
29+
expect(codeBlock).toHaveTextContent("ls")
30+
31+
fireEvent.click(screen.getByText("commandOutput"))
32+
const outputBlock = screen.getAllByTestId("mock-code-block")[1]
33+
34+
expect(outputBlock).toHaveTextContent("Line 1")
35+
expect(outputBlock).toHaveTextContent("Line 2")
36+
expect(outputBlock).toHaveTextContent("Line 3")
4737
})
4838

4939
it("handles empty output", () => {
5040
renderComponent("ls", "")
51-
expect(screen.getByTestId("virtuoso-container")).toBeInTheDocument()
52-
expect(screen.getByTestId("virtuoso-item-0")).toBeInTheDocument()
53-
expect(screen.queryByTestId("virtuoso-item-1")).not.toBeInTheDocument()
41+
const codeBlock = screen.getByTestId("mock-code-block")
42+
expect(codeBlock).toHaveTextContent("ls")
43+
expect(screen.queryByText("commandOutput")).not.toBeInTheDocument()
44+
expect(screen.queryAllByTestId("mock-code-block")).toHaveLength(1)
5445
})
5546

5647
it("handles large output", () => {
5748
const largeOutput = Array.from({ length: 1000 }, (_, i) => `Line ${i + 1}`).join("\n")
5849
renderComponent("ls", largeOutput)
59-
expect(screen.getByTestId("virtuoso-container")).toBeInTheDocument()
60-
expect(screen.getByText("Line 1")).toBeInTheDocument()
61-
expect(screen.getByText("Line 1000")).toBeInTheDocument()
50+
const codeBlock = screen.getByTestId("mock-code-block")
51+
expect(codeBlock).toHaveTextContent("ls")
52+
53+
fireEvent.click(screen.getByText("commandOutput"))
54+
const outputBlock = screen.getAllByTestId("mock-code-block")[1]
55+
expect(outputBlock).toHaveTextContent("Line 1")
56+
expect(outputBlock).toHaveTextContent("Line 1000")
6257
})
6358
})
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as React from "react"
22

33
interface CodeBlockProps {
4-
children?: React.ReactNode
4+
source?: string
55
language?: string
66
}
77

8-
const CodeBlock: React.FC<CodeBlockProps> = () => <div data-testid="mock-code-block">Mocked Code Block</div>
8+
const CodeBlock: React.FC<CodeBlockProps> = ({ source = "" }) => <div data-testid="mock-code-block">{source}</div>
99

1010
export default CodeBlock

0 commit comments

Comments
 (0)