11// npx vitest src/components/settings/__tests__/CheckpointSettings.spec.tsx
22
3+ import type { ReactNode } from "react"
34import { render , screen , fireEvent } from "@/utils/test-utils"
45import { CheckpointSettings } from "../CheckpointSettings"
56
@@ -29,7 +30,17 @@ vi.mock("@/components/ui", async (importOriginal) => {
2930 const actual = await importOriginal < typeof import ( "@/components/ui" ) > ( )
3031 return {
3132 ...actual ,
32- Slider : ( { defaultValue, onValueChange, "data-testid" : dataTestId } : any ) => (
33+ // Narrow typed double: only the props CheckpointSettings consumes, so
34+ // drift in the Slider contract is a compile error here, not `any`.
35+ Slider : ( {
36+ defaultValue,
37+ onValueChange,
38+ "data-testid" : dataTestId ,
39+ } : {
40+ defaultValue ?: number [ ]
41+ onValueChange ?: ( value : number [ ] ) => void
42+ "data-testid" ?: string
43+ } ) => (
3344 < input
3445 type = "range"
3546 value = { defaultValue ?. [ 0 ] ?? 0 }
@@ -49,21 +60,44 @@ vi.mock("@/utils/vscode", () => ({
4960} ) )
5061
5162// Mock VSCode components to behave like standard HTML elements
52- vi . mock ( "@vscode/webview-ui-toolkit/react" , ( ) => ( {
53- VSCodeCheckbox : ( { checked, onChange, children, ...props } : any ) => (
54- < label { ...props } >
55- < input
56- type = "checkbox"
57- role = "checkbox"
58- checked = { checked || false }
59- aria-checked = { checked || false }
60- onChange = { ( e : any ) => onChange ?.( { target : { checked : e . target . checked } } ) }
61- />
62- { children }
63- </ label >
64- ) ,
65- VSCodeLink : ( { children, ...props } : any ) => < a { ...props } > { children } </ a > ,
66- } ) )
63+ vi . mock ( "@vscode/webview-ui-toolkit/react" , ( ) => {
64+ // Narrow event double: the real toolkit dispatches a native Event whose
65+ // currentTarget is the web component with a boolean `checked`; the mock
66+ // forwards the input's checked state on both target and currentTarget so
67+ // handlers can be typed against either surface.
68+ type CheckboxChangeEvent = {
69+ target : { checked : boolean }
70+ currentTarget : { checked : boolean }
71+ }
72+ return {
73+ VSCodeCheckbox : ( {
74+ checked,
75+ onChange,
76+ children,
77+ "data-testid" : dataTestId ,
78+ } : {
79+ checked ?: boolean
80+ onChange ?: ( e : CheckboxChangeEvent ) => void
81+ children ?: ReactNode
82+ "data-testid" ?: string
83+ } ) => (
84+ < label data-testid = { dataTestId } >
85+ < input
86+ type = "checkbox"
87+ role = "checkbox"
88+ checked = { checked || false }
89+ aria-checked = { checked || false }
90+ onChange = { ( e ) => {
91+ const value = e . currentTarget . checked
92+ onChange ?.( { target : { checked : value } , currentTarget : { checked : value } } )
93+ } }
94+ />
95+ { children }
96+ </ label >
97+ ) ,
98+ VSCodeLink : ( { children, href } : { children ?: ReactNode ; href ?: string } ) => < a href = { href } > { children } </ a > ,
99+ }
100+ } )
67101
68102describe ( "CheckpointSettings" , ( ) => {
69103 const setCachedStateField = vi . fn ( )
0 commit comments