@@ -28,15 +28,16 @@ suite("new-middleware command", () => {
28
28
utilsStub = {
29
29
nearestParentDartFrogProject : sinon . stub ( ) ,
30
30
normalizeRoutePath : sinon . stub ( ) ,
31
- resolveDartFrogProjectPathFromWorkspace : sinon . stub ( ) ,
31
+ resolveDartFrogProjectPathFromActiveTextEditor : sinon . stub ( ) ,
32
+ resolveDartFrogProjectPathFromWorkspaceFolders : sinon . stub ( ) ,
32
33
isDartFrogCLIInstalled : sinon . stub ( ) ,
33
34
suggestInstallingDartFrogCLI : sinon . stub ( ) ,
34
35
} ;
35
36
utilsStub . isDartFrogCLIInstalled . returns ( true ) ;
36
37
37
38
utilsStub . nearestParentDartFrogProject
38
39
. withArgs ( invalidUri . fsPath )
39
- . returns ( undefined ) ;
40
+ . returns ( ) ;
40
41
utilsStub . nearestParentDartFrogProject
41
42
. withArgs ( validUri . fsPath )
42
43
. returns ( validUri . fsPath ) ;
@@ -74,9 +75,10 @@ suite("new-middleware command", () => {
74
75
} ) ;
75
76
76
77
suite ( "file open dialog" , ( ) => {
77
- test ( "is shown when Uri is undefined and fails to resolve a path from workspace" , async ( ) => {
78
+ test ( "is shown when Uri is undefined and fails to resolve a path from workspace folder " , async ( ) => {
78
79
vscodeStub . window . showOpenDialog . resolves ( ) ;
79
- utilsStub . resolveDartFrogProjectPathFromWorkspace . returns ( undefined ) ;
80
+ utilsStub . resolveDartFrogProjectPathFromActiveTextEditor . returns ( ) ;
81
+ utilsStub . resolveDartFrogProjectPathFromWorkspaceFolders . returns ( ) ;
80
82
81
83
await command . newMiddleware ( ) ;
82
84
@@ -88,22 +90,40 @@ suite("new-middleware command", () => {
88
90
} ) ;
89
91
} ) ;
90
92
91
- test ( "is not shown when Uri is undefined but resolves a path from workspace" , async ( ) => {
92
- utilsStub . resolveDartFrogProjectPathFromWorkspace . returns (
93
- "/home/dart_frog/routes"
94
- ) ;
95
- utilsStub . nearestParentDartFrogProject . returns ( "/home/dart_frog/" ) ;
96
- utilsStub . normalizeRoutePath . returns ( "/" ) ;
93
+ suite ( "is not shown" , ( ) => {
94
+ test ( "when Uri is defined" , async ( ) => {
95
+ await command . newMiddleware ( invalidUri ) ;
97
96
98
- await command . newMiddleware ( ) ;
97
+ sinon . assert . notCalled ( vscodeStub . window . showOpenDialog ) ;
98
+ } ) ;
99
99
100
- sinon . assert . notCalled ( vscodeStub . window . showOpenDialog ) ;
101
- } ) ;
100
+ test ( "when Uri is undefined but resolves a path from active text editor" , async ( ) => {
101
+ utilsStub . resolveDartFrogProjectPathFromActiveTextEditor . returns (
102
+ "/home/dart_frog/routes/index.dart"
103
+ ) ;
104
+ utilsStub . nearestParentDartFrogProject . returns ( "/home/dart_frog/" ) ;
105
+ utilsStub . normalizeRoutePath . returns ( "/" ) ;
102
106
103
- test ( "is not shown when Uri is defined" , async ( ) => {
104
- await command . newMiddleware ( invalidUri ) ;
107
+ await command . newMiddleware ( ) ;
108
+
109
+ sinon . assert . notCalled ( vscodeStub . window . showOpenDialog ) ;
110
+ } ) ;
105
111
106
- sinon . assert . notCalled ( vscodeStub . window . showOpenDialog ) ;
112
+ test ( "when Uri and active text editor are undefined but resolves a path from workspace folder" , async ( ) => {
113
+ utilsStub . resolveDartFrogProjectPathFromActiveTextEditor . returns ( ) ;
114
+ utilsStub . resolveDartFrogProjectPathFromWorkspaceFolders . returns (
115
+ "/home/dart_frog/routes"
116
+ ) ;
117
+ utilsStub . nearestParentDartFrogProject . returns ( "/home/dart_frog/" ) ;
118
+ utilsStub . normalizeRoutePath . returns ( "/" ) ;
119
+
120
+ await command . newMiddleware ( ) ;
121
+
122
+ sinon . assert . called (
123
+ utilsStub . resolveDartFrogProjectPathFromActiveTextEditor
124
+ ) ;
125
+ sinon . assert . notCalled ( vscodeStub . window . showOpenDialog ) ;
126
+ } ) ;
107
127
} ) ;
108
128
} ) ;
109
129
@@ -159,22 +179,49 @@ suite("new-middleware command", () => {
159
179
) ;
160
180
161
181
suite ( "prompts for route path" , ( ) => {
162
- test ( "is shown when Uri is undefined and selected file is valid" , async ( ) => {
163
- vscodeStub . window . showInputBox . returns ( "animals/frog" ) ;
164
- utilsStub . resolveDartFrogProjectPathFromWorkspace . returns (
165
- "home/routes/animals/frog"
166
- ) ;
167
- utilsStub . nearestParentDartFrogProject . returns (
168
- "home/routes/animals/frog"
169
- ) ;
170
- utilsStub . normalizeRoutePath . returns ( "/animals/frog" ) ;
182
+ suite ( "is shown" , ( ) => {
183
+ test ( "when Uri is undefined and resolved active text editor is valid" , async ( ) => {
184
+ vscodeStub . window . showInputBox . returns ( "animals/frog" ) ;
185
+ utilsStub . resolveDartFrogProjectPathFromActiveTextEditor . returns (
186
+ "home/routes/animals/frog"
187
+ ) ;
188
+ utilsStub . nearestParentDartFrogProject . returns (
189
+ "home/routes/animals/frog"
190
+ ) ;
191
+ utilsStub . normalizeRoutePath . returns ( "/animals/frog" ) ;
171
192
172
- await command . newMiddleware ( ) ;
193
+ await command . newMiddleware ( ) ;
173
194
174
- sinon . assert . calledWith ( vscodeStub . window . showInputBox , {
175
- prompt : "Middleware's route path" ,
176
- value : "/animals/frog" ,
177
- placeHolder : "_middleware" ,
195
+ sinon . assert . notCalled (
196
+ utilsStub . resolveDartFrogProjectPathFromWorkspaceFolders
197
+ ) ;
198
+ sinon . assert . calledWith ( vscodeStub . window . showInputBox , {
199
+ prompt : "Middleware's route path" ,
200
+ value : "/animals/frog" ,
201
+ placeHolder : "_middleware" ,
202
+ } ) ;
203
+ } ) ;
204
+
205
+ test ( "when Uri and resolved active text editor are undefined but resolved workspace file is valid" , async ( ) => {
206
+ vscodeStub . window . showInputBox . returns ( "animals/frog" ) ;
207
+ utilsStub . resolveDartFrogProjectPathFromWorkspaceFolders . returns (
208
+ "home/routes/animals/frog"
209
+ ) ;
210
+ utilsStub . nearestParentDartFrogProject . returns (
211
+ "home/routes/animals/frog"
212
+ ) ;
213
+ utilsStub . normalizeRoutePath . returns ( "/animals/frog" ) ;
214
+
215
+ await command . newMiddleware ( ) ;
216
+
217
+ sinon . assert . called (
218
+ utilsStub . resolveDartFrogProjectPathFromActiveTextEditor
219
+ ) ;
220
+ sinon . assert . calledWith ( vscodeStub . window . showInputBox , {
221
+ prompt : "Middleware's route path" ,
222
+ value : "/animals/frog" ,
223
+ placeHolder : "_middleware" ,
224
+ } ) ;
178
225
} ) ;
179
226
} ) ;
180
227
@@ -199,7 +246,7 @@ suite("new-middleware command", () => {
199
246
200
247
beforeEach ( ( ) => {
201
248
vscodeStub . window . showInputBox . returns ( "animals/frog" ) ;
202
- utilsStub . resolveDartFrogProjectPathFromWorkspace . returns (
249
+ utilsStub . resolveDartFrogProjectPathFromWorkspaceFolders . returns (
203
250
"home/routes/animals/frog"
204
251
) ;
205
252
utilsStub . nearestParentDartFrogProject . returns (
@@ -225,7 +272,7 @@ suite("new-middleware command", () => {
225
272
} ) ;
226
273
227
274
test ( "is shown when prompt is undefined" , async ( ) => {
228
- vscodeStub . window . showInputBox . returns ( undefined ) ;
275
+ vscodeStub . window . showInputBox . returns ( ) ;
229
276
230
277
await command . newMiddleware ( ) ;
231
278
@@ -319,7 +366,7 @@ suite("new-middleware command", () => {
319
366
} ) ;
320
367
321
368
test ( "successfully with prompt route path" , async ( ) => {
322
- utilsStub . resolveDartFrogProjectPathFromWorkspace . returns (
369
+ utilsStub . resolveDartFrogProjectPathFromWorkspaceFolders . returns (
323
370
"home/routes/animals/frog"
324
371
) ;
325
372
utilsStub . nearestParentDartFrogProject . returns (
0 commit comments