1+ import { resolve } from 'path'
12import { afterEach , beforeEach , describe , it , suite } from 'mocha'
23import { expect } from 'chai'
34import { fake , restore , stub } from 'sinon'
@@ -10,10 +11,9 @@ import { DvcCli } from '../../cli/dvc'
1011import { Config } from '../../config'
1112import { RegisteredCommands } from '../../commands/external'
1213import { Title } from '../../vscode/title'
14+ import { ConfigKey } from '../../vscode/config'
1315
1416suite ( 'Status Test Suite' , ( ) => {
15- const dvcPathOption = 'dvc.dvcPath'
16-
1717 const disposable = Disposable . fn ( )
1818
1919 beforeEach ( ( ) => {
@@ -22,16 +22,19 @@ suite('Status Test Suite', () => {
2222
2323 afterEach ( async ( ) => {
2424 disposable . dispose ( )
25- await workspace . getConfiguration ( ) . update ( dvcPathOption , undefined , false )
25+ await workspace
26+ . getConfiguration ( )
27+ . update ( ConfigKey . DVC_PATH , undefined , false )
2628 return closeAllEditors ( )
2729 } )
2830
2931 describe ( 'Status' , ( ) => {
30- const disabledText = '$(circle-slash) DVC'
31- const loadingText = '$(loading~spin) DVC'
32- const waitingText = '$(circle-large-outline) DVC'
32+ const preReadyDisabledText = '$(circle-slash) DVC'
33+ const disabledText = `${ preReadyDisabledText } (Global)`
34+ const loadingText = '$(loading~spin) DVC (Global)'
35+ const waitingText = '$(circle-large-outline) DVC (Global)'
3336
34- it ( 'should show the correct status of the cli' , ( ) => {
37+ it ( 'should show the correct status of the cli' , async ( ) => {
3538 const cwd = __dirname
3639 const processCompleted = disposable . track ( new EventEmitter < CliResult > ( ) )
3740 const processStarted = disposable . track ( new EventEmitter < CliStarted > ( ) )
@@ -50,7 +53,17 @@ suite('Status Test Suite', () => {
5053 'createStatusBarItem'
5154 ) . returns ( mockStatusBarItem )
5255
53- const status = disposable . track ( new Status ( [ cli ] ) )
56+ const status = disposable . track (
57+ new Status (
58+ {
59+ getCliPath : ( ) => undefined ,
60+ getPythonBinPath : ( ) => undefined ,
61+ isPythonExtensionUsed : ( ) => false ,
62+ isReady : ( ) => Promise . resolve ( )
63+ } as unknown as Config ,
64+ cli
65+ )
66+ )
5467
5568 const firstFinishedCommand = {
5669 command : 'one is still running' ,
@@ -64,10 +77,10 @@ suite('Status Test Suite', () => {
6477 }
6578
6679 expect ( mockCreateStatusBarItem ) . to . be . calledOnce
67- expect ( mockStatusBarItem . text ) . to . equal ( disabledText )
80+ expect ( mockStatusBarItem . text ) . to . equal ( preReadyDisabledText )
6881 expect ( mockStatusBarItem . command ) . to . equal ( undefined )
6982
70- status . setAvailability ( true )
83+ await status . setAvailability ( true )
7184
7285 expect ( mockStatusBarItem . text ) . to . equal ( waitingText )
7386 expect ( mockStatusBarItem . command ) . to . equal ( undefined )
@@ -102,7 +115,7 @@ suite('Status Test Suite', () => {
102115 expect ( mockStatusBarItem . text ) . to . equal ( waitingText )
103116 expect ( mockStatusBarItem . command ) . to . equal ( undefined )
104117
105- status . setAvailability ( false )
118+ await status . setAvailability ( false )
106119
107120 expect ( mockStatusBarItem . text ) . to . equal ( disabledText )
108121 expect ( mockStatusBarItem . command ) . to . deep . equal ( {
@@ -111,7 +124,7 @@ suite('Status Test Suite', () => {
111124 } )
112125 } )
113126
114- it ( 'should floor the number of workers at 0' , ( ) => {
127+ it ( 'should floor the number of workers at 0' , async ( ) => {
115128 const processCompleted = disposable . track ( new EventEmitter < CliResult > ( ) )
116129 const processStarted = disposable . track ( new EventEmitter < CliStarted > ( ) )
117130
@@ -127,7 +140,17 @@ suite('Status Test Suite', () => {
127140 } as unknown as StatusBarItem
128141 stub ( window , 'createStatusBarItem' ) . returns ( mockStatusBarItem )
129142
130- const status = disposable . track ( new Status ( [ cli ] ) )
143+ const status = disposable . track (
144+ new Status (
145+ {
146+ getCliPath : ( ) => undefined ,
147+ getPythonBinPath : ( ) => undefined ,
148+ isPythonExtensionUsed : ( ) => false ,
149+ isReady : ( ) => Promise . resolve ( )
150+ } as unknown as Config ,
151+ cli
152+ )
153+ )
131154
132155 const mockCliResult = {
133156 command : 'there is nothing currently running' ,
@@ -137,7 +160,7 @@ suite('Status Test Suite', () => {
137160 pid : 200
138161 }
139162
140- status . setAvailability ( true )
163+ await status . setAvailability ( true )
141164
142165 processCompleted . fire ( mockCliResult )
143166 processCompleted . fire ( mockCliResult )
@@ -155,5 +178,90 @@ suite('Status Test Suite', () => {
155178 } )
156179 expect ( mockStatusBarItem . text ) . to . equal ( loadingText )
157180 } )
181+
182+ it ( 'should return the correct values dependent on the current settings' , async ( ) => {
183+ const mockedIsPythonExtensionUsed = stub ( )
184+ const mockGetCliPath = stub ( )
185+ const mockGetPythonBinPath = stub ( )
186+
187+ const mockStatusBarItem = {
188+ dispose : fake ( ) ,
189+ show : fake ( ) ,
190+ text : ''
191+ } as unknown as StatusBarItem
192+ stub ( window , 'createStatusBarItem' ) . returns ( mockStatusBarItem )
193+
194+ const status = disposable . track (
195+ new Status ( {
196+ getCliPath : mockGetCliPath ,
197+ getPythonBinPath : mockGetPythonBinPath ,
198+ isPythonExtensionUsed : mockedIsPythonExtensionUsed ,
199+ isReady : ( ) => Promise . resolve ( )
200+ } as unknown as Config )
201+ )
202+
203+ const setupMocks = (
204+ isPythonExtensionUsed : boolean ,
205+ cliPath : string | undefined ,
206+ pythonBinPath : string | undefined
207+ ) => {
208+ mockedIsPythonExtensionUsed . resetBehavior ( )
209+ mockGetCliPath . resetBehavior ( )
210+ mockGetPythonBinPath . resetBehavior ( )
211+
212+ mockedIsPythonExtensionUsed . returns ( isPythonExtensionUsed )
213+ mockGetCliPath . returns ( cliPath )
214+ mockGetPythonBinPath . returns ( pythonBinPath )
215+ }
216+
217+ setupMocks ( false , undefined , undefined )
218+
219+ await status . setAvailability ( true )
220+
221+ expect ( mockStatusBarItem . text ) . to . equal ( waitingText )
222+ expect ( mockStatusBarItem . tooltip ) . to . equal ( 'dvc' )
223+
224+ const mockPythonPath = resolve ( 'a' , 'virtual' , 'environment' )
225+
226+ setupMocks ( true , undefined , mockPythonPath )
227+
228+ await status . setAvailability ( true )
229+
230+ expect ( mockStatusBarItem . text ) . to . equal (
231+ '$(circle-large-outline) DVC (Auto)'
232+ )
233+ expect ( mockStatusBarItem . tooltip ) . to . equal (
234+ 'Interpreter set by Python extension'
235+ )
236+
237+ setupMocks ( false , undefined , mockPythonPath )
238+
239+ await status . setAvailability ( true )
240+
241+ expect ( mockStatusBarItem . text ) . to . equal (
242+ '$(circle-large-outline) DVC (Manual)'
243+ )
244+ expect ( mockStatusBarItem . tooltip ) . to . equal ( mockPythonPath )
245+
246+ const mockDvcPath = resolve ( 'path' , 'to' , 'dvc' )
247+
248+ setupMocks ( false , mockDvcPath , mockPythonPath )
249+
250+ await status . setAvailability ( true )
251+
252+ expect ( mockStatusBarItem . text ) . to . equal (
253+ '$(circle-large-outline) DVC (Global)'
254+ )
255+ expect ( mockStatusBarItem . tooltip ) . to . equal ( mockDvcPath )
256+
257+ setupMocks ( false , 'dvc' , mockPythonPath )
258+
259+ await status . setAvailability ( true )
260+
261+ expect ( mockStatusBarItem . text ) . to . equal (
262+ '$(circle-large-outline) DVC (Global)'
263+ )
264+ expect ( mockStatusBarItem . tooltip ) . to . equal ( 'dvc' )
265+ } )
158266 } )
159267} )
0 commit comments