|
|
@@ -1,13 +1,25 @@
|
|
|
// npx jest src/components/chat/__tests__/TaskHeader.test.tsx
|
|
|
|
|
|
import React from "react"
|
|
|
-import { render, screen } from "@testing-library/react"
|
|
|
+import { render, screen, fireEvent } from "@testing-library/react"
|
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
|
|
|
|
|
import type { ProviderSettings } from "@roo-code/types"
|
|
|
|
|
|
import TaskHeader, { TaskHeaderProps } from "../TaskHeader"
|
|
|
|
|
|
+// Mock i18n
|
|
|
+jest.mock("react-i18next", () => ({
|
|
|
+ useTranslation: () => ({
|
|
|
+ t: (key: string) => key, // Simple mock that returns the key
|
|
|
+ }),
|
|
|
+ // Mock initReactI18next to prevent initialization errors in tests
|
|
|
+ initReactI18next: {
|
|
|
+ type: "3rdParty",
|
|
|
+ init: jest.fn(),
|
|
|
+ },
|
|
|
+}))
|
|
|
+
|
|
|
// Mock the vscode API
|
|
|
jest.mock("@/utils/vscode", () => ({
|
|
|
vscode: {
|
|
|
@@ -28,7 +40,7 @@ jest.mock("@src/context/ExtensionStateContext", () => ({
|
|
|
apiKey: "test-api-key", // Add relevant fields
|
|
|
apiModelId: "claude-3-opus-20240229", // Add relevant fields
|
|
|
} as ProviderSettings, // Optional: Add type assertion if ProviderSettings is imported
|
|
|
- currentTaskItem: null,
|
|
|
+ currentTaskItem: { id: "test-task-id" },
|
|
|
}),
|
|
|
}))
|
|
|
|
|
|
@@ -79,4 +91,25 @@ describe("TaskHeader", () => {
|
|
|
renderTaskHeader({ totalCost: NaN })
|
|
|
expect(screen.queryByText(/\$/)).not.toBeInTheDocument()
|
|
|
})
|
|
|
+
|
|
|
+ it("should render the condense context button", () => {
|
|
|
+ renderTaskHeader()
|
|
|
+ expect(screen.getByTitle("chat:task.condenseContext")).toBeInTheDocument()
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should call handleCondenseContext when condense context button is clicked", () => {
|
|
|
+ const handleCondenseContext = jest.fn()
|
|
|
+ renderTaskHeader({ handleCondenseContext })
|
|
|
+ const condenseButton = screen.getByTitle("chat:task.condenseContext")
|
|
|
+ fireEvent.click(condenseButton)
|
|
|
+ expect(handleCondenseContext).toHaveBeenCalledWith("test-task-id")
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should disable the condense context button when buttonsDisabled is true", () => {
|
|
|
+ const handleCondenseContext = jest.fn()
|
|
|
+ renderTaskHeader({ buttonsDisabled: true, handleCondenseContext })
|
|
|
+ const condenseButton = screen.getByTitle("chat:task.condenseContext")
|
|
|
+ fireEvent.click(condenseButton)
|
|
|
+ expect(handleCondenseContext).not.toHaveBeenCalled()
|
|
|
+ })
|
|
|
})
|