@@ -16,22 +16,18 @@ describe("Command Autocomplete", () => {
1616 { type : ContextMenuOptionType . Problems , value : "problems" } ,
1717 ]
1818
19- // Mock translation function
20- const mockT = ( key : string , options ?: { name ?: string } ) => {
21- if ( key === "chat:command.triggerDescription" ) {
22- return `Trigger the ${ options ?. name || "command" } command`
23- }
24- return key
25- }
26-
2719 describe ( "slash command command suggestions" , ( ) => {
2820 it ( 'should return all commands when query is just "/"' , ( ) => {
29- const options = getContextMenuOptions ( "/" , "/" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
21+ const options = getContextMenuOptions ( "/" , "/" , null , mockQueryItems , [ ] , [ ] , mockCommands )
3022
31- expect ( options ) . toHaveLength ( 5 )
32- expect ( options . every ( ( option ) => option . type === ContextMenuOptionType . Command ) ) . toBe ( true )
23+ // Should have 6 items: 1 section header + 5 commands
24+ expect ( options ) . toHaveLength ( 6 )
3325
34- const commandNames = options . map ( ( option ) => option . value )
26+ // Filter out section headers to check commands
27+ const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
28+ expect ( commandOptions ) . toHaveLength ( 5 )
29+
30+ const commandNames = commandOptions . map ( ( option ) => option . value )
3531 expect ( commandNames ) . toContain ( "setup" )
3632 expect ( commandNames ) . toContain ( "build" )
3733 expect ( commandNames ) . toContain ( "deploy" )
@@ -40,7 +36,7 @@ describe("Command Autocomplete", () => {
4036 } )
4137
4238 it ( "should filter commands based on fuzzy search" , ( ) => {
43- const options = getContextMenuOptions ( "/set" , "/set" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
39+ const options = getContextMenuOptions ( "/set" , "/set" , null , mockQueryItems , [ ] , [ ] , mockCommands )
4440
4541 // Should match 'setup' (fuzzy search behavior may vary)
4642 expect ( options . length ) . toBeGreaterThan ( 0 )
@@ -50,18 +46,17 @@ describe("Command Autocomplete", () => {
5046 } )
5147
5248 it ( "should return commands with correct format" , ( ) => {
53- const options = getContextMenuOptions ( "/setup" , "/setup" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
49+ const options = getContextMenuOptions ( "/setup" , "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
5450
5551 const setupOption = options . find ( ( option ) => option . value === "setup" )
5652 expect ( setupOption ) . toBeDefined ( )
5753 expect ( setupOption ! . type ) . toBe ( ContextMenuOptionType . Command )
58- expect ( setupOption ! . label ) . toBe ( "setup" )
59- expect ( setupOption ! . description ) . toBe ( "Trigger the setup command" )
60- expect ( setupOption ! . icon ) . toBe ( "$(play)" )
54+ expect ( setupOption ! . slashCommand ) . toBe ( "/setup" )
55+ expect ( setupOption ! . value ) . toBe ( "setup" )
6156 } )
6257
6358 it ( "should handle empty command list" , ( ) => {
64- const options = getContextMenuOptions ( "/setup" , "/setup" , mockT , null , mockQueryItems , [ ] , [ ] , [ ] )
59+ const options = getContextMenuOptions ( "/setup" , "/setup" , null , mockQueryItems , [ ] , [ ] , [ ] )
6560
6661 // Should return NoResults when no commands match
6762 expect ( options ) . toHaveLength ( 1 )
@@ -72,7 +67,6 @@ describe("Command Autocomplete", () => {
7267 const options = getContextMenuOptions (
7368 "/nonexistent" ,
7469 "/nonexistent" ,
75- mockT ,
7670 null ,
7771 mockQueryItems ,
7872 [ ] ,
@@ -86,7 +80,7 @@ describe("Command Autocomplete", () => {
8680 } )
8781
8882 it ( "should not return command suggestions for non-slash queries" , ( ) => {
89- const options = getContextMenuOptions ( "setup" , "setup" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
83+ const options = getContextMenuOptions ( "setup" , "setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
9084
9185 // Should not contain command options for non-slash queries
9286 const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
@@ -100,24 +94,15 @@ describe("Command Autocomplete", () => {
10094 { name : "deploy.prod" , source : "global" } ,
10195 ]
10296
103- const options = getContextMenuOptions (
104- "/setup" ,
105- "/setup" ,
106- mockT ,
107- null ,
108- mockQueryItems ,
109- [ ] ,
110- [ ] ,
111- specialCommands ,
112- )
97+ const options = getContextMenuOptions ( "/setup" , "/setup" , null , mockQueryItems , [ ] , [ ] , specialCommands )
11398
11499 const setupDevOption = options . find ( ( option ) => option . value === "setup-dev" )
115100 expect ( setupDevOption ) . toBeDefined ( )
116- expect ( setupDevOption ! . label ) . toBe ( "setup-dev" )
101+ expect ( setupDevOption ! . slashCommand ) . toBe ( "/ setup-dev" )
117102 } )
118103
119104 it ( "should handle case-insensitive fuzzy matching" , ( ) => {
120- const options = getContextMenuOptions ( "/setup" , "/setup" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
105+ const options = getContextMenuOptions ( "/setup" , "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
121106
122107 const commandNames = options . map ( ( option ) => option . value )
123108 expect ( commandNames ) . toContain ( "setup" )
@@ -133,20 +118,20 @@ describe("Command Autocomplete", () => {
133118 const options = getContextMenuOptions (
134119 "/test" ,
135120 "/test" ,
136- mockT ,
137121 null ,
138122 mockQueryItems ,
139123 [ ] ,
140124 [ ] ,
141125 commandsWithSimilarNames ,
142126 )
143127
144- // 'test' should be first due to exact match
145- expect ( options [ 0 ] . value ) . toBe ( "test" )
128+ // Filter out section headers and check the first command
129+ const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
130+ expect ( commandOptions [ 0 ] . value ) . toBe ( "test" )
146131 } )
147132
148133 it ( "should handle partial matches correctly" , ( ) => {
149- const options = getContextMenuOptions ( "/te" , "/te" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
134+ const options = getContextMenuOptions ( "/te" , "/te" , null , mockQueryItems , [ ] , [ ] , mockCommands )
150135
151136 // Should match 'test-suite'
152137 const commandNames = options . map ( ( option ) => option . value )
@@ -173,7 +158,7 @@ describe("Command Autocomplete", () => {
173158 ] as any [ ]
174159
175160 it ( "should return both modes and commands for slash commands" , ( ) => {
176- const options = getContextMenuOptions ( "/" , "/" , mockT , null , mockQueryItems , [ ] , mockModes , mockCommands )
161+ const options = getContextMenuOptions ( "/" , "/" , null , mockQueryItems , [ ] , mockModes , mockCommands )
177162
178163 const modeOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Mode )
179164 const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
@@ -183,16 +168,7 @@ describe("Command Autocomplete", () => {
183168 } )
184169
185170 it ( "should filter both modes and commands based on query" , ( ) => {
186- const options = getContextMenuOptions (
187- "/co" ,
188- "/co" ,
189- mockT ,
190- null ,
191- mockQueryItems ,
192- [ ] ,
193- mockModes ,
194- mockCommands ,
195- )
171+ const options = getContextMenuOptions ( "/co" , "/co" , null , mockQueryItems , [ ] , mockModes , mockCommands )
196172
197173 // Should match 'code' mode and possibly some commands (fuzzy search may match)
198174 const modeOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Mode )
@@ -207,28 +183,30 @@ describe("Command Autocomplete", () => {
207183
208184 describe ( "command source indication" , ( ) => {
209185 it ( "should not expose source information in autocomplete" , ( ) => {
210- const options = getContextMenuOptions ( "/setup" , "/setup" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
186+ const options = getContextMenuOptions ( "/setup" , "/setup" , null , mockQueryItems , [ ] , [ ] , mockCommands )
211187
212188 const setupOption = options . find ( ( option ) => option . value === "setup" )
213189 expect ( setupOption ) . toBeDefined ( )
214190
215191 // Source should not be exposed in the UI
216- expect ( setupOption ! . description ) . not . toContain ( "project" )
217- expect ( setupOption ! . description ) . not . toContain ( "global" )
218- expect ( setupOption ! . description ) . toBe ( "Trigger the setup command" )
192+ if ( setupOption ! . description ) {
193+ expect ( setupOption ! . description ) . not . toContain ( "project" )
194+ expect ( setupOption ! . description ) . not . toContain ( "global" )
195+ expect ( setupOption ! . description ) . toBe ( "Trigger the setup command" )
196+ }
219197 } )
220198 } )
221199
222200 describe ( "edge cases" , ( ) => {
223201 it ( "should handle undefined commands gracefully" , ( ) => {
224- const options = getContextMenuOptions ( "/setup" , "/setup" , mockT , null , mockQueryItems , [ ] , [ ] , undefined )
202+ const options = getContextMenuOptions ( "/setup" , "/setup" , null , mockQueryItems , [ ] , [ ] , undefined )
225203
226204 expect ( options ) . toHaveLength ( 1 )
227205 expect ( options [ 0 ] . type ) . toBe ( ContextMenuOptionType . NoResults )
228206 } )
229207
230208 it ( "should handle empty query with commands" , ( ) => {
231- const options = getContextMenuOptions ( "" , "" , mockT , null , mockQueryItems , [ ] , [ ] , mockCommands )
209+ const options = getContextMenuOptions ( "" , "" , null , mockQueryItems , [ ] , [ ] , mockCommands )
232210
233211 // Should not return command options for empty query
234212 const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
@@ -240,19 +218,12 @@ describe("Command Autocomplete", () => {
240218 { name : "very-long-command-name-that-exceeds-normal-length" , source : "project" } ,
241219 ]
242220
243- const options = getContextMenuOptions (
244- "/very" ,
245- "/very" ,
246- mockT ,
247- null ,
248- mockQueryItems ,
249- [ ] ,
250- [ ] ,
251- longNameCommands ,
252- )
221+ const options = getContextMenuOptions ( "/very" , "/very" , null , mockQueryItems , [ ] , [ ] , longNameCommands )
253222
254- expect ( options . length ) . toBe ( 1 )
255- expect ( options [ 0 ] . value ) . toBe ( "very-long-command-name-that-exceeds-normal-length" )
223+ // Should have 2 items: 1 section header + 1 command
224+ expect ( options . length ) . toBe ( 2 )
225+ const commandOptions = options . filter ( ( option ) => option . type === ContextMenuOptionType . Command )
226+ expect ( commandOptions [ 0 ] . value ) . toBe ( "very-long-command-name-that-exceeds-normal-length" )
256227 } )
257228
258229 it ( "should handle commands with numeric names" , ( ) => {
@@ -262,7 +233,7 @@ describe("Command Autocomplete", () => {
262233 { name : "123test" , source : "project" } ,
263234 ]
264235
265- const options = getContextMenuOptions ( "/v" , "/v" , mockT , null , mockQueryItems , [ ] , [ ] , numericCommands )
236+ const options = getContextMenuOptions ( "/v" , "/v" , null , mockQueryItems , [ ] , [ ] , numericCommands )
266237
267238 const commandNames = options . map ( ( option ) => option . value )
268239 expect ( commandNames ) . toContain ( "v2-setup" )
0 commit comments