@@ -14,10 +14,12 @@ import { randomUUID } from '../../shared'
1414import { installFakeClock } from '../testUtil'
1515import { NotificationFetcher , RemoteFetcher , ResourceResponse } from '../../notifications/controller'
1616import { HttpResourceFetcher } from '../../shared/resourcefetcher/httpResourceFetcher'
17- import { testNotificationsNode } from '../../notifications/panelNode'
17+
18+ // one test node to use across different tests
19+ // re-declaration would cause a command conflict
20+ export const panelNode : NotificationsNode = new NotificationsNode ( )
1821
1922describe ( 'Notifications Controller' , function ( ) {
20- const panelNode : NotificationsNode = testNotificationsNode
2123 const ruleEngine : RuleEngine = new RuleEngine ( {
2224 ideVersion : '1.83.0' ,
2325 extensionVersion : '1.20.0' ,
@@ -117,6 +119,7 @@ describe('Notifications Controller', function () {
117119 } ,
118120 emergency : { } ,
119121 dismissed : [ ] ,
122+ newlyReceived : [ 'id:startup2' ] ,
120123 } )
121124 assert . equal ( panelNode . startUpNotifications . length , 1 )
122125 assert . equal ( panelNode . emergencyNotifications . length , 0 )
@@ -147,6 +150,7 @@ describe('Notifications Controller', function () {
147150 eTag,
148151 } ,
149152 dismissed : [ content . notifications [ 0 ] . id ] ,
153+ newlyReceived : [ 'id:emergency2' ] ,
150154 } )
151155 assert . equal ( panelNode . startUpNotifications . length , 0 )
152156 assert . equal ( panelNode . emergencyNotifications . length , 1 )
@@ -203,6 +207,7 @@ describe('Notifications Controller', function () {
203207 eTag : eTag2 ,
204208 } ,
205209 dismissed : [ emergencyContent . notifications [ 0 ] . id ] ,
210+ newlyReceived : [ 'id:startup2' , 'id:emergency2' ] ,
206211 } )
207212 assert . equal ( panelNode . startUpNotifications . length , 1 )
208213 assert . equal ( panelNode . emergencyNotifications . length , 1 )
@@ -235,6 +240,7 @@ describe('Notifications Controller', function () {
235240 } ,
236241 emergency : { } ,
237242 dismissed : [ ] ,
243+ newlyReceived : [ ] ,
238244 } )
239245
240246 await dismissNotification ( content . notifications [ 1 ] )
@@ -247,6 +253,7 @@ describe('Notifications Controller', function () {
247253 } ,
248254 emergency : { } ,
249255 dismissed : [ content . notifications [ 1 ] . id ] ,
256+ newlyReceived : [ ] ,
250257 } )
251258
252259 assert . equal ( panelNode . getChildren ( ) . length , 1 )
@@ -285,6 +292,7 @@ describe('Notifications Controller', function () {
285292 } ,
286293 emergency : { } ,
287294 dismissed : [ content . notifications [ 0 ] . id ] ,
295+ newlyReceived : [ ] ,
288296 } )
289297
290298 assert . equal ( panelNode . getChildren ( ) . length , 1 )
@@ -336,6 +344,7 @@ describe('Notifications Controller', function () {
336344 } ,
337345 emergency : { } ,
338346 dismissed : [ ] ,
347+ newlyReceived : [ 'id:startup2' ] ,
339348 } )
340349 assert . equal ( panelNode . getChildren ( ) . length , 1 )
341350
@@ -352,6 +361,7 @@ describe('Notifications Controller', function () {
352361 } ,
353362 emergency : { } ,
354363 dismissed : [ ] ,
364+ newlyReceived : [ 'id:startup2' ] ,
355365 } )
356366 assert . equal ( panelNode . getChildren ( ) . length , 1 )
357367 } )
@@ -389,6 +399,7 @@ describe('Notifications Controller', function () {
389399 eTag : '1' ,
390400 } ,
391401 dismissed : [ emergencyContent . notifications [ 0 ] . id , startUpContent . notifications [ 0 ] . id ] ,
402+ newlyReceived : [ ] ,
392403 } )
393404
394405 const emptyContent = {
@@ -411,6 +422,7 @@ describe('Notifications Controller', function () {
411422 eTag : '1' ,
412423 } ,
413424 dismissed : [ emergencyContent . notifications [ 0 ] . id ] ,
425+ newlyReceived : [ ] ,
414426 } )
415427 assert . equal ( panelNode . getChildren ( ) . length , 1 )
416428
@@ -430,6 +442,7 @@ describe('Notifications Controller', function () {
430442 eTag : '1' ,
431443 } ,
432444 dismissed : [ ] ,
445+ newlyReceived : [ ] ,
433446 } )
434447
435448 assert . equal ( panelNode . getChildren ( ) . length , 0 )
@@ -446,6 +459,27 @@ describe('Notifications Controller', function () {
446459 assert . doesNotThrow ( ( ) => new NotificationsController ( panelNode , fetcher ) . pollForStartUp ( ruleEngine ) )
447460 assert . ok ( wasCalled )
448461 } )
462+
463+ it ( 'calls onReceiveNotifications when a new valid notification is added' , async function ( ) {
464+ const eTag = randomUUID ( )
465+ const content = {
466+ schemaVersion : '1.x' ,
467+ notifications : [ getValidTestNotification ( 'id:newValidNotification' ) ] ,
468+ }
469+ fetcher . setStartUpContent ( {
470+ eTag,
471+ content : JSON . stringify ( content ) ,
472+ } )
473+
474+ const onReceiveSpy = sinon . spy ( panelNode , 'onReceiveNotifications' )
475+
476+ await controller . pollForStartUp ( ruleEngine )
477+
478+ assert . equal ( onReceiveSpy . callCount , 1 )
479+ assert . deepStrictEqual ( onReceiveSpy . args [ 0 ] [ 0 ] , [ content . notifications [ 0 ] ] )
480+
481+ onReceiveSpy . restore ( )
482+ } )
449483} )
450484
451485describe ( 'RemoteFetcher' , function ( ) {
0 commit comments