11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33import { assert } from 'chai' ;
4- import { anything , instance , mock , when } from 'ts-mockito' ;
4+ import { anything , instance , mock , verify , when } from 'ts-mockito' ;
55
66import { QuickPickItem } from 'vscode' ;
77import { ApplicationShell } from '../../../client/common/application/applicationShell' ;
8+ import { CommandManager } from '../../../client/common/application/commandManager' ;
9+ import { ICommandManager } from '../../../client/common/application/types' ;
810import { ConfigurationService } from '../../../client/common/configuration/service' ;
11+ import { IDataScienceSettings } from '../../../client/common/types' ;
912import { DataScience } from '../../../client/common/utils/localize' ;
1013import { noop } from '../../../client/common/utils/misc' ;
1114import { MultiStepInputFactory } from '../../../client/common/utils/multiStepInput' ;
@@ -19,29 +22,38 @@ import { MockQuickPick } from '../mockQuickPick';
1922// tslint:disable: max-func-body-length
2023suite ( 'Data Science - Jupyter Server URI Selector' , ( ) => {
2124 let quickPick : MockQuickPick | undefined ;
22-
25+ let cmdManager : ICommandManager ;
26+ let dsSettings : IDataScienceSettings ;
2327 function createDataScienceObject (
2428 quickPickSelection : string ,
2529 inputSelection : string ,
2630 updateCallback : ( val : string ) => void ,
2731 mockStorage ?: MockMemento
2832 ) : JupyterServerSelector {
33+ dsSettings = {
34+ jupyterServerURI : Settings . JupyterServerLocalLaunch
35+ // tslint:disable-next-line: no-any
36+ } as any ;
2937 const configService = mock ( ConfigurationService ) ;
3038 const applicationShell = mock ( ApplicationShell ) ;
39+ cmdManager = mock ( CommandManager ) ;
3140 const storage = mockStorage ? mockStorage : new MockMemento ( ) ;
3241 quickPick = new MockQuickPick ( quickPickSelection ) ;
3342 const input = new MockInputBox ( inputSelection ) ;
43+ when ( cmdManager . executeCommand ( anything ( ) , anything ( ) ) ) . thenResolve ( ) ;
3444 when ( applicationShell . createQuickPick ( ) ) . thenReturn ( quickPick ! ) ;
3545 when ( applicationShell . createInputBox ( ) ) . thenReturn ( input ) ;
3646 const multiStepFactory = new MultiStepInputFactory ( instance ( applicationShell ) ) ;
47+ // tslint:disable-next-line: no-any
48+ when ( configService . getSettings ( anything ( ) ) ) . thenReturn ( { datascience : dsSettings } as any ) ;
3749 when ( configService . updateSetting ( 'dataScience.jupyterServerURI' , anything ( ) , anything ( ) , anything ( ) ) ) . thenCall (
3850 ( _a1 , a2 , _a3 , _a4 ) => {
3951 updateCallback ( a2 ) ;
4052 return Promise . resolve ( ) ;
4153 }
4254 ) ;
4355
44- return new JupyterServerSelector ( storage , multiStepFactory , instance ( configService ) ) ;
56+ return new JupyterServerSelector ( storage , multiStepFactory , instance ( configService ) , instance ( cmdManager ) ) ;
4557 }
4658
4759 test ( 'Local pick server uri' , async ( ) => {
@@ -130,6 +142,23 @@ suite('Data Science - Jupyter Server URI Selector', () => {
130142 assert . equal ( value , 'http://localhost:1111' , 'Already running should end up with the user inputed value' ) ;
131143 } ) ;
132144
145+ test ( 'Remote server uri (reload VSCode if there is a change in settings)' , async ( ) => {
146+ let value = '' ;
147+ const ds = createDataScienceObject ( '$(server) Existing' , 'http://localhost:1111' , v => ( value = v ) ) ;
148+ await ds . selectJupyterURI ( ) ;
149+ assert . equal ( value , 'http://localhost:1111' , 'Already running should end up with the user inputed value' ) ;
150+ verify ( cmdManager . executeCommand ( anything ( ) , anything ( ) ) ) . once ( ) ;
151+ } ) ;
152+
153+ test ( 'Remote server uri (do not reload VSCode if there is no change in settings)' , async ( ) => {
154+ let value = '' ;
155+ const ds = createDataScienceObject ( '$(server) Existing' , 'http://localhost:1111' , v => ( value = v ) ) ;
156+ dsSettings . jupyterServerURI = 'http://localhost:1111' ;
157+ await ds . selectJupyterURI ( ) ;
158+ assert . equal ( value , 'http://localhost:1111' , 'Already running should end up with the user inputed value' ) ;
159+ verify ( cmdManager . executeCommand ( anything ( ) , anything ( ) ) ) . never ( ) ;
160+ } ) ;
161+
133162 test ( 'Invalid server uri' , async ( ) => {
134163 let value = '' ;
135164 const ds = createDataScienceObject ( '$(server) Existing' , 'httx://localhost:1111' , v => ( value = v ) ) ;
0 commit comments