|
@@ -1,18 +1,33 @@
|
|
|
// npx jest src/components/chat/__tests__/CommandExecution.test.tsx
|
|
// npx jest src/components/chat/__tests__/CommandExecution.test.tsx
|
|
|
|
|
|
|
|
import React from "react"
|
|
import React from "react"
|
|
|
-import { render, screen, fireEvent } from "@testing-library/react"
|
|
|
|
|
|
|
+import { render, screen } from "@testing-library/react"
|
|
|
|
|
|
|
|
import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext"
|
|
import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext"
|
|
|
|
|
|
|
|
import { CommandExecution } from "../CommandExecution"
|
|
import { CommandExecution } from "../CommandExecution"
|
|
|
|
|
|
|
|
-jest.mock("../../../components/common/CodeBlock")
|
|
|
|
|
-
|
|
|
|
|
jest.mock("@src/lib/utils", () => ({
|
|
jest.mock("@src/lib/utils", () => ({
|
|
|
cn: (...inputs: any[]) => inputs.filter(Boolean).join(" "),
|
|
cn: (...inputs: any[]) => inputs.filter(Boolean).join(" "),
|
|
|
}))
|
|
}))
|
|
|
|
|
|
|
|
|
|
+jest.mock("lucide-react", () => ({
|
|
|
|
|
+ ChevronDown: () => <div data-testid="chevron-down">ChevronDown</div>,
|
|
|
|
|
+}))
|
|
|
|
|
+
|
|
|
|
|
+jest.mock("react-virtuoso", () => ({
|
|
|
|
|
+ Virtuoso: React.forwardRef(({ totalCount, itemContent }: any, ref: any) => (
|
|
|
|
|
+ <div ref={ref} data-testid="virtuoso-container">
|
|
|
|
|
+ {Array.from({ length: totalCount }).map((_, index) => (
|
|
|
|
|
+ <div key={index} data-testid={`virtuoso-item-${index}`}>
|
|
|
|
|
+ {itemContent(index)}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )),
|
|
|
|
|
+ VirtuosoHandle: jest.fn(),
|
|
|
|
|
+}))
|
|
|
|
|
+
|
|
|
describe("CommandExecution", () => {
|
|
describe("CommandExecution", () => {
|
|
|
const renderComponent = (command: string, output: string) => {
|
|
const renderComponent = (command: string, output: string) => {
|
|
|
return render(
|
|
return render(
|
|
@@ -25,34 +40,24 @@ describe("CommandExecution", () => {
|
|
|
it("renders command output with virtualized list", () => {
|
|
it("renders command output with virtualized list", () => {
|
|
|
const testOutput = "Line 1\nLine 2\nLine 3"
|
|
const testOutput = "Line 1\nLine 2\nLine 3"
|
|
|
renderComponent("ls", testOutput)
|
|
renderComponent("ls", testOutput)
|
|
|
- const codeBlock = screen.getByTestId("mock-code-block")
|
|
|
|
|
- expect(codeBlock).toHaveTextContent("ls")
|
|
|
|
|
-
|
|
|
|
|
- fireEvent.click(screen.getByText("commandOutput"))
|
|
|
|
|
- const outputBlock = screen.getAllByTestId("mock-code-block")[1]
|
|
|
|
|
-
|
|
|
|
|
- expect(outputBlock).toHaveTextContent("Line 1")
|
|
|
|
|
- expect(outputBlock).toHaveTextContent("Line 2")
|
|
|
|
|
- expect(outputBlock).toHaveTextContent("Line 3")
|
|
|
|
|
|
|
+ expect(screen.getByTestId("virtuoso-container")).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.getByText("Line 1")).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.getByText("Line 2")).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.getByText("Line 3")).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("handles empty output", () => {
|
|
it("handles empty output", () => {
|
|
|
renderComponent("ls", "")
|
|
renderComponent("ls", "")
|
|
|
- const codeBlock = screen.getByTestId("mock-code-block")
|
|
|
|
|
- expect(codeBlock).toHaveTextContent("ls")
|
|
|
|
|
- expect(screen.queryByText("commandOutput")).not.toBeInTheDocument()
|
|
|
|
|
- expect(screen.queryAllByTestId("mock-code-block")).toHaveLength(1)
|
|
|
|
|
|
|
+ expect(screen.getByTestId("virtuoso-container")).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.getByTestId("virtuoso-item-0")).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.queryByTestId("virtuoso-item-1")).not.toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("handles large output", () => {
|
|
it("handles large output", () => {
|
|
|
const largeOutput = Array.from({ length: 1000 }, (_, i) => `Line ${i + 1}`).join("\n")
|
|
const largeOutput = Array.from({ length: 1000 }, (_, i) => `Line ${i + 1}`).join("\n")
|
|
|
renderComponent("ls", largeOutput)
|
|
renderComponent("ls", largeOutput)
|
|
|
- const codeBlock = screen.getByTestId("mock-code-block")
|
|
|
|
|
- expect(codeBlock).toHaveTextContent("ls")
|
|
|
|
|
-
|
|
|
|
|
- fireEvent.click(screen.getByText("commandOutput"))
|
|
|
|
|
- const outputBlock = screen.getAllByTestId("mock-code-block")[1]
|
|
|
|
|
- expect(outputBlock).toHaveTextContent("Line 1")
|
|
|
|
|
- expect(outputBlock).toHaveTextContent("Line 1000")
|
|
|
|
|
|
|
+ expect(screen.getByTestId("virtuoso-container")).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.getByText("Line 1")).toBeInTheDocument()
|
|
|
|
|
+ expect(screen.getByText("Line 1000")).toBeInTheDocument()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|