1
1
import * as vscode from 'vscode' ;
2
2
import { beforeEach , afterEach } from 'mocha' ;
3
- import chai from 'chai' ;
3
+ import { expect } from 'chai' ;
4
4
import sinon from 'sinon' ;
5
5
import type { DataService } from 'mongodb-data-service' ;
6
+ import path from 'path' ;
6
7
7
8
import ActiveConnectionCodeLensProvider from '../../../editors/activeConnectionCodeLensProvider' ;
8
9
import ConnectionController from '../../../connectionController' ;
@@ -12,8 +13,6 @@ import { ExtensionContextStub } from '../stubs';
12
13
import TelemetryService from '../../../telemetry/telemetryService' ;
13
14
import { TEST_DATABASE_URI } from '../dbTestHelper' ;
14
15
15
- const expect = chai . expect ;
16
-
17
16
suite ( 'Active Connection CodeLens Provider Test Suite' , ( ) => {
18
17
const extensionContextStub = new ExtensionContextStub ( ) ;
19
18
const testStorageController = new StorageController ( extensionContextStub ) ;
@@ -42,19 +41,23 @@ suite('Active Connection CodeLens Provider Test Suite', () => {
42
41
} ) ;
43
42
44
43
suite ( 'the MongoDB playground in JS' , ( ) => {
44
+ const mockFileName = path . join ( 'nonexistent' , 'playground-test.mongodb.js' ) ;
45
+ const mockDocumentUri = vscode . Uri . from ( {
46
+ path : mockFileName ,
47
+ scheme : 'untitled' ,
48
+ } ) ;
49
+ const mockTextDoc : vscode . TextDocument = {
50
+ uri : mockDocumentUri ,
51
+ } as Pick < vscode . TextDocument , 'uri' > as vscode . TextDocument ;
52
+
45
53
suite ( 'user is not connected' , ( ) => {
46
54
beforeEach ( ( ) => {
47
- testCodeLensProvider . setActiveTextEditor (
48
- vscode . window . activeTextEditor
49
- ) ;
50
55
const fakeShowQuickPick = sandbox . fake ( ) ;
51
56
sandbox . replace ( vscode . window , 'showQuickPick' , fakeShowQuickPick ) ;
52
- const fakeIsPlayground = sandbox . fake . returns ( true ) ;
53
- sandbox . replace ( testCodeLensProvider , 'isPlayground' , fakeIsPlayground ) ;
54
57
} ) ;
55
58
56
59
test ( 'show disconnected message in code lenses' , ( ) => {
57
- const codeLens = testCodeLensProvider . provideCodeLenses ( ) ;
60
+ const codeLens = testCodeLensProvider . provideCodeLenses ( mockTextDoc ) ;
58
61
59
62
expect ( codeLens ) . to . be . an ( 'array' ) ;
60
63
expect ( codeLens . length ) . to . be . equal ( 1 ) ;
@@ -89,16 +92,11 @@ suite('Active Connection CodeLens Provider Test Suite', () => {
89
92
} as unknown as DataService ;
90
93
91
94
testConnectionController . setActiveDataService ( activeDataServiceStub ) ;
92
- testCodeLensProvider . setActiveTextEditor (
93
- vscode . window . activeTextEditor
94
- ) ;
95
95
sandbox . replace (
96
96
testConnectionController ,
97
97
'getActiveConnectionName' ,
98
98
sandbox . fake . returns ( 'fakeName' )
99
99
) ;
100
- const fakeIsPlayground = sandbox . fake . returns ( true ) ;
101
- sandbox . replace ( testCodeLensProvider , 'isPlayground' , fakeIsPlayground ) ;
102
100
} ) ;
103
101
104
102
test ( 'show active connection in code lenses' , ( ) => {
@@ -109,7 +107,7 @@ suite('Active Connection CodeLens Provider Test Suite', () => {
109
107
url : TEST_DATABASE_URI ,
110
108
} )
111
109
) ;
112
- const codeLens = testCodeLensProvider . provideCodeLenses ( ) ;
110
+ const codeLens = testCodeLensProvider . provideCodeLenses ( mockTextDoc ) ;
113
111
114
112
expect ( codeLens ) . to . be . an ( 'array' ) ;
115
113
expect ( codeLens . length ) . to . be . equal ( 1 ) ;
@@ -131,7 +129,7 @@ suite('Active Connection CodeLens Provider Test Suite', () => {
131
129
url : `${ TEST_DATABASE_URI } /fakeDBName` ,
132
130
} )
133
131
) ;
134
- const codeLens = testCodeLensProvider . provideCodeLenses ( ) ;
132
+ const codeLens = testCodeLensProvider . provideCodeLenses ( mockTextDoc ) ;
135
133
expect ( codeLens ) . to . be . an ( 'array' ) ;
136
134
expect ( codeLens . length ) . to . be . equal ( 1 ) ;
137
135
expect ( codeLens [ 0 ] . command ?. title ) . to . be . equal (
@@ -147,16 +145,23 @@ suite('Active Connection CodeLens Provider Test Suite', () => {
147
145
} ) ;
148
146
149
147
suite ( 'the regular JS file' , ( ) => {
148
+ const mockFileName = path . join ( 'nonexistent' , 'playground-test.js' ) ;
149
+ const mockDocumentUri = vscode . Uri . from ( {
150
+ path : mockFileName ,
151
+ scheme : 'untitled' ,
152
+ } ) ;
153
+ const mockTextDoc : vscode . TextDocument = {
154
+ uri : mockDocumentUri ,
155
+ } as Pick < vscode . TextDocument , 'uri' > as vscode . TextDocument ;
156
+
150
157
suite ( 'user is not connected' , ( ) => {
151
158
beforeEach ( ( ) => {
152
159
const fakeShowQuickPick = sandbox . fake ( ) ;
153
160
sandbox . replace ( vscode . window , 'showQuickPick' , fakeShowQuickPick ) ;
154
- const fakeIsPlayground = sandbox . fake . returns ( false ) ;
155
- sandbox . replace ( testCodeLensProvider , 'isPlayground' , fakeIsPlayground ) ;
156
161
} ) ;
157
162
158
163
test ( 'show not show the active connection code lenses' , ( ) => {
159
- const codeLens = testCodeLensProvider . provideCodeLenses ( ) ;
164
+ const codeLens = testCodeLensProvider . provideCodeLenses ( mockTextDoc ) ;
160
165
161
166
expect ( codeLens ) . to . be . an ( 'array' ) ;
162
167
expect ( codeLens . length ) . to . be . equal ( 0 ) ;
@@ -191,12 +196,10 @@ suite('Active Connection CodeLens Provider Test Suite', () => {
191
196
'getActiveConnectionName' ,
192
197
sandbox . fake . returns ( 'fakeName' )
193
198
) ;
194
- const fakeIsPlayground = sandbox . fake . returns ( false ) ;
195
- sandbox . replace ( testCodeLensProvider , 'isPlayground' , fakeIsPlayground ) ;
196
199
} ) ;
197
200
198
- test ( 'show not show the active connection code lensess ' , ( ) => {
199
- const codeLens = testCodeLensProvider . provideCodeLenses ( ) ;
201
+ test ( 'show not show the active connection code lenses ' , ( ) => {
202
+ const codeLens = testCodeLensProvider . provideCodeLenses ( mockTextDoc ) ;
200
203
201
204
expect ( codeLens ) . to . be . an ( 'array' ) ;
202
205
expect ( codeLens . length ) . to . be . equal ( 0 ) ;
0 commit comments