@@ -41,11 +41,23 @@ vi.mock("@/utils/vscode", () => ({
4141 } ,
4242} ) )
4343
44- // Mock ControlledCheckbox
45- vi . mock ( "../../common/ControlledCheckbox" , ( ) => ( {
46- ControlledCheckbox : ( { children, checked, onChange } : any ) => (
44+ // Mock useKeybindings hook
45+ vi . mock ( "@/hooks/useKeybindings" , ( ) => ( {
46+ useKeybindings : ( ) => ( {
47+ "kilo-code.addToContextAndFocus" : "Cmd+K" ,
48+ "kilo-code.ghost.generateSuggestions" : "Cmd+Shift+G" ,
49+ } ) ,
50+ } ) )
51+
52+ // Mock VSCodeCheckbox to render as regular HTML checkbox for testing
53+ vi . mock ( "@vscode/webview-ui-toolkit/react" , ( ) => ( {
54+ VSCodeCheckbox : ( { checked, onChange, children } : any ) => (
4755 < label >
48- < input type = "checkbox" checked = { checked } onChange = { ( e ) => onChange ( e . target . checked ) } />
56+ < input
57+ type = "checkbox"
58+ checked = { checked }
59+ onChange = { ( e ) => onChange ( { target : { checked : e . target . checked } } ) }
60+ />
4961 { children }
5062 </ label >
5163 ) ,
@@ -83,7 +95,7 @@ const defaultGhostServiceSettings: GhostServiceSettings = {
8395const renderComponent = ( props = { } ) => {
8496 const defaultProps = {
8597 ghostServiceSettings : defaultGhostServiceSettings ,
86- setCachedStateField : vi . fn ( ) ,
98+ onGhostServiceSettingsChange : vi . fn ( ) ,
8799 ...props ,
88100 }
89101
@@ -119,69 +131,43 @@ describe("GhostServiceSettingsView", () => {
119131 } )
120132
121133 it ( "toggles auto trigger checkbox correctly" , ( ) => {
122- const setCachedStateField = vi . fn ( )
123- renderComponent ( { setCachedStateField } )
134+ const onGhostServiceSettingsChange = vi . fn ( )
135+ renderComponent ( { onGhostServiceSettingsChange } )
124136
125- // Find and click the auto trigger checkbox
126- const checkbox = screen
127- . getByText ( / k i l o c o d e : g h o s t .s e t t i n g s .e n a b l e A u t o T r i g g e r .l a b e l / )
128- . closest ( "label" )
129- ?. querySelector ( "input[type='checkbox']" )
130-
131- if ( checkbox ) {
132- fireEvent . click ( checkbox )
133- }
134-
135- expect ( setCachedStateField ) . toHaveBeenCalledWith (
136- "ghostServiceSettings" ,
137- expect . objectContaining ( {
138- enableAutoTrigger : true ,
139- } ) ,
140- )
137+ const checkboxLabel = screen . getByText ( / k i l o c o d e : g h o s t .s e t t i n g s .e n a b l e A u t o T r i g g e r .l a b e l / ) . closest ( "label" )
138+ const checkbox = checkboxLabel ?. querySelector ( 'input[type="checkbox"]' ) as HTMLInputElement
139+
140+ fireEvent . click ( checkbox )
141+
142+ expect ( onGhostServiceSettingsChange ) . toHaveBeenCalledWith ( "enableAutoTrigger" , true )
141143 } )
142144
143145 it ( "toggles quick inline task keybinding checkbox correctly" , ( ) => {
144- const setCachedStateField = vi . fn ( )
145- renderComponent ( { setCachedStateField } )
146+ const onGhostServiceSettingsChange = vi . fn ( )
147+ renderComponent ( { onGhostServiceSettingsChange } )
146148
147- // Find and click the quick inline task keybinding checkbox
148- const checkbox = screen
149+ const checkboxLabel = screen
149150 . getByText ( / k i l o c o d e : g h o s t .s e t t i n g s .e n a b l e Q u i c k I n l i n e T a s k K e y b i n d i n g .l a b e l / )
150151 . closest ( "label" )
151- ?. querySelector ( "input[type='checkbox']" )
152-
153- if ( checkbox ) {
154- fireEvent . click ( checkbox )
155- }
156-
157- expect ( setCachedStateField ) . toHaveBeenCalledWith (
158- "ghostServiceSettings" ,
159- expect . objectContaining ( {
160- enableQuickInlineTaskKeybinding : true ,
161- } ) ,
162- )
152+ const checkbox = checkboxLabel ?. querySelector ( 'input[type="checkbox"]' ) as HTMLInputElement
153+
154+ fireEvent . click ( checkbox )
155+
156+ expect ( onGhostServiceSettingsChange ) . toHaveBeenCalledWith ( "enableQuickInlineTaskKeybinding" , true )
163157 } )
164158
165159 it ( "toggles smart inline task keybinding checkbox correctly" , ( ) => {
166- const setCachedStateField = vi . fn ( )
167- renderComponent ( { setCachedStateField } )
160+ const onGhostServiceSettingsChange = vi . fn ( )
161+ renderComponent ( { onGhostServiceSettingsChange } )
168162
169- // Find and click the smart inline task keybinding checkbox
170- const checkbox = screen
163+ const checkboxLabel = screen
171164 . getByText ( / k i l o c o d e : g h o s t .s e t t i n g s .e n a b l e S m a r t I n l i n e T a s k K e y b i n d i n g .l a b e l / )
172165 . closest ( "label" )
173- ?. querySelector ( "input[type='checkbox']" )
174-
175- if ( checkbox ) {
176- fireEvent . click ( checkbox )
177- }
178-
179- expect ( setCachedStateField ) . toHaveBeenCalledWith (
180- "ghostServiceSettings" ,
181- expect . objectContaining ( {
182- enableSmartInlineTaskKeybinding : true ,
183- } ) ,
184- )
166+ const checkbox = checkboxLabel ?. querySelector ( 'input[type="checkbox"]' ) as HTMLInputElement
167+
168+ fireEvent . click ( checkbox )
169+
170+ expect ( onGhostServiceSettingsChange ) . toHaveBeenCalledWith ( "enableSmartInlineTaskKeybinding" , true )
185171 } )
186172
187173 it ( "renders Trans components with proper structure" , ( ) => {
0 commit comments