-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add mode display indicators on task cards (#6493) #6498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 31 commits
efaaed9
57d3fbe
ef61905
f5a51c4
bcbf329
80413c0
ab10140
39c5cf7
00a0b63
080b61b
7a5ad14
2c73ff2
05ccf57
fdb1f35
10ce509
ab1f9fc
74fd8b4
6745c8f
faf2ee5
b2dadf9
f648e4c
a6d1e60
be90907
ed3a077
856313f
4dd68ea
b10fa5e
f016d7b
23855f2
3803c29
7612005
cf44525
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import React from "react" | ||
| import { findModeBySlug, getAllModes } from "@roo/modes" | ||
MuriloFP marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import { useExtensionState } from "@/context/ExtensionStateContext" | ||
| import { StandardTooltip } from "@/components/ui" | ||
| import { cn } from "@/lib/utils" | ||
|
|
||
| interface ModeBadgeProps { | ||
| modeSlug?: string | ||
| className?: string | ||
| } | ||
|
|
||
| export const ModeBadge: React.FC<ModeBadgeProps> = ({ modeSlug, className }) => { | ||
| const { customModes } = useExtensionState() | ||
|
|
||
| if (!modeSlug) { | ||
| return null | ||
| } | ||
|
|
||
| // Get all modes (built-in + custom) | ||
| const allModes = getAllModes(customModes) | ||
| const mode = findModeBySlug(modeSlug, allModes) | ||
|
||
| const displayName = mode?.name || modeSlug // Fallback to slug if mode deleted | ||
|
|
||
| return ( | ||
| <StandardTooltip content={displayName}> | ||
| <span | ||
| className={cn( | ||
| "inline-flex items-center px-2 py-0.5 rounded text-xs font-medium", | ||
|
||
| "bg-vscode-badge-background text-vscode-badge-foreground", | ||
| "max-w-[120px] truncate", | ||
| className, | ||
| )}> | ||
| {displayName} | ||
| </span> | ||
| </StandardTooltip> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { render, screen } from "@/utils/test-utils" | ||
| import { ModeBadge } from "../ModeBadge" | ||
|
|
||
| // Mock the shared modes module | ||
| vi.mock("@roo/modes", () => ({ | ||
| findModeBySlug: vi.fn((slug, _modes) => { | ||
| if (slug === "code") return { slug: "code", name: "💻 Code" } | ||
| if (slug === "architect") return { slug: "architect", name: "🏗️ Architect" } | ||
| if (slug === "custom") return { slug: "custom", name: "Very Long Custom Mode Name That Should Be Truncated" } | ||
| return undefined | ||
| }), | ||
| getAllModes: vi.fn(() => []), | ||
| })) | ||
|
|
||
| // Mock ExtensionStateContext | ||
| vi.mock("@/context/ExtensionStateContext", () => ({ | ||
| useExtensionState: () => ({ | ||
| customModes: [], | ||
| }), | ||
| })) | ||
|
|
||
| describe("ModeBadge", () => { | ||
| it("renders mode name when mode exists", () => { | ||
| render(<ModeBadge modeSlug="code" />) | ||
| expect(screen.getByText("💻 Code")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("renders slug as fallback when mode not found", () => { | ||
| render(<ModeBadge modeSlug="deleted-mode" />) | ||
| expect(screen.getByText("deleted-mode")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("returns null when no mode slug provided", () => { | ||
| const { container } = render(<ModeBadge />) | ||
| expect(container.firstChild).toBeNull() | ||
| }) | ||
|
|
||
| it("truncates long mode names", () => { | ||
| render(<ModeBadge modeSlug="custom" />) | ||
| const badge = screen.getByText(/Very Long Custom Mode Name/) | ||
| expect(badge).toHaveClass("truncate") | ||
| expect(badge).toHaveClass("max-w-[120px]") | ||
| }) | ||
|
|
||
| it("shows full name in tooltip", async () => { | ||
|
||
| render(<ModeBadge modeSlug="custom" />) | ||
| // Tooltip content would be tested with user interaction | ||
| // This is a simplified test | ||
| expect(screen.getByText(/Very Long Custom Mode Name/)).toBeInTheDocument() | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock setup here seems quite complex for the test needs. Could we simplify this mock to improve maintainability? The hoisted pattern is good, but the getter/setter functions might be overkill for these tests.