@@ -7,11 +7,11 @@ import { expect } from 'chai';
77import * as TypeMoq from 'typemoq' ;
88import { CancellationTokenSource , CodeLens , Range , Selection , TextEditor } from 'vscode' ;
99
10- import { IApplicationShell , IDocumentManager } from '../../../client/common/application/types' ;
10+ import { IApplicationShell , ICommandManager , IDocumentManager } from '../../../client/common/application/types' ;
1111import { PythonSettings } from '../../../client/common/configSettings' ;
1212import { IFileSystem } from '../../../client/common/platform/types' ;
1313import { IConfigurationService , ILogger } from '../../../client/common/types' ;
14- import { Commands } from '../../../client/datascience/constants' ;
14+ import { Commands , EditorContexts } from '../../../client/datascience/constants' ;
1515import { DataScienceCodeLensProvider } from '../../../client/datascience/editor-integration/codelensprovider' ;
1616import { CodeWatcher } from '../../../client/datascience/editor-integration/codewatcher' ;
1717import { ICodeWatcher , IHistory , IHistoryProvider } from '../../../client/datascience/types' ;
@@ -29,12 +29,14 @@ suite('DataScience Code Watcher Unit Tests', () => {
2929 let historyProvider : TypeMoq . IMock < IHistoryProvider > ;
3030 let activeHistory : TypeMoq . IMock < IHistory > ;
3131 let documentManager : TypeMoq . IMock < IDocumentManager > ;
32+ let commandManager : TypeMoq . IMock < ICommandManager > ;
3233 let textEditor : TypeMoq . IMock < TextEditor > ;
3334 let fileSystem : TypeMoq . IMock < IFileSystem > ;
3435 let configService : TypeMoq . IMock < IConfigurationService > ;
3536 let serviceContainer : TypeMoq . IMock < IServiceContainer > ;
3637 let helper : TypeMoq . IMock < ICodeExecutionHelper > ;
3738 let tokenSource : CancellationTokenSource ;
39+ const contexts : Map < string , boolean > = new Map < string , boolean > ( ) ;
3840 const pythonSettings = new class extends PythonSettings {
3941 public fireChangeEvent ( ) {
4042 this . changed . fire ( ) ;
@@ -52,6 +54,7 @@ suite('DataScience Code Watcher Unit Tests', () => {
5254 fileSystem = TypeMoq . Mock . ofType < IFileSystem > ( ) ;
5355 configService = TypeMoq . Mock . ofType < IConfigurationService > ( ) ;
5456 helper = TypeMoq . Mock . ofType < ICodeExecutionHelper > ( ) ;
57+ commandManager = TypeMoq . Mock . ofType < ICommandManager > ( ) ;
5558
5659 // Setup default settings
5760 pythonSettings . datascience = {
@@ -94,6 +97,13 @@ suite('DataScience Code Watcher Unit Tests', () => {
9497 // Setup config service
9598 configService . setup ( c => c . getSettings ( ) ) . returns ( ( ) => pythonSettings ) ;
9699
100+ commandManager . setup ( c => c . executeCommand ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( c , n , v ) => {
101+ if ( c === 'setContext' ) {
102+ contexts . set ( n , v ) ;
103+ }
104+ return Promise . resolve ( ) ;
105+ } ) ;
106+
97107 codeWatcher = new CodeWatcher ( appShell . object , logger . object , historyProvider . object , fileSystem . object , configService . object , documentManager . object , helper . object ) ;
98108 } ) ;
99109
@@ -657,20 +667,24 @@ testing2`; // Command tests override getText, so just need the ranges here
657667 const inputText = '#%% foobar' ;
658668 const document = createDocument ( inputText , fileName , version , TypeMoq . Times . atLeastOnce ( ) ) ;
659669 documentManager . setup ( d => d . textDocuments ) . returns ( ( ) => [ document . object ] ) ;
660- const codeLensProvider = new DataScienceCodeLensProvider ( serviceContainer . object , documentManager . object , configService . object ) ;
670+ const codeLensProvider = new DataScienceCodeLensProvider ( serviceContainer . object , documentManager . object , configService . object , commandManager . object ) ;
661671
662672 let result = codeLensProvider . provideCodeLenses ( document . object , tokenSource . token ) ;
663673 expect ( result , 'result not okay' ) . to . be . ok ;
664674 let codeLens = result as CodeLens [ ] ;
665675 expect ( codeLens . length ) . to . equal ( 2 , 'Code lens wrong length' ) ;
666676
677+ expect ( contexts . get ( EditorContexts . HasCodeCells ) ) . to . be . equal ( true , 'Code cells context not set' ) ;
678+
667679 // Change settings
668680 pythonSettings . datascience . codeRegularExpression = '#%%%.*dude' ;
669681 result = codeLensProvider . provideCodeLenses ( document . object , tokenSource . token ) ;
670682 expect ( result , 'result not okay' ) . to . be . ok ;
671683 codeLens = result as CodeLens [ ] ;
672684 expect ( codeLens . length ) . to . equal ( 0 , 'Code lens wrong length' ) ;
673685
686+ expect ( contexts . get ( EditorContexts . HasCodeCells ) ) . to . be . equal ( false , 'Code cells context not set' ) ;
687+
674688 // Change settings to empty
675689 pythonSettings . datascience . codeRegularExpression = '' ;
676690 result = codeLensProvider . provideCodeLenses ( document . object , tokenSource . token ) ;
0 commit comments