Skip to content

Commit 0f37ea7

Browse files
committed
fix: update ContextManagementSettings tests to handle UI component mocks correctly
- Added role='combobox' to Select mock to fix accessibility test failures - Fixed checkbox assertions to target the input element instead of the wrapper - Added keyboard event handling to Slider mock for arrow key interactions - All 31 tests now pass successfully
1 parent f24ea54 commit 0f37ea7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

webview-ui/src/components/settings/__tests__/ContextManagementSettings.spec.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ vi.mock("@/components/ui", () => ({
2424
type="range"
2525
value={value?.[0] ?? 0}
2626
onChange={(e) => onValueChange([parseFloat(e.target.value)])}
27+
onKeyDown={(e) => {
28+
const currentValue = value?.[0] ?? 0
29+
if (e.key === "ArrowRight") {
30+
onValueChange([currentValue + 1])
31+
} else if (e.key === "ArrowLeft") {
32+
onValueChange([currentValue - 1])
33+
}
34+
}}
2735
data-testid={dataTestId}
2836
disabled={disabled}
2937
role="slider"
@@ -37,7 +45,11 @@ vi.mock("@/components/ui", () => ({
3745
{children}
3846
</button>
3947
),
40-
Select: ({ children, ...props }: any) => <div {...props}>{children}</div>,
48+
Select: ({ children, ...props }: any) => (
49+
<div role="combobox" {...props}>
50+
{children}
51+
</div>
52+
),
4153
SelectTrigger: ({ children, ...props }: any) => <div {...props}>{children}</div>,
4254
SelectValue: ({ children, ...props }: any) => <div {...props}>{children}</div>,
4355
SelectContent: ({ children, ...props }: any) => <div {...props}>{children}</div>,
@@ -384,7 +396,8 @@ describe("ContextManagementSettings", () => {
384396
render(<ContextManagementSettings {...props} />)
385397

386398
const checkbox = screen.getByTestId("auto-condense-context-checkbox")
387-
expect(checkbox).toBeChecked()
399+
const input = checkbox.querySelector('input[type="checkbox"]')
400+
expect(input).toBeChecked()
388401

389402
// Toggle off
390403
fireEvent.click(checkbox)
@@ -429,7 +442,8 @@ describe("ContextManagementSettings", () => {
429442
render(<ContextManagementSettings {...propsWithMaxReadFileLine} />)
430443

431444
const checkbox = screen.getByTestId("max-read-file-always-full-checkbox")
432-
expect(checkbox).toBeChecked()
445+
const input = checkbox.querySelector('input[type="checkbox"]')
446+
expect(input).toBeChecked()
433447
})
434448

435449
it("handles boundary values for sliders", () => {

0 commit comments

Comments
 (0)