@@ -114,12 +114,6 @@ describe('lib/core/notification_center', function() {
114114 } ) ;
115115 } ) ;
116116
117- context ( 'an error is caught' , function ( ) {
118- it ( 'should return -1 if an error is caught' )
119- it ( 'should thrown an error if an error is caught' ) ;
120- it ( 'should log an error message if an error is caught' ) ;
121- } ) ;
122-
123117 context ( 'add notification listener for type ACTIVATE' , function ( ) {
124118 var listenerId2 ;
125119 it ( 'should return -1 if that same ACTIVATE callback is already added' , function ( ) {
@@ -264,7 +258,25 @@ describe('lib/core/notification_center', function() {
264258 listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
265259 assert . strictEqual ( listenerRemoved , true ) ;
266260 } ) ;
267- it ( 'should not remove any other listeners except for the one belonging to the listenerId' ) ;
261+ it ( 'should not remove any other listeners except for the one belonging to the listenerId' , function ( ) {
262+ // register first ACTIVATE notification listener (to be removed)
263+ listenerId = notificationCenterInstance . addNotificationListener (
264+ enums . NOTIFICATION_TYPES . ACTIVATE ,
265+ activateCallbackSpy1
266+ ) ;
267+ // register second ACTIVATE notification listener (not to be removed)
268+ notificationCenterInstance . addNotificationListener (
269+ enums . NOTIFICATION_TYPES . ACTIVATE ,
270+ activateCallbackSpy2
271+ ) ;
272+ // remove first ACTIVATE listener
273+ listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
274+ notificationCenterInstance . sendNotifications ( enums . NOTIFICATION_TYPES . ACTIVATE , { } ) ;
275+ // check assertions that first listener is removed, callback1 not called, but second callback2 is called.
276+ assert . strictEqual ( listenerRemoved , true ) ;
277+ sinon . assert . notCalled ( activateCallbackSpy1 ) ;
278+ sinon . assert . calledOnce ( activateCallbackSpy2 ) ;
279+ } ) ;
268280 } ) ;
269281 context ( 'remove notification listener for type DECISION' , function ( ) {
270282 it ( 'should return true when valid listenerId of DECISION type has been supplied and the listener is removed' , function ( ) {
@@ -275,6 +287,25 @@ describe('lib/core/notification_center', function() {
275287 listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
276288 assert . strictEqual ( listenerRemoved , true ) ;
277289 } ) ;
290+ it ( 'should not remove any other listeners except for the one belonging to the listenerId' , function ( ) {
291+ // register first DECISION notification listener (to be removed)
292+ listenerId = notificationCenterInstance . addNotificationListener (
293+ enums . NOTIFICATION_TYPES . DECISION ,
294+ decisionCallbackSpy1
295+ ) ;
296+ // register second DECISION notification listener (not to be removed)
297+ notificationCenterInstance . addNotificationListener (
298+ enums . NOTIFICATION_TYPES . DECISION ,
299+ decisionCallbackSpy2
300+ ) ;
301+ // remove first DECISION listener
302+ listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
303+ notificationCenterInstance . sendNotifications ( enums . NOTIFICATION_TYPES . DECISION , { } ) ;
304+ // check assertions that first listener is removed, callback1 not called, but second callback2 is called.
305+ assert . strictEqual ( listenerRemoved , true ) ;
306+ sinon . assert . notCalled ( decisionCallbackSpy1 ) ;
307+ sinon . assert . calledOnce ( decisionCallbackSpy2 ) ;
308+ } ) ;
278309 } ) ;
279310 context ( 'remove notification listener for type LOG_EVENT' , function ( ) {
280311 it ( 'should return true when valid listenerId of LOG_EVENT type has been supplied and the listener is removed' , function ( ) {
@@ -285,6 +316,25 @@ describe('lib/core/notification_center', function() {
285316 listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
286317 assert . strictEqual ( listenerRemoved , true ) ;
287318 } ) ;
319+ it ( 'should not remove any other listeners except for the one belonging to the listenerId' , function ( ) {
320+ // register first LOG_EVENT notification listener (to be removed)
321+ listenerId = notificationCenterInstance . addNotificationListener (
322+ enums . NOTIFICATION_TYPES . LOG_EVENT ,
323+ logEventCallbackSpy1
324+ ) ;
325+ // register second LOG_EVENT notification listener (not to be removed)
326+ notificationCenterInstance . addNotificationListener (
327+ enums . NOTIFICATION_TYPES . LOG_EVENT ,
328+ logEventCallbackSpy2
329+ ) ;
330+ // remove first LOG_EVENT listener
331+ listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
332+ notificationCenterInstance . sendNotifications ( enums . NOTIFICATION_TYPES . LOG_EVENT , { } ) ;
333+ // check assertions that first listener is removed, callback1 not called, but second callback2 is called.
334+ assert . strictEqual ( listenerRemoved , true ) ;
335+ sinon . assert . notCalled ( logEventCallbackSpy1 ) ;
336+ sinon . assert . calledOnce ( logEventCallbackSpy2 ) ;
337+ } ) ;
288338 } ) ;
289339 context ( 'remove notification listener for type OPTIMIZELY_CONFIG_UPDATE' , function ( ) {
290340 it ( 'should return true when valid listenerId of OPTIMIZELY_CONFIG_UPDATE type has been supplied and the listener is removed' , function ( ) {
@@ -295,6 +345,25 @@ describe('lib/core/notification_center', function() {
295345 listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
296346 assert . strictEqual ( listenerRemoved , true ) ;
297347 } ) ;
348+ it ( 'should not remove any other listeners except for the one belonging to the listenerId' , function ( ) {
349+ // register first OPTIMIZELY_CONFIG_UPDATE notification listener (to be removed)
350+ listenerId = notificationCenterInstance . addNotificationListener (
351+ enums . NOTIFICATION_TYPES . OPTIMIZELY_CONFIG_UPDATE ,
352+ configUpdateCallbackSpy1
353+ ) ;
354+ // register second OPTIMIZELY_CONFIG_UPDATE notification listener (not to be removed)
355+ notificationCenterInstance . addNotificationListener (
356+ enums . NOTIFICATION_TYPES . OPTIMIZELY_CONFIG_UPDATE ,
357+ configUpdateCallbackSpy2
358+ ) ;
359+ // remove first OPTIMIZELY_CONFIG_UPDATE listener
360+ listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
361+ notificationCenterInstance . sendNotifications ( enums . NOTIFICATION_TYPES . OPTIMIZELY_CONFIG_UPDATE , { } ) ;
362+ // check assertions that first listener is removed, callback1 not called, but second callback2 is called.
363+ assert . strictEqual ( listenerRemoved , true ) ;
364+ sinon . assert . notCalled ( configUpdateCallbackSpy1 ) ;
365+ sinon . assert . calledOnce ( configUpdateCallbackSpy2 ) ;
366+ } ) ;
298367 } ) ;
299368 context ( 'remove notification listener for type TRACK' , function ( ) {
300369 it ( 'should return true when valid listenerId of TRACK type has been supplied and the listener is removed' , function ( ) {
@@ -305,6 +374,25 @@ describe('lib/core/notification_center', function() {
305374 listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
306375 assert . strictEqual ( listenerRemoved , true ) ;
307376 } ) ;
377+ it ( 'should not remove any other listeners except for the one belonging to the listenerId' , function ( ) {
378+ // register first TRACK notification listener (to be removed)
379+ listenerId = notificationCenterInstance . addNotificationListener (
380+ enums . NOTIFICATION_TYPES . TRACK ,
381+ trackCallbackSpy1
382+ ) ;
383+ // register second TRACK notification listener (not to be removed)
384+ notificationCenterInstance . addNotificationListener (
385+ enums . NOTIFICATION_TYPES . TRACK ,
386+ trackCallbackSpy2
387+ ) ;
388+ // remove first TRACK listener
389+ listenerRemoved = notificationCenterInstance . removeNotificationListener ( listenerId ) ;
390+ notificationCenterInstance . sendNotifications ( enums . NOTIFICATION_TYPES . TRACK , { } ) ;
391+ // check assertions that first listener is removed, callback1 not called, but second callback2 is called.
392+ assert . strictEqual ( listenerRemoved , true ) ;
393+ sinon . assert . notCalled ( trackCallbackSpy1 ) ;
394+ sinon . assert . calledOnce ( trackCallbackSpy2 ) ;
395+ } ) ;
308396 } ) ;
309397
310398 } ) ;
@@ -377,7 +465,7 @@ describe('lib/core/notification_center', function() {
377465 activateCallbackSpy2
378466 ) ;
379467 // remove ACTIVATE listeners
380- notificationCenterInstance . clearAllNotificationListeners ( enums . NOTIFICATION_TYPES . ACTIVATE ) ;
468+ notificationCenterInstance . clearNotificationListeners ( enums . NOTIFICATION_TYPES . ACTIVATE ) ;
381469 // trigger send notifications
382470 notificationCenterInstance . sendNotifications (
383471 enums . NOTIFICATION_TYPES . ACTIVATE ,
0 commit comments