Skip to content

Commit cf44525

Browse files
committed
fix: address PR review feedback for mode display indicators
- Changed from findModeBySlug to getModeBySlug for better mode resolution - Removed unnecessary 'items-center' CSS class from ModeBadge - Simplified mock setup in TaskHeader.spec.tsx for better maintainability - Improved tooltip test clarity in ModeBadge.spec.tsx - All tests passing successfully
1 parent 7612005 commit cf44525

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

webview-ui/src/components/chat/__tests__/TaskHeader.spec.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ vi.mock("@vscode/webview-ui-toolkit/react", () => ({
3333
}))
3434

3535
// Mock the ExtensionStateContext
36-
const { mockGetCurrentTaskItem, mockSetCurrentTaskItem } = vi.hoisted(() => {
37-
let currentTaskItem: any = { id: "test-task-id", mode: "code" }
38-
return {
39-
mockGetCurrentTaskItem: () => currentTaskItem,
40-
mockSetCurrentTaskItem: (newItem: any) => {
41-
currentTaskItem = newItem
42-
},
43-
}
44-
})
36+
const mockCurrentTaskItem = vi.hoisted(() => ({
37+
value: { id: "test-task-id", mode: "code" } as any,
38+
}))
4539

4640
vi.mock("@src/context/ExtensionStateContext", () => ({
4741
useExtensionState: () => ({
@@ -50,7 +44,7 @@ vi.mock("@src/context/ExtensionStateContext", () => ({
5044
apiKey: "test-api-key",
5145
apiModelId: "claude-3-opus-20240229",
5246
} as ProviderSettings,
53-
currentTaskItem: mockGetCurrentTaskItem(),
47+
currentTaskItem: mockCurrentTaskItem.value,
5448
customModes: [],
5549
}),
5650
}))
@@ -147,22 +141,16 @@ describe("TaskHeader", () => {
147141

148142
it("should not display mode badge when currentTaskItem has no mode", () => {
149143
// Override the mock for this test
150-
const originalTaskItem = mockGetCurrentTaskItem()
151-
mockSetCurrentTaskItem({
144+
const originalTaskItem = mockCurrentTaskItem.value
145+
mockCurrentTaskItem.value = {
152146
id: "test-task-id",
153-
number: 1,
154-
ts: Date.now(),
155-
task: "Test task",
156-
tokensIn: 100,
157-
tokensOut: 50,
158-
totalCost: 0.05,
159147
// No mode property
160-
})
148+
}
161149

162150
renderTaskHeader()
163151
expect(screen.queryByTestId("mode-badge")).not.toBeInTheDocument()
164152

165153
// Restore original mock
166-
mockSetCurrentTaskItem(originalTaskItem)
154+
mockCurrentTaskItem.value = originalTaskItem
167155
})
168156
})

webview-ui/src/components/common/ModeBadge.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react"
2-
import { findModeBySlug, getAllModes } from "@roo/modes"
2+
import { getModeBySlug } from "@roo/modes"
33
import { useExtensionState } from "@/context/ExtensionStateContext"
44
import { StandardTooltip } from "@/components/ui"
55
import { cn } from "@/lib/utils"
@@ -16,16 +16,15 @@ export const ModeBadge: React.FC<ModeBadgeProps> = ({ modeSlug, className }) =>
1616
return null
1717
}
1818

19-
// Get all modes (built-in + custom)
20-
const allModes = getAllModes(customModes)
21-
const mode = findModeBySlug(modeSlug, allModes)
19+
// Get mode using getModeBySlug which checks custom modes first, then built-in
20+
const mode = getModeBySlug(modeSlug, customModes)
2221
const displayName = mode?.name || modeSlug // Fallback to slug if mode deleted
2322

2423
return (
2524
<StandardTooltip content={displayName}>
2625
<span
2726
className={cn(
28-
"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium",
27+
"inline-flex px-2 py-0.5 rounded text-xs font-medium",
2928
"bg-vscode-badge-background text-vscode-badge-foreground",
3029
"max-w-[120px] truncate",
3130
className,

webview-ui/src/components/common/__tests__/ModeBadge.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { ModeBadge } from "../ModeBadge"
33

44
// Mock the shared modes module
55
vi.mock("@roo/modes", () => ({
6-
findModeBySlug: vi.fn((slug, _modes) => {
6+
getModeBySlug: vi.fn((slug, _customModes) => {
77
if (slug === "code") return { slug: "code", name: "💻 Code" }
88
if (slug === "architect") return { slug: "architect", name: "🏗️ Architect" }
99
if (slug === "custom") return { slug: "custom", name: "Very Long Custom Mode Name That Should Be Truncated" }
1010
return undefined
1111
}),
12-
getAllModes: vi.fn(() => []),
1312
}))
1413

1514
// Mock ExtensionStateContext
@@ -42,10 +41,11 @@ describe("ModeBadge", () => {
4241
expect(badge).toHaveClass("max-w-[120px]")
4342
})
4443

45-
it("shows full name in tooltip", async () => {
44+
it("shows full name in tooltip", () => {
4645
render(<ModeBadge modeSlug="custom" />)
47-
// Tooltip content would be tested with user interaction
48-
// This is a simplified test
49-
expect(screen.getByText(/Very Long Custom Mode Name/)).toBeInTheDocument()
46+
// The tooltip content is set via the StandardTooltip's content prop
47+
// We verify the text is rendered in the badge itself
48+
const badge = screen.getByText(/Very Long Custom Mode Name/)
49+
expect(badge).toBeInTheDocument()
5050
})
5151
})

0 commit comments

Comments
 (0)