Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions webview-ui/src/__tests__/ContextWindowProgress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ jest.mock("@/utils/format", () => ({
formatLargeNumber: jest.fn((num) => num.toString()),
}))

// Mock VSCodeBadge component for all tests
jest.mock("@vscode/webview-ui-toolkit/react", () => ({
VSCodeBadge: ({ children }: { children: React.ReactNode }) => <div data-testid="vscode-badge">{children}</div>,
}))

// Mock ExtensionStateContext since we use useExtensionState
jest.mock("../context/ExtensionStateContext", () => ({
useExtensionState: jest.fn(() => ({
Expand Down
11 changes: 6 additions & 5 deletions webview-ui/src/components/chat/TaskHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next"
import { vscode } from "@/utils/vscode"
import { formatLargeNumber } from "@/utils/format"
import { calculateTokenDistribution, getMaxTokensForModel } from "@/utils/model-utils"
import { Button, Badge } from "@/components/ui"
import { Button } from "@/components/ui"

import { ClineMessage } from "../../../../src/shared/ExtensionMessage"
import { mentionRegexGlobal } from "../../../../src/shared/context-mentions"
Expand All @@ -17,6 +17,7 @@ import Thumbnails from "../common/Thumbnails"
import { normalizeApiConfiguration } from "../settings/ApiOptions"
import { DeleteTaskDialog } from "../history/DeleteTaskDialog"
import { cn } from "@/lib/utils"
import { VSCodeBadge } from "@vscode/webview-ui-toolkit/react"

interface TaskHeaderProps {
task: ClineMessage
Expand Down Expand Up @@ -95,7 +96,7 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
contextTokens={contextTokens || 0}
maxTokens={getMaxTokensForModel(selectedModelInfo, apiConfiguration)}
/>
{!!totalCost && <Badge>${totalCost.toFixed(2)}</Badge>}
{!!totalCost && <VSCodeBadge>${totalCost.toFixed(2)}</VSCodeBadge>}
</div>
)}
{/* Expanded state: Show task text and images */}
Expand Down Expand Up @@ -278,7 +279,7 @@ const ContextWindowProgress = ({ contextWindow, contextTokens, maxTokens }: Cont
/>

{/* Main progress bar container */}
<div className="flex items-center h-1 rounded-[2px] overflow-hidden w-full bg-[color-mix(in_srgb,var(--vscode-badge-foreground)_20%,transparent)]">
<div className="flex items-center h-1 rounded-[2px] overflow-hidden w-full bg-[color-mix(in_srgb,var(--vscode-foreground)_20%,transparent)]">
{/* Current tokens container */}
<div className="relative h-full" style={{ width: `${currentPercent}%` }}>
{/* Invisible overlay for current tokens section */}
Expand All @@ -291,7 +292,7 @@ const ContextWindowProgress = ({ contextWindow, contextTokens, maxTokens }: Cont
data-testid="context-tokens-used"
/>
{/* Current tokens used - darkest */}
<div className="h-full w-full bg-[var(--vscode-badge-foreground)] transition-width duration-300 ease-out" />
<div className="h-full w-full bg-[var(--vscode-foreground)] transition-width duration-300 ease-out" />
</div>

{/* Container for reserved tokens */}
Expand All @@ -305,7 +306,7 @@ const ContextWindowProgress = ({ contextWindow, contextTokens, maxTokens }: Cont
data-testid="context-reserved-tokens"
/>
{/* Reserved for output section - medium gray */}
<div className="h-full w-full bg-[color-mix(in_srgb,var(--vscode-badge-foreground)_30%,transparent)] transition-width duration-300 ease-out" />
<div className="h-full w-full bg-[color-mix(in_srgb,var(--vscode-foreground)_30%,transparent)] transition-width duration-300 ease-out" />
</div>

{/* Empty section (if any) */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jest.mock("@/utils/vscode", () => ({
},
}))

// Mock the VSCodeBadge component
jest.mock("@vscode/webview-ui-toolkit/react", () => ({
VSCodeBadge: ({ children }: { children: React.ReactNode }) => <div data-testid="vscode-badge">{children}</div>,
}))

// Mock the ExtensionStateContext
jest.mock("../../../context/ExtensionStateContext", () => ({
useExtensionState: () => ({
Expand Down
6 changes: 0 additions & 6 deletions webview-ui/src/i18n/__tests__/TranslationContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react"
import { render } from "@testing-library/react"
import "@testing-library/jest-dom"
import TranslationProvider, { useAppTranslation } from "../TranslationContext"
import { setupI18nForTests } from "../test-utils"

// Mock the useExtensionState hook
jest.mock("@/context/ExtensionStateContext", () => ({
Expand All @@ -23,11 +22,6 @@ const TestComponent = () => {
}

describe("TranslationContext", () => {
beforeAll(() => {
// Initialize i18next with test translations
setupI18nForTests()
})

it("should provide translations via context", () => {
const { getByTestId } = render(
<TranslationProvider>
Expand Down
4 changes: 4 additions & 0 deletions webview-ui/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import "@testing-library/jest-dom"
import { setupI18nForTests } from "./i18n/test-utils"

// Set up i18n for all tests
setupI18nForTests()

// Mock crypto.getRandomValues
Object.defineProperty(window, "crypto", {
Expand Down