4
4
*/
5
5
6
6
import assert from 'assert'
7
- import * as sinon from 'sinon'
8
- import * as vscode from 'vscode'
9
-
10
- import { FakeExtensionContext } from '../../fakeExtensionContext'
11
7
import {
12
8
handleTelemetryNoticeResponse ,
13
9
noticeResponseViewSettings ,
14
10
noticeResponseOk ,
15
- TELEMETRY_NOTICE_VERSION_ACKNOWLEDGED ,
16
11
hasUserSeenTelemetryNotice ,
17
12
setHasUserSeenTelemetryNotice ,
18
13
} from '../../../shared/telemetry/activation'
14
+ import globals from '../../../shared/extensionGlobals'
19
15
20
16
describe ( 'handleTelemetryNoticeResponse' , function ( ) {
21
- let extensionContext : vscode . ExtensionContext
22
- let sandbox : sinon . SinonSandbox
23
-
24
- before ( function ( ) {
25
- sandbox = sinon . createSandbox ( )
26
- } )
27
-
28
- after ( function ( ) {
29
- sandbox . restore ( )
30
- } )
31
-
32
- beforeEach ( async function ( ) {
33
- extensionContext = await FakeExtensionContext . create ( )
34
- } )
35
-
36
17
it ( 'does nothing when notice is discarded' , async function ( ) {
37
- await handleTelemetryNoticeResponse ( undefined , extensionContext )
38
-
18
+ await handleTelemetryNoticeResponse ( undefined )
39
19
assert . strictEqual (
40
- extensionContext . globalState . get ( TELEMETRY_NOTICE_VERSION_ACKNOWLEDGED ) ,
20
+ globals . globalState . get ( 'awsTelemetryNoticeVersionAck' ) ,
41
21
undefined ,
42
22
'Expected opt out shown state to remain unchanged'
43
23
)
44
24
} )
45
25
46
26
it ( 'handles View Settings response' , async function ( ) {
47
- const executeCommand = sandbox . stub ( vscode . commands , 'executeCommand' )
48
-
49
- await handleTelemetryNoticeResponse ( noticeResponseViewSettings , extensionContext )
50
-
51
- assert . ok ( executeCommand . calledOnce , 'Expected to trigger View Settings' )
27
+ await handleTelemetryNoticeResponse ( noticeResponseViewSettings )
52
28
assert . strictEqual (
53
- extensionContext . globalState . get ( TELEMETRY_NOTICE_VERSION_ACKNOWLEDGED ) ,
29
+ globals . globalState . get ( 'awsTelemetryNoticeVersionAck' ) ,
54
30
2 ,
55
31
'Expected opt out shown state to be set'
56
32
)
57
33
} )
58
34
59
35
it ( 'handles Ok response' , async function ( ) {
60
- await handleTelemetryNoticeResponse ( noticeResponseOk , extensionContext )
36
+ await handleTelemetryNoticeResponse ( noticeResponseOk )
61
37
62
38
assert . strictEqual (
63
- extensionContext . globalState . get ( TELEMETRY_NOTICE_VERSION_ACKNOWLEDGED ) ,
39
+ globals . globalState . get ( 'awsTelemetryNoticeVersionAck' ) ,
64
40
2 ,
65
41
'Expected opt out shown state to be set'
66
42
)
67
43
} )
68
44
} )
69
45
70
46
describe ( 'hasUserSeenTelemetryNotice' , async function ( ) {
71
- let extensionContext : vscode . ExtensionContext
72
- let sandbox : sinon . SinonSandbox
73
-
74
- before ( function ( ) {
75
- sandbox = sinon . createSandbox ( )
76
- } )
77
-
78
- after ( function ( ) {
79
- sandbox . restore ( )
80
- } )
81
-
82
- beforeEach ( async function ( ) {
83
- extensionContext = await FakeExtensionContext . create ( )
84
- } )
47
+ beforeEach ( async function ( ) { } )
85
48
86
49
it ( 'is affected by setHasUserSeenTelemetryNotice' , async function ( ) {
87
- assert . ok ( ! hasUserSeenTelemetryNotice ( extensionContext ) )
88
- await setHasUserSeenTelemetryNotice ( extensionContext )
89
- assert . ok ( hasUserSeenTelemetryNotice ( extensionContext ) )
50
+ assert . ok ( ! hasUserSeenTelemetryNotice ( ) )
51
+ await setHasUserSeenTelemetryNotice ( )
52
+ assert . ok ( hasUserSeenTelemetryNotice ( ) )
90
53
} )
91
54
92
55
const scenarios = [
@@ -98,8 +61,8 @@ describe('hasUserSeenTelemetryNotice', async function () {
98
61
99
62
scenarios . forEach ( ( scenario ) => {
100
63
it ( scenario . desc , async ( ) => {
101
- await extensionContext . globalState . update ( TELEMETRY_NOTICE_VERSION_ACKNOWLEDGED , scenario . currentState )
102
- assert . strictEqual ( hasUserSeenTelemetryNotice ( extensionContext ) , scenario . expectedHasSeen )
64
+ await globals . globalState . update ( 'awsTelemetryNoticeVersionAck' , scenario . currentState )
65
+ assert . strictEqual ( hasUserSeenTelemetryNotice ( ) , scenario . expectedHasSeen )
103
66
} )
104
67
} )
105
68
} )
0 commit comments