33import React from "react"
44import { render , screen } from "@testing-library/react"
55
6+ import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext"
7+
68import { CommandExecution } from "../CommandExecution"
79
810jest . mock ( "@src/lib/utils" , ( ) => ( {
911 cn : ( ...inputs : any [ ] ) => inputs . filter ( Boolean ) . join ( " " ) ,
1012} ) )
1113
14+ jest . mock ( "lucide-react" , ( ) => ( {
15+ ChevronDown : ( ) => < div data-testid = "chevron-down" > ChevronDown</ div > ,
16+ } ) )
17+
1218jest . mock ( "react-virtuoso" , ( ) => ( {
1319 Virtuoso : React . forwardRef ( ( { totalCount, itemContent } : any , ref : any ) => (
1420 < div ref = { ref } data-testid = "virtuoso-container" >
@@ -23,25 +29,33 @@ jest.mock("react-virtuoso", () => ({
2329} ) )
2430
2531describe ( "CommandExecution" , ( ) => {
32+ const renderComponent = ( command : string , output : string ) => {
33+ return render (
34+ < ExtensionStateContextProvider >
35+ < CommandExecution command = { command } output = { output } />
36+ </ ExtensionStateContextProvider > ,
37+ )
38+ }
39+
2640 it ( "renders command output with virtualized list" , ( ) => {
2741 const testOutput = "Line 1\nLine 2\nLine 3"
28- render ( < CommandExecution command = "ls" output = { testOutput } isExpanded = { false } /> )
42+ renderComponent ( "ls" , testOutput )
2943 expect ( screen . getByTestId ( "virtuoso-container" ) ) . toBeInTheDocument ( )
3044 expect ( screen . getByText ( "Line 1" ) ) . toBeInTheDocument ( )
3145 expect ( screen . getByText ( "Line 2" ) ) . toBeInTheDocument ( )
3246 expect ( screen . getByText ( "Line 3" ) ) . toBeInTheDocument ( )
3347 } )
3448
3549 it ( "handles empty output" , ( ) => {
36- render ( < CommandExecution command = "ls" output = "" isExpanded = { false } /> )
50+ renderComponent ( "ls" , "" )
3751 expect ( screen . getByTestId ( "virtuoso-container" ) ) . toBeInTheDocument ( )
3852 expect ( screen . getByTestId ( "virtuoso-item-0" ) ) . toBeInTheDocument ( )
3953 expect ( screen . queryByTestId ( "virtuoso-item-1" ) ) . not . toBeInTheDocument ( )
4054 } )
4155
4256 it ( "handles large output" , ( ) => {
4357 const largeOutput = Array . from ( { length : 1000 } , ( _ , i ) => `Line ${ i + 1 } ` ) . join ( "\n" )
44- render ( < CommandExecution command = "ls" output = { largeOutput } isExpanded = { false } /> )
58+ renderComponent ( "ls" , largeOutput )
4559 expect ( screen . getByTestId ( "virtuoso-container" ) ) . toBeInTheDocument ( )
4660 expect ( screen . getByText ( "Line 1" ) ) . toBeInTheDocument ( )
4761 expect ( screen . getByText ( "Line 1000" ) ) . toBeInTheDocument ( )
0 commit comments