@@ -8,7 +8,8 @@ import * as FakeTimers from '@sinonjs/fake-timers'
88import assert from 'assert'
99import sinon from 'sinon'
1010import globals from '../../shared/extensionGlobals'
11- import { randomUUID } from '../../shared'
11+ import { randomUUID } from '../../shared/crypto'
12+ import * as setContext from '../../shared/vscode/setContext'
1213import { assertTelemetry , installFakeClock } from '../testUtil'
1314import {
1415 NotificationFetcher ,
@@ -89,7 +90,7 @@ describe('Notifications Controller', function () {
8990 beforeEach ( async function ( ) {
9091 panelNode . setNotifications ( [ ] , [ ] )
9192 fetcher = new TestFetcher ( )
92- controller = new NotificationsController ( panelNode , fetcher )
93+ controller = new NotificationsController ( panelNode , fetcher , '_aws.test.notification' as any )
9394
9495 ruleEngineSpy = sinon . spy ( ruleEngine , 'shouldDisplayNotification' )
9596 focusPanelSpy = sinon . spy ( panelNode , 'focusPanel' )
@@ -107,6 +108,10 @@ describe('Notifications Controller', function () {
107108 } )
108109
109110 it ( 'can fetch and store startup notifications' , async function ( ) {
111+ // There seems to be a race condition with having a global spy object that is reset after each
112+ // test. Doesn't seem to affect the other ones, for some reason.
113+ const setContextSpy = sinon . spy ( setContext , 'setContext' )
114+
110115 const eTag = randomUUID ( )
111116 const content = {
112117 schemaVersion : '1.x' ,
@@ -135,9 +140,14 @@ describe('Notifications Controller', function () {
135140 assert . deepStrictEqual ( panelNode . startUpNotifications , [ content . notifications [ 0 ] ] )
136141 assert . equal ( panelNode . getChildren ( ) . length , 1 )
137142 assert . equal ( focusPanelSpy . callCount , 0 )
143+ assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
144+
145+ setContextSpy . restore ( )
138146 } )
139147
140148 it ( 'can fetch and store emergency notifications' , async function ( ) {
149+ const setContextSpy = sinon . spy ( setContext , 'setContext' )
150+
141151 const eTag = randomUUID ( )
142152 const content = {
143153 schemaVersion : '1.x' ,
@@ -166,9 +176,14 @@ describe('Notifications Controller', function () {
166176 assert . deepStrictEqual ( panelNode . emergencyNotifications , [ content . notifications [ 0 ] ] )
167177 assert . equal ( panelNode . getChildren ( ) . length , 1 )
168178 assert . equal ( focusPanelSpy . callCount , 1 )
179+ assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
180+
181+ setContextSpy . restore ( )
169182 } )
170183
171184 it ( 'can fetch and store both startup and emergency notifications' , async function ( ) {
185+ const setContextSpy = sinon . spy ( setContext , 'setContext' )
186+
172187 const eTag1 = randomUUID ( )
173188 const eTag2 = randomUUID ( )
174189 const startUpContent = {
@@ -224,9 +239,14 @@ describe('Notifications Controller', function () {
224239 assert . deepStrictEqual ( panelNode . emergencyNotifications , [ emergencyContent . notifications [ 0 ] ] )
225240 assert . equal ( panelNode . getChildren ( ) . length , 2 )
226241 assert . equal ( focusPanelSpy . callCount , 1 )
242+ assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
243+
244+ setContextSpy . restore ( )
227245 } )
228246
229247 it ( 'dismisses a startup notification' , async function ( ) {
248+ const setContextSpy = sinon . spy ( setContext , 'setContext' )
249+
230250 const eTag = randomUUID ( )
231251 const content = {
232252 schemaVersion : '1.x' ,
@@ -241,6 +261,7 @@ describe('Notifications Controller', function () {
241261
242262 assert . equal ( panelNode . getChildren ( ) . length , 2 )
243263 assert . equal ( panelNode . startUpNotifications . length , 2 )
264+ assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
244265
245266 assert . deepStrictEqual ( await globals . globalState . get ( controller . storageKey ) , {
246267 startUp : {
@@ -267,9 +288,13 @@ describe('Notifications Controller', function () {
267288
268289 assert . equal ( panelNode . getChildren ( ) . length , 1 )
269290 assert . equal ( panelNode . startUpNotifications . length , 1 )
291+
292+ setContextSpy . restore ( )
270293 } )
271294
272295 it ( 'does not redisplay dismissed notifications' , async function ( ) {
296+ const setContextSpy = sinon . spy ( setContext , 'setContext' )
297+
273298 const content = {
274299 schemaVersion : '1.x' ,
275300 notifications : [ getValidTestNotification ( 'id:startup1' ) ] ,
@@ -281,9 +306,11 @@ describe('Notifications Controller', function () {
281306
282307 await controller . pollForStartUp ( ruleEngine )
283308 assert . equal ( panelNode . getChildren ( ) . length , 1 )
309+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
284310
285311 await dismissNotification ( content . notifications [ 0 ] )
286312 assert . equal ( panelNode . getChildren ( ) . length , 0 )
313+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , false ] )
287314
288315 content . notifications . push ( getValidTestNotification ( 'id:startup2' ) )
289316 fetcher . setStartUpContent ( {
@@ -305,6 +332,9 @@ describe('Notifications Controller', function () {
305332 } )
306333
307334 assert . equal ( panelNode . getChildren ( ) . length , 1 )
335+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
336+
337+ setContextSpy . restore ( )
308338 } )
309339
310340 it ( 'does not refocus emergency notifications' , async function ( ) {
@@ -376,6 +406,8 @@ describe('Notifications Controller', function () {
376406 } )
377407
378408 it ( 'cleans out dismissed state' , async function ( ) {
409+ const setContextSpy = sinon . spy ( setContext , 'setContext' )
410+
379411 const startUpContent = {
380412 schemaVersion : '1.x' ,
381413 notifications : [ getValidTestNotification ( 'id:startup1' ) ] ,
@@ -434,6 +466,7 @@ describe('Notifications Controller', function () {
434466 newlyReceived : [ ] ,
435467 } )
436468 assert . equal ( panelNode . getChildren ( ) . length , 1 )
469+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
437470
438471 fetcher . setEmergencyContent ( {
439472 eTag : '1' ,
@@ -455,6 +488,9 @@ describe('Notifications Controller', function () {
455488 } )
456489
457490 assert . equal ( panelNode . getChildren ( ) . length , 0 )
491+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , false ] )
492+
493+ setContextSpy . restore ( )
458494 } )
459495
460496 it ( 'does not rethrow errors when fetching' , async function ( ) {
0 commit comments