@@ -10,91 +10,102 @@ import * as comms from '../comms';
10
10
import * as links from '../links' ;
11
11
import * as native from './native' ;
12
12
13
+ const raiseNativeNotificationMock = jest . spyOn (
14
+ native ,
15
+ 'raiseNativeNotification' ,
16
+ ) ;
17
+ const raiseSoundNotificationMock = jest . spyOn ( native , 'raiseSoundNotification' ) ;
18
+
13
19
describe ( 'renderer/utils/notifications/native.ts' , ( ) => {
14
20
afterEach ( ( ) => {
15
21
jest . clearAllMocks ( ) ;
16
22
} ) ;
17
23
18
24
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 ' , ( ) => {
20
26
const settings : SettingsState = {
21
27
...defaultSettings ,
22
28
playSound : true ,
23
29
showNotifications : true ,
24
30
} ;
25
31
26
- jest . spyOn ( native , 'raiseNativeNotification' ) ;
27
- jest . spyOn ( native , 'raiseSoundNotification' ) ;
28
-
29
- native . triggerNativeNotifications ( [ ] , mockAccountNotifications , {
32
+ native . triggerNativeNotifications ( [ ] , mockSingleAccountNotifications , {
30
33
auth : mockAuth ,
31
34
settings,
32
35
} ) ;
33
36
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 ) ;
36
41
} ) ;
37
42
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 = {
40
45
...defaultSettings ,
41
- playSound : false ,
42
- showNotifications : false ,
46
+ playSound : true ,
47
+ showNotifications : true ,
43
48
} ;
44
49
45
- jest . spyOn ( native , 'raiseNativeNotification' ) ;
46
- jest . spyOn ( native , 'raiseSoundNotification' ) ;
47
-
48
50
native . triggerNativeNotifications ( [ ] , mockAccountNotifications , {
49
51
auth : mockAuth ,
50
52
settings,
51
53
} ) ;
52
54
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 ) ;
55
59
} ) ;
56
60
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 = {
59
63
...defaultSettings ,
60
64
playSound : true ,
61
65
showNotifications : true ,
62
66
} ;
63
67
64
- jest . spyOn ( native , 'raiseNativeNotification' ) ;
65
- jest . spyOn ( native , 'raiseSoundNotification' ) ;
66
-
67
68
native . triggerNativeNotifications (
68
69
mockSingleAccountNotifications ,
69
70
mockSingleAccountNotifications ,
70
- { auth : mockAuth , settings } ,
71
+ {
72
+ auth : mockAuth ,
73
+ settings,
74
+ } ,
71
75
) ;
72
76
73
- expect ( native . raiseNativeNotification ) . not . toHaveBeenCalled ( ) ;
74
- expect ( native . raiseSoundNotification ) . not . toHaveBeenCalled ( ) ;
77
+ expect ( raiseNativeNotificationMock ) . not . toHaveBeenCalled ( ) ;
78
+ expect ( raiseSoundNotificationMock ) . not . toHaveBeenCalled ( ) ;
75
79
} ) ;
76
80
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 = {
79
83
...defaultSettings ,
80
84
playSound : true ,
81
85
showNotifications : true ,
82
86
} ;
83
87
84
- jest . spyOn ( native , 'raiseNativeNotification' ) ;
85
- jest . spyOn ( native , 'raiseSoundNotification' ) ;
86
-
87
88
native . triggerNativeNotifications ( [ ] , [ ] , {
88
89
auth : mockAuth ,
89
90
settings,
90
91
} ) ;
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 , {
92
104
auth : mockAuth ,
93
105
settings,
94
106
} ) ;
95
107
96
- expect ( native . raiseNativeNotification ) . not . toHaveBeenCalled ( ) ;
97
- expect ( native . raiseSoundNotification ) . not . toHaveBeenCalled ( ) ;
108
+ expect ( raiseNativeNotificationMock ) . not . toHaveBeenCalled ( ) ;
98
109
} ) ;
99
110
} ) ;
100
111
@@ -126,35 +137,4 @@ describe('renderer/utils/notifications/native.ts', () => {
126
137
expect ( showWindowMock ) . toHaveBeenCalledTimes ( 1 ) ;
127
138
} ) ;
128
139
} ) ;
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
- } ) ;
160
140
} ) ;
0 commit comments