Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix(terminal): correct data-testid placement, use nullish coalescing,…
… and harden test patterns (#119)

- TerminalSettings.tsx: move data-testid from Radix <Select> root
  (no DOM node) to <SelectTrigger> button so the attribute survives
  in production; replace || with ?? for the terminalProfile sentinel
  fallback so empty string is not incorrectly replaced; export
  DEFAULT_PROFILE_VALUE for reuse in tests.
- TerminalSettings.profile.spec.tsx: import DEFAULT_PROFILE_VALUE,
  replace hardcoded sentinel strings; adopt rerender() over
  cleanup()+render() so onTerminalProfilePickerOpened is preserved
  across re-renders; remove unused cleanup import.
- Remove PR screenshots from docs/ (after1.png, after2.png,
  before.png).
  • Loading branch information
F915 committed Jun 10, 2026
commit 6745500490a53bac9990a78c32ba640a3fbe4ba6
Binary file removed docs/after1.png
Comment thread
F915 marked this conversation as resolved.
Resolved
Binary file not shown.
Binary file removed docs/after2.png
Binary file not shown.
Binary file removed docs/before.png
Binary file not shown.
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/TerminalSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type TerminalSettingsProps = HTMLAttributes<HTMLDivElement> & {

// Sentinel value that maps to `undefined` (use VS Code's default shell).
// The Select component cannot accept empty-string item values.
const DEFAULT_PROFILE_VALUE = "__zoo_code_follow_vscode_sentinel__"
export const DEFAULT_PROFILE_VALUE = "__zoo_code_follow_vscode_sentinel__"

export const TerminalSettings = ({
terminalOutputPreviewSize,
Expand Down Expand Up @@ -203,15 +203,14 @@ export const TerminalSettings = ({
</label>

<Select
value={terminalProfile || DEFAULT_PROFILE_VALUE}
value={terminalProfile ?? DEFAULT_PROFILE_VALUE}
onValueChange={(value) =>
setCachedStateField(
"terminalProfile",
value === DEFAULT_PROFILE_VALUE ? undefined : value,
)
}
data-testid="terminal-profile-dropdown">
<SelectTrigger className="w-full">
}>
<SelectTrigger className="w-full" data-testid="terminal-profile-dropdown">
<SelectValue placeholder={t("settings:common.select")} />
</SelectTrigger>
<SelectContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import * as React from "react"

import { render, screen, fireEvent, act, cleanup } from "@/utils/test-utils"
import { render, screen, fireEvent, act } from "@/utils/test-utils"

import { TerminalSettings } from "../TerminalSettings"
import { TerminalSettings, DEFAULT_PROFILE_VALUE } from "../TerminalSettings"

// Mock translation hook to echo keys
vi.mock("@/i18n/TranslationContext", () => ({
Expand Down Expand Up @@ -56,16 +56,16 @@ function renderSelectChildren(children: any, onValueChange: (value: string) => v
return React.Children.map(children, (child: any) => {
if (!child || typeof child !== "object") return child
const itemValue = child.props?.value ?? child.props?.["data-item-value"]
if (child.props?.children && itemValue === undefined) {
return renderSelectChildren(child.props.children, onValueChange)
}
if (itemValue !== undefined) {
return (
<button data-testid={`option-${itemValue}`} onClick={() => onValueChange(itemValue)}>
{child.props.children}
</button>
)
}
if (child.props?.children) {
return React.cloneElement(child, {}, renderSelectChildren(child.props.children, onValueChange))
}
return child
})
}
Expand All @@ -78,15 +78,15 @@ describe("TerminalSettings unified profile dropdown", () => {
const setup = (terminalProfile?: string) => {
const setCachedStateField = vi.fn()
const onTerminalProfilePickerOpened = vi.fn()
render(
const { rerender } = render(
<TerminalSettings
terminalShellIntegrationDisabled={false}
terminalProfile={terminalProfile}
onTerminalProfilePickerOpened={onTerminalProfilePickerOpened}
setCachedStateField={setCachedStateField}
/>,
)
return { onTerminalProfilePickerOpened, setCachedStateField }
return { onTerminalProfilePickerOpened, setCachedStateField, rerender }
}

it("requests the terminal profile names on mount via the allowlisted message", () => {
Expand All @@ -99,13 +99,13 @@ describe("TerminalSettings unified profile dropdown", () => {
setup()
const dropdown = screen.getByTestId("terminal-profile-dropdown")
expect(dropdown).toBeInTheDocument()
expect(dropdown.getAttribute("data-value")).toBe("__zoo_code_follow_vscode_sentinel__")
expect(dropdown.closest('[data-testid="select"]')?.getAttribute("data-value")).toBe(DEFAULT_PROFILE_VALUE)
// Configure button visible because "Following VS Code profile" is selected
expect(screen.getByTestId("terminal-profile-configure-button")).toBeInTheDocument()
})

it("selects a specific profile and hides the Configure button", () => {
const { setCachedStateField } = setup()
const { setCachedStateField, onTerminalProfilePickerOpened, rerender } = setup()

act(() => {
window.dispatchEvent(
Expand All @@ -119,12 +119,11 @@ describe("TerminalSettings unified profile dropdown", () => {
fireEvent.click(screen.getByTestId("option-Git Bash"))
expect(setCachedStateField).toHaveBeenCalledWith("terminalProfile", "Git Bash")

// Re-render with profile selected (cleanup first to avoid stale DOM from first render)
cleanup()
render(
rerender(
<TerminalSettings
terminalShellIntegrationDisabled={false}
terminalProfile="Git Bash"
onTerminalProfilePickerOpened={onTerminalProfilePickerOpened}
setCachedStateField={setCachedStateField}
/>,
)
Expand All @@ -144,7 +143,7 @@ describe("TerminalSettings unified profile dropdown", () => {
)
})

fireEvent.click(screen.getByTestId("option-__zoo_code_follow_vscode_sentinel__"))
fireEvent.click(screen.getByTestId(`option-${DEFAULT_PROFILE_VALUE}`))
expect(setCachedStateField).toHaveBeenCalledWith("terminalProfile", undefined)
})

Expand Down
Loading