11// npx jest src/components/chat/__tests__/CommandExecution.test.tsx
22
33import React from "react"
4- import { render , screen , fireEvent } from "@testing-library/react"
4+ import { render , screen } from "@testing-library/react"
55
66import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext"
77
88import { CommandExecution } from "../CommandExecution"
99
10- jest . mock ( "../../../components/common/CodeBlock" )
11-
1210jest . mock ( "@src/lib/utils" , ( ) => ( {
1311 cn : ( ...inputs : any [ ] ) => inputs . filter ( Boolean ) . join ( " " ) ,
1412} ) )
1513
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+
1631describe ( "CommandExecution" , ( ) => {
1732 const renderComponent = ( command : string , output : string ) => {
1833 return render (
@@ -25,34 +40,24 @@ describe("CommandExecution", () => {
2540 it ( "renders command output with virtualized list" , ( ) => {
2641 const testOutput = "Line 1\nLine 2\nLine 3"
2742 renderComponent ( "ls" , testOutput )
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" )
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 ( )
3747 } )
3848
3949 it ( "handles empty output" , ( ) => {
4050 renderComponent ( "ls" , "" )
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 )
51+ expect ( screen . getByTestId ( "virtuoso-container" ) ) . toBeInTheDocument ( )
52+ expect ( screen . getByTestId ( "virtuoso-item-0" ) ) . toBeInTheDocument ( )
53+ expect ( screen . queryByTestId ( "virtuoso-item-1" ) ) . not . toBeInTheDocument ( )
4554 } )
4655
4756 it ( "handles large output" , ( ) => {
4857 const largeOutput = Array . from ( { length : 1000 } , ( _ , i ) => `Line ${ i + 1 } ` ) . join ( "\n" )
4958 renderComponent ( "ls" , largeOutput )
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" )
59+ expect ( screen . getByTestId ( "virtuoso-container" ) ) . toBeInTheDocument ( )
60+ expect ( screen . getByText ( "Line 1" ) ) . toBeInTheDocument ( )
61+ expect ( screen . getByText ( "Line 1000" ) ) . toBeInTheDocument ( )
5762 } )
5863} )
0 commit comments