@@ -9,6 +9,7 @@ import assert from 'assert'
99import sinon from 'sinon'
1010import globals from '../../shared/extensionGlobals'
1111import { randomUUID } from '../../shared'
12+ import * as setContext from '../../shared/vscode/setContext'
1213import { assertTelemetry , installFakeClock } from '../testUtil'
1314import {
1415 NotificationFetcher ,
@@ -45,8 +46,9 @@ describe('Notifications Controller', function () {
4546 let controller : NotificationsController
4647 let fetcher : TestFetcher
4748
48- let ruleEngineSpy : sinon . SinonSpy
49- let focusPanelSpy : sinon . SinonSpy
49+ const ruleEngineSpy = sinon . spy ( ruleEngine , 'shouldDisplayNotification' )
50+ const focusPanelSpy = sinon . spy ( panelNode , 'focusPanel' )
51+ const setContextSpy = sinon . spy ( setContext , 'setContext' )
5052
5153 function dismissNotification ( notification : ToolkitNotification ) {
5254 // We could call `controller.dismissNotification()`, but this emulates a call
@@ -89,10 +91,7 @@ describe('Notifications Controller', function () {
8991 beforeEach ( async function ( ) {
9092 panelNode . setNotifications ( [ ] , [ ] )
9193 fetcher = new TestFetcher ( )
92- controller = new NotificationsController ( panelNode , fetcher )
93-
94- ruleEngineSpy = sinon . spy ( ruleEngine , 'shouldDisplayNotification' )
95- focusPanelSpy = sinon . spy ( panelNode , 'focusPanel' )
94+ controller = new NotificationsController ( panelNode , fetcher , '_aws.test.notification' as any )
9695
9796 await globals . globalState . update ( controller . storageKey , {
9897 startUp : { } as NotificationData ,
@@ -102,8 +101,14 @@ describe('Notifications Controller', function () {
102101 } )
103102
104103 afterEach ( function ( ) {
105- ruleEngineSpy . restore ( )
104+ ruleEngineSpy . resetHistory ( )
105+ focusPanelSpy . resetHistory ( )
106+ setContextSpy . resetHistory ( )
107+ } )
108+
109+ after ( function ( ) {
106110 focusPanelSpy . restore ( )
111+ setContextSpy . restore ( )
107112 } )
108113
109114 it ( 'can fetch and store startup notifications' , async function ( ) {
@@ -135,6 +140,7 @@ 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 ) )
138144 } )
139145
140146 it ( 'can fetch and store emergency notifications' , async function ( ) {
@@ -166,6 +172,7 @@ describe('Notifications Controller', function () {
166172 assert . deepStrictEqual ( panelNode . emergencyNotifications , [ content . notifications [ 0 ] ] )
167173 assert . equal ( panelNode . getChildren ( ) . length , 1 )
168174 assert . equal ( focusPanelSpy . callCount , 1 )
175+ assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
169176 } )
170177
171178 it ( 'can fetch and store both startup and emergency notifications' , async function ( ) {
@@ -224,6 +231,7 @@ describe('Notifications Controller', function () {
224231 assert . deepStrictEqual ( panelNode . emergencyNotifications , [ emergencyContent . notifications [ 0 ] ] )
225232 assert . equal ( panelNode . getChildren ( ) . length , 2 )
226233 assert . equal ( focusPanelSpy . callCount , 1 )
234+ assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
227235 } )
228236
229237 it ( 'dismisses a startup notification' , async function ( ) {
@@ -241,6 +249,7 @@ describe('Notifications Controller', function () {
241249
242250 assert . equal ( panelNode . getChildren ( ) . length , 2 )
243251 assert . equal ( panelNode . startUpNotifications . length , 2 )
252+ assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
244253
245254 assert . deepStrictEqual ( await globals . globalState . get ( controller . storageKey ) , {
246255 startUp : {
@@ -281,9 +290,11 @@ describe('Notifications Controller', function () {
281290
282291 await controller . pollForStartUp ( ruleEngine )
283292 assert . equal ( panelNode . getChildren ( ) . length , 1 )
293+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
284294
285295 await dismissNotification ( content . notifications [ 0 ] )
286296 assert . equal ( panelNode . getChildren ( ) . length , 0 )
297+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , false ] )
287298
288299 content . notifications . push ( getValidTestNotification ( 'id:startup2' ) )
289300 fetcher . setStartUpContent ( {
@@ -305,6 +316,7 @@ describe('Notifications Controller', function () {
305316 } )
306317
307318 assert . equal ( panelNode . getChildren ( ) . length , 1 )
319+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
308320 } )
309321
310322 it ( 'does not refocus emergency notifications' , async function ( ) {
@@ -434,6 +446,7 @@ describe('Notifications Controller', function () {
434446 newlyReceived : [ ] ,
435447 } )
436448 assert . equal ( panelNode . getChildren ( ) . length , 1 )
449+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
437450
438451 fetcher . setEmergencyContent ( {
439452 eTag : '1' ,
@@ -455,6 +468,7 @@ describe('Notifications Controller', function () {
455468 } )
456469
457470 assert . equal ( panelNode . getChildren ( ) . length , 0 )
471+ assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , false ] )
458472 } )
459473
460474 it ( 'does not rethrow errors when fetching' , async function ( ) {
0 commit comments