@@ -197,31 +197,42 @@ suite('gopls opt out', () => {
197
197
sandbox . restore ( ) ;
198
198
} ) ;
199
199
200
- // testConfig, choice, probability, wantCount
201
- const testCases : [ goLanguageServer . GoplsOptOutConfig , string , number , number ] [ ] = [
200
+ const today = new Date ( ) ;
201
+ const yesterday = new Date ( today . valueOf ( ) - 1000 * 60 * 60 * 24 ) ;
202
+
203
+ // testConfig, choice, wantCount
204
+ const testCases : [ goLanguageServer . GoplsOptOutConfig , string , number ] [ ] = [
202
205
// No saved config, different choices in the first dialog box.
203
- [ { } , 'Enable' , undefined , 1 ] ,
204
- [ { } , 'Not now' , undefined , 1 ] ,
205
- [ { } , 'Never' , 1 , 2 ] ,
206
- [ { } , 'Never' , 0 , 1 ] ,
207
- [ { } , 'Never' , undefined , - 1 ] , // Non-deterministic. Skip callCount check.
208
- // Saved config, doesn't matter what the user chooses.
209
- [ { prompt : false } , '' , undefined , 0 ] ,
210
- [ { prompt : false , lastDatePrompted : new Date ( ) } , '' , undefined , 0 ] ,
211
- [ { prompt : true } , '' , undefined , 1 ] ,
212
- [ { prompt : true , lastDatePrompted : new Date ( ) } , '' , undefined , 0 ]
206
+ [ { } , 'Yes' , 1 ] ,
207
+ [ { } , 'No' , 1 ] ,
208
+ [ { } , '' , 1 ] ,
209
+ [ { lastDatePrompted : new Date ( '2020-04-02' ) } , '' , 1 ] ,
210
+ [ { lastDatePrompted : yesterday } , '' , 0 ] ,
211
+ [ { prompt : false } , '' , 0 ] ,
212
+ [ { prompt : false , lastDatePrompted : new Date ( '2020-04-02' ) } , '' , 0 ] ,
213
+ [ { prompt : false , lastDatePrompted : yesterday } , '' , 0 ] ,
214
+ [ { prompt : true } , '' , 1 ] ,
215
+ [ { prompt : true , lastDatePrompted : new Date ( '2020-04-02' ) } , 'Yes' , 1 ] ,
216
+ [ { prompt : true , lastDatePrompted : yesterday } , '' , 0 ]
213
217
] ;
214
218
215
- testCases . map ( async ( [ testConfig , choice , probability , wantCount ] , i ) => {
219
+ testCases . map ( async ( [ testConfig , choice , wantCount ] , i ) => {
216
220
test ( `opt out: ${ i } ` , async ( ) => {
217
221
const stub = sandbox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( { title : choice } ) ;
218
222
const getGoplsOptOutConfigStub = sandbox . stub ( goLanguageServer , 'getGoplsOptOutConfig' ) . returns ( testConfig ) ;
223
+ const flushGoplsOptOutConfigStub = sandbox . stub ( goLanguageServer , 'flushGoplsOptOutConfig' ) ;
219
224
220
- await goLanguageServer . promptAboutGoplsOptOut ( probability ) ;
221
- if ( wantCount >= 0 ) {
222
- assert . strictEqual ( stub . callCount , wantCount ) ;
223
- }
225
+ await goLanguageServer . promptAboutGoplsOptOut ( ) ;
226
+ assert . strictEqual ( stub . callCount , wantCount , 'unexpected call count' ) ;
224
227
sandbox . assert . called ( getGoplsOptOutConfigStub ) ;
228
+ sandbox . assert . calledOnce ( flushGoplsOptOutConfigStub ) ;
229
+ const got = flushGoplsOptOutConfigStub . getCall ( 0 ) . args [ 0 ] ;
230
+ if ( choice === 'Yes' ) assert . strictEqual ( got . prompt , false , 'unexpected prompt config stored' ) ;
231
+ if ( wantCount > 0 )
232
+ assert (
233
+ got . lastDatePrompted >= today ,
234
+ `unexpected lastDatePrompted: ${ JSON . stringify ( got . lastDatePrompted ) } `
235
+ ) ;
225
236
} ) ;
226
237
} ) ;
227
238
} ) ;
0 commit comments