@@ -9,6 +9,7 @@ import { ProviderName } from "../../../schemas"
99import { importSettings , exportSettings } from "../importExport"
1010import { ProviderSettingsManager } from "../ProviderSettingsManager"
1111import { ContextProxy } from "../ContextProxy"
12+ import { CustomModesManager } from "../CustomModesManager"
1213
1314// Mock VSCode modules
1415jest . mock ( "vscode" , ( ) => ( {
@@ -37,6 +38,7 @@ describe("importExport", () => {
3738 let mockProviderSettingsManager : jest . Mocked < ProviderSettingsManager >
3839 let mockContextProxy : jest . Mocked < ContextProxy >
3940 let mockExtensionContext : jest . Mocked < vscode . ExtensionContext >
41+ let mockCustomModesManager : jest . Mocked < CustomModesManager >
4042
4143 beforeEach ( ( ) => {
4244 // Reset all mocks
@@ -56,6 +58,11 @@ describe("importExport", () => {
5658 export : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( { } ) ) ,
5759 } as unknown as jest . Mocked < ContextProxy >
5860
61+ // Setup customModesManager mock
62+ mockCustomModesManager = {
63+ updateCustomMode : jest . fn ( ) ,
64+ } as unknown as jest . Mocked < CustomModesManager >
65+
5966 const map = new Map < string , string > ( )
6067
6168 mockExtensionContext = {
@@ -74,6 +81,7 @@ describe("importExport", () => {
7481 const result = await importSettings ( {
7582 providerSettingsManager : mockProviderSettingsManager ,
7683 contextProxy : mockContextProxy ,
84+ customModesManager : mockCustomModesManager ,
7785 } )
7886
7987 expect ( result ) . toEqual ( { success : false } )
@@ -138,6 +146,7 @@ describe("importExport", () => {
138146 const result = await importSettings ( {
139147 providerSettingsManager : mockProviderSettingsManager ,
140148 contextProxy : mockContextProxy ,
149+ customModesManager : mockCustomModesManager ,
141150 } )
142151
143152 expect ( result . success ) . toBe ( true )
@@ -181,6 +190,7 @@ describe("importExport", () => {
181190 const result = await importSettings ( {
182191 providerSettingsManager : mockProviderSettingsManager ,
183192 contextProxy : mockContextProxy ,
193+ customModesManager : mockCustomModesManager ,
184194 } )
185195
186196 expect ( result ) . toEqual ( { success : false } )
@@ -202,6 +212,7 @@ describe("importExport", () => {
202212 const result = await importSettings ( {
203213 providerSettingsManager : mockProviderSettingsManager ,
204214 contextProxy : mockContextProxy ,
215+ customModesManager : mockCustomModesManager ,
205216 } )
206217
207218 expect ( result ) . toEqual ( { success : false } )
@@ -220,6 +231,7 @@ describe("importExport", () => {
220231 const result = await importSettings ( {
221232 providerSettingsManager : mockProviderSettingsManager ,
222233 contextProxy : mockContextProxy ,
234+ customModesManager : mockCustomModesManager ,
223235 } )
224236
225237 expect ( result ) . toEqual ( { success : false } )
@@ -252,6 +264,7 @@ describe("importExport", () => {
252264 const result = await importSettings ( {
253265 providerSettingsManager,
254266 contextProxy : mockContextProxy ,
267+ customModesManager : mockCustomModesManager ,
255268 } )
256269
257270 expect ( result . success ) . toBe ( true )
@@ -261,6 +274,50 @@ describe("importExport", () => {
261274 } )
262275 } )
263276
277+ it ( "should call updateCustomMode for each custom mode in config" , async ( ) => {
278+ ; ( vscode . window . showOpenDialog as jest . Mock ) . mockResolvedValue ( [ { fsPath : "/mock/path/settings.json" } ] )
279+ const customModes = [
280+ {
281+ slug : "mode1" ,
282+ name : "Mode One" ,
283+ roleDefinition : "Custom role one" ,
284+ groups : [ ] ,
285+ } ,
286+ {
287+ slug : "mode2" ,
288+ name : "Mode Two" ,
289+ roleDefinition : "Custom role two" ,
290+ groups : [ ] ,
291+ } ,
292+ ]
293+ const mockFileContent = JSON . stringify ( {
294+ providerProfiles : {
295+ currentApiConfigName : "test" ,
296+ apiConfigs : { } ,
297+ } ,
298+ globalSettings : {
299+ mode : "code" ,
300+ customModes,
301+ } ,
302+ } )
303+ ; ( fs . readFile as jest . Mock ) . mockResolvedValue ( mockFileContent )
304+ mockProviderSettingsManager . export . mockResolvedValue ( {
305+ currentApiConfigName : "test" ,
306+ apiConfigs : { } ,
307+ } )
308+ mockProviderSettingsManager . listConfig . mockResolvedValue ( [ ] )
309+ const result = await importSettings ( {
310+ providerSettingsManager : mockProviderSettingsManager ,
311+ contextProxy : mockContextProxy ,
312+ customModesManager : mockCustomModesManager ,
313+ } )
314+ expect ( result . success ) . toBe ( true )
315+ expect ( mockCustomModesManager . updateCustomMode ) . toHaveBeenCalledTimes ( customModes . length )
316+ customModes . forEach ( ( mode ) => {
317+ expect ( mockCustomModesManager . updateCustomMode ) . toHaveBeenCalledWith ( mode . slug , mode )
318+ } )
319+ } )
320+
264321 describe ( "exportSettings" , ( ) => {
265322 it ( "should not export settings when user cancels file selection" , async ( ) => {
266323 // Mock user canceling file selection
0 commit comments