11// npx jest src/components/chat/__tests__/TaskHeader.test.tsx
22
33import React from "react"
4- import { render , screen } from "@testing-library/react"
4+ import { render , screen , fireEvent } from "@testing-library/react"
55import { QueryClient , QueryClientProvider } from "@tanstack/react-query"
66
77import type { ProviderSettings } from "@roo-code/types"
88
99import TaskHeader , { TaskHeaderProps } from "../TaskHeader"
1010
11+ // Mock i18n
12+ jest . mock ( "react-i18next" , ( ) => ( {
13+ useTranslation : ( ) => ( {
14+ t : ( key : string ) => key , // Simple mock that returns the key
15+ } ) ,
16+ } ) )
17+
1118// Mock the vscode API
1219jest . mock ( "@/utils/vscode" , ( ) => ( {
1320 vscode : {
@@ -28,7 +35,7 @@ jest.mock("@src/context/ExtensionStateContext", () => ({
2835 apiKey : "test-api-key" , // Add relevant fields
2936 apiModelId : "claude-3-opus-20240229" , // Add relevant fields
3037 } as ProviderSettings , // Optional: Add type assertion if ProviderSettings is imported
31- currentTaskItem : null ,
38+ currentTaskItem : { id : "test-task-id" } , // Add a mock currentTaskItem for the condense button
3239 } ) ,
3340} ) )
3441
@@ -79,4 +86,23 @@ describe("TaskHeader", () => {
7986 renderTaskHeader ( { totalCost : NaN } )
8087 expect ( screen . queryByText ( / \$ / ) ) . not . toBeInTheDocument ( )
8188 } )
89+
90+ it ( "should render the condense context button" , ( ) => {
91+ renderTaskHeader ( )
92+ expect ( screen . getByTitle ( "chat:task.condenseContext" ) ) . toBeInTheDocument ( )
93+ } )
94+
95+ it ( "should call handleCondenseContext when condense context button is clicked" , ( ) => {
96+ const handleCondenseContext = jest . fn ( )
97+ renderTaskHeader ( { handleCondenseContext } )
98+ const condenseButton = screen . getByTitle ( "chat:task.condenseContext" )
99+ fireEvent . click ( condenseButton )
100+ expect ( handleCondenseContext ) . toHaveBeenCalledWith ( "test-task-id" )
101+ } )
102+
103+ it ( "should disable the condense context button when buttonsDisabled is true" , ( ) => {
104+ renderTaskHeader ( { buttonsDisabled : true } )
105+ const condenseButton = screen . getByTitle ( "chat:task.condenseContext" )
106+ expect ( condenseButton ) . toBeDisabled ( )
107+ } )
82108} )
0 commit comments