@@ -10,91 +10,102 @@ import * as comms from '../comms';
1010import * as links from '../links' ;
1111import * as native from './native' ;
1212
13+ const raiseNativeNotificationMock = jest . spyOn (
14+ native ,
15+ 'raiseNativeNotification' ,
16+ ) ;
17+ const raiseSoundNotificationMock = jest . spyOn ( native , 'raiseSoundNotification' ) ;
18+
1319describe ( 'renderer/utils/notifications/native.ts' , ( ) => {
1420 afterEach ( ( ) => {
1521 jest . clearAllMocks ( ) ;
1622 } ) ;
1723
1824 describe ( 'triggerNativeNotifications' , ( ) => {
19- it ( 'should raise a native notification (settings - on) ' , ( ) => {
25+ it ( 'should raise a native notification and play sound for a single new notification ' , ( ) => {
2026 const settings : SettingsState = {
2127 ...defaultSettings ,
2228 playSound : true ,
2329 showNotifications : true ,
2430 } ;
2531
26- jest . spyOn ( native , 'raiseNativeNotification' ) ;
27- jest . spyOn ( native , 'raiseSoundNotification' ) ;
28-
29- native . triggerNativeNotifications ( [ ] , mockAccountNotifications , {
32+ native . triggerNativeNotifications ( [ ] , mockSingleAccountNotifications , {
3033 auth : mockAuth ,
3134 settings,
3235 } ) ;
3336
34- expect ( native . raiseNativeNotification ) . toHaveBeenCalledTimes ( 1 ) ;
35- expect ( native . raiseSoundNotification ) . toHaveBeenCalledTimes ( 1 ) ;
37+ expect ( raiseNativeNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ;
38+
39+ expect ( raiseSoundNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ;
40+ expect ( raiseSoundNotificationMock ) . toHaveBeenCalledWith ( 0.2 ) ;
3641 } ) ;
3742
38- it ( 'should not raise a native notification (settings - off) ' , ( ) => {
39- const settings = {
43+ it ( 'should raise a native notification and play sound for multiple new notifications ' , ( ) => {
44+ const settings : SettingsState = {
4045 ...defaultSettings ,
41- playSound : false ,
42- showNotifications : false ,
46+ playSound : true ,
47+ showNotifications : true ,
4348 } ;
4449
45- jest . spyOn ( native , 'raiseNativeNotification' ) ;
46- jest . spyOn ( native , 'raiseSoundNotification' ) ;
47-
4850 native . triggerNativeNotifications ( [ ] , mockAccountNotifications , {
4951 auth : mockAuth ,
5052 settings,
5153 } ) ;
5254
53- expect ( native . raiseNativeNotification ) . not . toHaveBeenCalled ( ) ;
54- expect ( native . raiseSoundNotification ) . not . toHaveBeenCalled ( ) ;
55+ expect ( raiseNativeNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ;
56+
57+ expect ( raiseSoundNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ;
58+ expect ( raiseSoundNotificationMock ) . toHaveBeenCalledWith ( 0.2 ) ;
5559 } ) ;
5660
57- it ( 'should not raise a native notification or play a sound ( no new notifications) ' , ( ) => {
58- const settings = {
61+ it ( 'should not raise a native notification or play a sound when there are no new notifications' , ( ) => {
62+ const settings : SettingsState = {
5963 ...defaultSettings ,
6064 playSound : true ,
6165 showNotifications : true ,
6266 } ;
6367
64- jest . spyOn ( native , 'raiseNativeNotification' ) ;
65- jest . spyOn ( native , 'raiseSoundNotification' ) ;
66-
6768 native . triggerNativeNotifications (
6869 mockSingleAccountNotifications ,
6970 mockSingleAccountNotifications ,
70- { auth : mockAuth , settings } ,
71+ {
72+ auth : mockAuth ,
73+ settings,
74+ } ,
7175 ) ;
7276
73- expect ( native . raiseNativeNotification ) . not . toHaveBeenCalled ( ) ;
74- expect ( native . raiseSoundNotification ) . not . toHaveBeenCalled ( ) ;
77+ expect ( raiseNativeNotificationMock ) . not . toHaveBeenCalled ( ) ;
78+ expect ( raiseSoundNotificationMock ) . not . toHaveBeenCalled ( ) ;
7579 } ) ;
7680
77- it ( 'should not raise a native notification (because of 0( zero) notifications) ' , ( ) => {
78- const settings = {
81+ it ( 'should not raise a native notification or play a sound when there are zero notifications' , ( ) => {
82+ const settings : SettingsState = {
7983 ...defaultSettings ,
8084 playSound : true ,
8185 showNotifications : true ,
8286 } ;
8387
84- jest . spyOn ( native , 'raiseNativeNotification' ) ;
85- jest . spyOn ( native , 'raiseSoundNotification' ) ;
86-
8788 native . triggerNativeNotifications ( [ ] , [ ] , {
8889 auth : mockAuth ,
8990 settings,
9091 } ) ;
91- native . triggerNativeNotifications ( [ ] , [ ] , {
92+
93+ expect ( raiseNativeNotificationMock ) . not . toHaveBeenCalled ( ) ;
94+ expect ( raiseSoundNotificationMock ) . not . toHaveBeenCalled ( ) ;
95+ } ) ;
96+
97+ it ( 'should not raise a native notification when setting disabled' , ( ) => {
98+ const settings : SettingsState = {
99+ ...defaultSettings ,
100+ showNotifications : false ,
101+ } ;
102+
103+ native . triggerNativeNotifications ( [ ] , mockAccountNotifications , {
92104 auth : mockAuth ,
93105 settings,
94106 } ) ;
95107
96- expect ( native . raiseNativeNotification ) . not . toHaveBeenCalled ( ) ;
97- expect ( native . raiseSoundNotification ) . not . toHaveBeenCalled ( ) ;
108+ expect ( raiseNativeNotificationMock ) . not . toHaveBeenCalled ( ) ;
98109 } ) ;
99110 } ) ;
100111
@@ -126,35 +137,4 @@ describe('renderer/utils/notifications/native.ts', () => {
126137 expect ( showWindowMock ) . toHaveBeenCalledTimes ( 1 ) ;
127138 } ) ;
128139 } ) ;
129-
130- describe ( 'raiseSoundNotification' , ( ) => {
131- it ( 'should play a sound' , ( ) => {
132- jest . spyOn ( window . Audio . prototype , 'play' ) ;
133- native . raiseSoundNotification ( ) ;
134- expect ( window . Audio . prototype . play ) . toHaveBeenCalledTimes ( 1 ) ;
135- } ) ;
136-
137- it ( 'should play notification sound with correct volume' , ( ) => {
138- const settings : SettingsState = {
139- ...defaultSettings ,
140- playSound : true ,
141- showNotifications : false ,
142- notificationVolume : 80 ,
143- } ;
144-
145- const raiseSoundNotificationMock = jest . spyOn (
146- native ,
147- 'raiseSoundNotification' ,
148- ) ;
149- jest . spyOn ( native , 'raiseNativeNotification' ) ;
150-
151- native . triggerNativeNotifications ( [ ] , mockAccountNotifications , {
152- auth : mockAuth ,
153- settings,
154- } ) ;
155-
156- expect ( raiseSoundNotificationMock ) . toHaveBeenCalledWith ( 0.8 ) ;
157- expect ( native . raiseNativeNotification ) . not . toHaveBeenCalled ( ) ;
158- } ) ;
159- } ) ;
160140} ) ;
0 commit comments