@@ -2,14 +2,14 @@ import * as actions from '../actions';
22import * as comms from '../utils/comms' ;
33import {
44 mockedGithubNotifications ,
5- mockedNotificationsRecuderData ,
5+ mockedNotificationsReducerData ,
66} from '../__mocks__/mockedData' ;
77import notificationsMiddleware from './notifications' ;
88import NativeNotifications from '../utils/notifications' ;
99
1010// Keep 3 notifications
1111// Ps. To receive 4 on actions.NOTIFICATIONS.SUCCESS,
12- const mockedNotifications = mockedNotificationsRecuderData . map (
12+ const mockedNotifications = mockedNotificationsReducerData . map (
1313 ( account , accountIndex ) => {
1414 if ( accountIndex === 0 ) {
1515 return {
@@ -22,25 +22,27 @@ const mockedNotifications = mockedNotificationsRecuderData.map(
2222 }
2323) ;
2424
25- const createFakeStore = ( ) => ( {
25+ const DEFAULT_STORE = {
26+ notifications : {
27+ response : mockedNotifications ,
28+ } ,
29+ settings : {
30+ playSound : false ,
31+ showNotifications : false ,
32+ } ,
33+ } ;
34+
35+ const createFakeStore = ( storeData ) => ( {
2636 getState ( ) {
27- return {
28- notifications : {
29- response : mockedNotifications ,
30- } ,
31- settings : {
32- playSound : false ,
33- showNotifications : false ,
34- } ,
35- } ;
37+ return storeData ;
3638 } ,
3739} ) ;
3840
39- const dispatchWithStoreOf = ( _ , action ) => {
41+ const dispatchWithStoreOf = ( storeData , action ) => {
4042 let dispatched = null ;
41- const dispatch = notificationsMiddleware ( createFakeStore ( ) ) (
42- ( actionAttempt ) => ( dispatched = actionAttempt )
43- ) ;
43+ const dispatch = notificationsMiddleware (
44+ createFakeStore ( { ... DEFAULT_STORE , ... storeData } )
45+ ) ( ( actionAttempt ) => ( dispatched = actionAttempt ) ) ;
4446 dispatch ( action ) ;
4547 return dispatched ;
4648} ;
@@ -54,7 +56,7 @@ describe('middleware/notifications.js', () => {
5456 it ( 'should raise notifications (native & sound, update tray icon, set badge)' , ( ) => {
5557 const action = {
5658 type : actions . NOTIFICATIONS . SUCCESS ,
57- payload : mockedNotificationsRecuderData ,
59+ payload : mockedNotificationsReducerData ,
5860 } ;
5961
6062 expect ( dispatchWithStoreOf ( { } , action ) ) . toEqual ( action ) ;
@@ -93,4 +95,44 @@ describe('middleware/notifications.js', () => {
9395 expect ( comms . updateTrayIcon ) . toHaveBeenCalledTimes ( 1 ) ;
9496 expect ( comms . updateTrayIcon ) . toHaveBeenCalledWith ( 2 ) ;
9597 } ) ;
98+
99+ it ( 'should update tray icon with no notifications' , ( ) => {
100+ const noNewNotifications = mockedNotificationsReducerData . map ( ( host ) => ( {
101+ ...host ,
102+ notifications : [ ] ,
103+ } ) ) ;
104+ const action = {
105+ type : actions . NOTIFICATIONS . SUCCESS ,
106+ payload : noNewNotifications ,
107+ } ;
108+ dispatchWithStoreOf (
109+ {
110+ ...DEFAULT_STORE ,
111+ notifications : {
112+ response : noNewNotifications ,
113+ } ,
114+ } ,
115+ action
116+ ) ;
117+ expect ( comms . updateTrayIcon ) . toHaveBeenCalledTimes ( 1 ) ;
118+ expect ( comms . updateTrayIcon ) . toHaveBeenCalledWith ( 0 ) ;
119+ } ) ;
120+
121+ it ( 'should show 0 notifications if no accounts logged in' , ( ) => {
122+ const action = {
123+ type : actions . NOTIFICATIONS . SUCCESS ,
124+ payload : mockedNotificationsReducerData ,
125+ } ;
126+ dispatchWithStoreOf (
127+ {
128+ ...DEFAULT_STORE ,
129+ notifications : {
130+ response : [ ] ,
131+ } ,
132+ } ,
133+ action
134+ ) ;
135+ expect ( comms . updateTrayIcon ) . toHaveBeenCalledTimes ( 1 ) ;
136+ expect ( comms . updateTrayIcon ) . toHaveBeenCalledWith ( 4 ) ;
137+ } ) ;
96138} ) ;
0 commit comments