11import { describe , it , expect , jest } from '@jest/globals' ;
22import * as cmd from '../../src/commands/handlers' ;
33
4- import { window , ExtensionContext } from 'vscode' ;
4+ import * as vsce from 'vscode' ;
55import * as core from 'lightning-flow-scanner-core' ;
66import { CacheProvider } from '../../src/providers/cache-provider' ;
77import { OutputChannel } from '../../src/providers/outputChannel' ;
8+ import * as cp from '../../src/providers/config-provider' ;
89
910jest . mock ( 'lightning-flow-scanner-core' ) ;
1011jest . mock ( '../../src/providers/cache-provider' ) ;
1112jest . mock ( '../../src/providers/outputChannel' ) ;
13+ jest . mock ( '../../src/providers/config-provider' ) ;
14+ jest . mock ( 'vscode' ) ;
1215
1316describe ( 'Commands' , ( ) => {
1417 it ( 'should be defined' , ( ) => {
@@ -43,7 +46,7 @@ describe('Commands', () => {
4346 ] ) ,
4447 } as any ;
4548
46- const spy = jest . spyOn ( window , 'showQuickPick' ) . mockReturnValue ( [
49+ const spy = jest . spyOn ( vsce . window , 'showQuickPick' ) . mockReturnValue ( [
4750 { label : 'Flow Name' , value : 'FlowName' } ,
4851 { label : 'API Version' , value : 'APIVersion' } ,
4952 ] as any ) ;
@@ -57,19 +60,39 @@ describe('Commands', () => {
5760
5861 const extensionContext = jest . fn ( ) ;
5962 const command = new cmd . default (
60- extensionContext as unknown as ExtensionContext
63+ extensionContext as unknown as vsce . ExtensionContext
6164 ) ;
6265
6366 await expect ( async ( ) => await command [ 'configRules' ] ( ) ) . not . toThrow ( ) ;
6467 } ) ;
6568
6669 it ( 'should read from configuration' , async ( ) => {
6770 const command = new cmd . default ( { } as any ) ;
71+ jest
72+ . spyOn ( cp . ConfigProvider . prototype , 'discover' )
73+ . mockImplementation ( ( ) =>
74+ Promise . resolve ( {
75+ fspath : '/fake/path' ,
76+ config : { rules : { APIName : { severity : 'error' } } } ,
77+ } as any )
78+ ) ;
79+ ( vsce . workspace as any ) . openTextDocument = jest . fn ( ) ;
80+ ( vsce . window as any ) . showTextDocument = jest . fn ( ) ;
6881 await expect ( command [ 'ruleConfiguration' ] ( ) ) . resolves . not . toThrow ( ) ;
6982 } ) ;
7083
7184 it ( 'should write to configuration' , async ( ) => {
7285 const command = new cmd . default ( { } as any ) ;
86+ jest
87+ . spyOn ( cp . ConfigProvider . prototype , 'discover' )
88+ . mockImplementation ( ( ) =>
89+ Promise . resolve ( {
90+ fspath : '/fake/path' ,
91+ config : { rules : { APIName : { severity : 'error' } } } ,
92+ } as any )
93+ ) ;
94+ ( vsce . workspace as any ) . openTextDocument = jest . fn ( ) ;
95+ ( vsce . window as any ) . showTextDocument = jest . fn ( ) ;
7396 await expect ( command [ 'ruleConfiguration' ] ( ) ) . resolves . not . toThrow ( ) ;
7497 } ) ;
7598 } ) ;
0 commit comments