1+ import type { TFunction } from "i18next"
2+
13import type { Command } from "@roo-code/types"
24
35import { getContextMenuOptions , ContextMenuOptionType } from "../utils/context-mentions"
46
7+ const t = ( ( key : string ) => key ) as TFunction
8+
59describe ( "Command Autocomplete" , ( ) => {
610 const mockCommands : Command [ ] = [
711 { name : "setup" , source : "project" } ,
@@ -19,7 +23,7 @@ describe("Command Autocomplete", () => {
1923
2024 describe ( "slash command command suggestions" , ( ) => {
2125 it ( 'should return all commands when query is just "/"' , ( ) => {
22- const options = getContextMenuOptions ( "/" , null , mockQueryItems , [ ] , [ ] , mockCommands )
26+ const options = getContextMenuOptions ( t , "/" , null , mockQueryItems , [ ] , [ ] , mockCommands )
2327
2428 // Should have 7 items: 1 section header + 6 commands
2529 expect ( options ) . toHaveLength ( 7 )
@@ -38,7 +42,7 @@ describe("Command Autocomplete", () => {
3842 } )
3943
4044 it ( "should filter commands based on fuzzy search" , ( ) => {
41- const options = getContextMenuOptions ( "/set" , null , mockQueryItems , [ ] , [ ] , mockCommands )
45+ const options = getContextMenuOptions ( t , "/set" , null , mockQueryItems , [ ] , [ ] , mockCommands )
4246
4347 // Should match 'setup' (fuzzy search behavior may vary)
4448 expect ( options . length ) . toBeGreaterThan ( 0 )
@@ -48,7 +52,7 @@ describe("Command Autocomplete", () => {
4852 } )
4953
5054 it ( "should return commands with correct format" , ( ) => {
51- const options = getContextMenuOptions ( "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
55+ const options = getContextMenuOptions ( t , "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
5256
5357 const setupOption = options . find ( ( option ) => option . value === "setup" )
5458 expect ( setupOption ) . toBeDefined ( )
@@ -58,23 +62,23 @@ describe("Command Autocomplete", () => {
5862 } )
5963
6064 it ( "should handle empty command list" , ( ) => {
61- const options = getContextMenuOptions ( "/setup" , null , mockQueryItems , [ ] , [ ] , [ ] )
65+ const options = getContextMenuOptions ( t , "/setup" , null , mockQueryItems , [ ] , [ ] , [ ] )
6266
6367 // Should return NoResults when no commands match
6468 expect ( options ) . toHaveLength ( 1 )
6569 expect ( options [ 0 ] . type ) . toBe ( ContextMenuOptionType . NoResults )
6670 } )
6771
6872 it ( "should handle no matching commands" , ( ) => {
69- const options = getContextMenuOptions ( "/nonexistent" , null , mockQueryItems , [ ] , [ ] , mockCommands )
73+ const options = getContextMenuOptions ( t , "/nonexistent" , null , mockQueryItems , [ ] , [ ] , mockCommands )
7074
7175 // Should return NoResults when no commands match
7276 expect ( options ) . toHaveLength ( 1 )
7377 expect ( options [ 0 ] . type ) . toBe ( ContextMenuOptionType . NoResults )
7478 } )
7579
7680 it ( "should not return command suggestions for non-slash queries" , ( ) => {
77- const options = getContextMenuOptions ( "setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
81+ const options = getContextMenuOptions ( t , "setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
7882
7983 // Should not contain command options for non-slash queries
8084 const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
@@ -88,15 +92,15 @@ describe("Command Autocomplete", () => {
8892 { name : "deploy.prod" , source : "global" } ,
8993 ]
9094
91- const options = getContextMenuOptions ( "/setup" , null , mockQueryItems , [ ] , [ ] , specialCommands )
95+ const options = getContextMenuOptions ( t , "/setup" , null , mockQueryItems , [ ] , [ ] , specialCommands )
9296
9397 const setupDevOption = options . find ( ( option ) => option . value === "setup-dev" )
9498 expect ( setupDevOption ) . toBeDefined ( )
9599 expect ( setupDevOption ! . slashCommand ) . toBe ( "/setup-dev" )
96100 } )
97101
98102 it ( "should handle case-insensitive fuzzy matching" , ( ) => {
99- const options = getContextMenuOptions ( "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
103+ const options = getContextMenuOptions ( t , "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
100104
101105 const commandNames = options . map ( ( option ) => option . value )
102106 expect ( commandNames ) . toContain ( "setup" )
@@ -109,15 +113,15 @@ describe("Command Autocomplete", () => {
109113 { name : "integration-test" , source : "project" } ,
110114 ]
111115
112- const options = getContextMenuOptions ( "/test" , null , mockQueryItems , [ ] , [ ] , commandsWithSimilarNames )
116+ const options = getContextMenuOptions ( t , "/test" , null , mockQueryItems , [ ] , [ ] , commandsWithSimilarNames )
113117
114118 // Filter out section headers and check the first command
115119 const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
116120 expect ( commandOptions [ 0 ] . value ) . toBe ( "test" )
117121 } )
118122
119123 it ( "should handle partial matches correctly" , ( ) => {
120- const options = getContextMenuOptions ( "/te" , null , mockQueryItems , [ ] , [ ] , mockCommands )
124+ const options = getContextMenuOptions ( t , "/te" , null , mockQueryItems , [ ] , [ ] , mockCommands )
121125
122126 // Should match 'test-suite'
123127 const commandNames = options . map ( ( option ) => option . value )
@@ -144,7 +148,7 @@ describe("Command Autocomplete", () => {
144148 ] as any [ ]
145149
146150 it ( "should return both modes and commands for slash commands" , ( ) => {
147- const options = getContextMenuOptions ( "/" , null , mockQueryItems , [ ] , mockModes , mockCommands )
151+ const options = getContextMenuOptions ( t , "/" , null , mockQueryItems , [ ] , mockModes , mockCommands )
148152
149153 const modeOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Mode )
150154 const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
@@ -154,7 +158,7 @@ describe("Command Autocomplete", () => {
154158 } )
155159
156160 it ( "should filter both modes and commands based on query" , ( ) => {
157- const options = getContextMenuOptions ( "/co" , null , mockQueryItems , [ ] , mockModes , mockCommands )
161+ const options = getContextMenuOptions ( t , "/co" , null , mockQueryItems , [ ] , mockModes , mockCommands )
158162
159163 // Should match 'code' mode and possibly some commands (fuzzy search may match)
160164 const modeOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Mode )
@@ -169,7 +173,7 @@ describe("Command Autocomplete", () => {
169173
170174 describe ( "command source indication" , ( ) => {
171175 it ( "should not expose source information in autocomplete" , ( ) => {
172- const options = getContextMenuOptions ( "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
176+ const options = getContextMenuOptions ( t , "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
173177
174178 const setupOption = options . find ( ( option ) => option . value === "setup" )
175179 expect ( setupOption ) . toBeDefined ( )
@@ -185,23 +189,23 @@ describe("Command Autocomplete", () => {
185189
186190 describe ( "argument hint functionality" , ( ) => {
187191 it ( "should include argumentHint in command options when present" , ( ) => {
188- const options = getContextMenuOptions ( "/release" , null , mockQueryItems , [ ] , [ ] , mockCommands )
192+ const options = getContextMenuOptions ( t , "/release" , null , mockQueryItems , [ ] , [ ] , mockCommands )
189193
190194 const releaseOption = options . find ( ( option ) => option . value === "release" )
191195 expect ( releaseOption ) . toBeDefined ( )
192196 expect ( releaseOption ! . argumentHint ) . toBe ( "patch | minor | major" )
193197 } )
194198
195199 it ( "should handle commands without argumentHint" , ( ) => {
196- const options = getContextMenuOptions ( "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
200+ const options = getContextMenuOptions ( t , "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
197201
198202 const setupOption = options . find ( ( option ) => option . value === "setup" )
199203 expect ( setupOption ) . toBeDefined ( )
200204 expect ( setupOption ! . argumentHint ) . toBeUndefined ( )
201205 } )
202206
203207 it ( "should preserve argumentHint through fuzzy search" , ( ) => {
204- const options = getContextMenuOptions ( "/rel" , null , mockQueryItems , [ ] , [ ] , mockCommands )
208+ const options = getContextMenuOptions ( t , "/rel" , null , mockQueryItems , [ ] , [ ] , mockCommands )
205209
206210 const releaseOption = options . find ( ( option ) => option . value === "release" )
207211 expect ( releaseOption ) . toBeDefined ( )
@@ -211,7 +215,7 @@ describe("Command Autocomplete", () => {
211215 it ( "should handle commands with empty argumentHint" , ( ) => {
212216 const commandsWithEmptyHint : Command [ ] = [ { name : "test-command" , source : "project" , argumentHint : "" } ]
213217
214- const options = getContextMenuOptions ( "/test" , null , mockQueryItems , [ ] , [ ] , commandsWithEmptyHint )
218+ const options = getContextMenuOptions ( t , "/test" , null , mockQueryItems , [ ] , [ ] , commandsWithEmptyHint )
215219
216220 const testOption = options . find ( ( option ) => option . value === "test-command" )
217221 expect ( testOption ) . toBeDefined ( )
@@ -221,14 +225,14 @@ describe("Command Autocomplete", () => {
221225
222226 describe ( "edge cases" , ( ) => {
223227 it ( "should handle undefined commands gracefully" , ( ) => {
224- const options = getContextMenuOptions ( "/setup" , null , mockQueryItems , [ ] , [ ] , undefined )
228+ const options = getContextMenuOptions ( t , "/setup" , null , mockQueryItems , [ ] , [ ] , undefined )
225229
226230 expect ( options ) . toHaveLength ( 1 )
227231 expect ( options [ 0 ] . type ) . toBe ( ContextMenuOptionType . NoResults )
228232 } )
229233
230234 it ( "should handle empty query with commands" , ( ) => {
231- const options = getContextMenuOptions ( "" , null , mockQueryItems , [ ] , [ ] , mockCommands )
235+ const options = getContextMenuOptions ( t , "" , null , mockQueryItems , [ ] , [ ] , mockCommands )
232236
233237 // Should not return command options for empty query
234238 const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
@@ -240,7 +244,7 @@ describe("Command Autocomplete", () => {
240244 { name : "very-long-command-name-that-exceeds-normal-length" , source : "project" } ,
241245 ]
242246
243- const options = getContextMenuOptions ( "/very" , null , mockQueryItems , [ ] , [ ] , longNameCommands )
247+ const options = getContextMenuOptions ( t , "/very" , null , mockQueryItems , [ ] , [ ] , longNameCommands )
244248
245249 // Should have 2 items: 1 section header + 1 command
246250 expect ( options . length ) . toBe ( 2 )
@@ -255,7 +259,7 @@ describe("Command Autocomplete", () => {
255259 { name : "123test" , source : "project" } ,
256260 ]
257261
258- const options = getContextMenuOptions ( "/v" , null , mockQueryItems , [ ] , [ ] , numericCommands )
262+ const options = getContextMenuOptions ( t , "/v" , null , mockQueryItems , [ ] , [ ] , numericCommands )
259263
260264 const commandNames = options . map ( ( option ) => option . value )
261265 expect ( commandNames ) . toContain ( "v2-setup" )
0 commit comments