-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnotifier-spec.coffee
241 lines (164 loc) · 7.77 KB
/
notifier-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
AtoumNotifier = require '../lib/notifier'
describe 'AtoumNotifier', ->
notifications = null
notification = null
notifier = null
beforeEach ->
notification =
dismiss: ->
onDidDismiss: ->
notifications =
addSuccess: ->
addWarning: ->
addError: ->
spyOn(notification, 'dismiss').andCallFake ->
spyOn(notification, 'onDidDismiss').andCallFake ->
returnNotification = -> notification
spyOn(notifications, 'addSuccess').andCallFake returnNotification
spyOn(notifications, 'addWarning').andCallFake returnNotification
spyOn(notifications, 'addError').andCallFake returnNotification
beforeEach ->
notifier = new AtoumNotifier notifications
it 'should initialize with empty scores', ->
expect(notifier.count).toBe 0
expect(notifier.failure).toBe 0
expect(notifier.skip).toBe 0
expect(notifier.voidNumber).toBe 0
it 'should be enabled', ->
expect(notifier.enabled).toBe true
describe 'When disabled', ->
beforeEach ->
notifier.disable()
afterEach ->
expect(notifications.addSuccess).not.toHaveBeenCalled()
expect(notifications.addWarning).not.toHaveBeenCalled()
expect(notifications.addError).not.toHaveBeenCalled()
it 'should not send notification for success', ->
notifier.testDidFinish status: 'ok'
notifier.runnerDidStop 0
it 'should not send notification for failure', ->
notifier.testDidFinish status: 'not ok'
notifier.runnerDidStop 1
it 'should not send notification for void', ->
notifier.testDidFinish status: 'void'
notifier.runnerDidStop 0
it 'should not send notification for skip', ->
notifier.testDidFinish status: 'skip'
notifier.runnerDidStop 0
it 'should not send notification for errors', ->
notifier.testDidFinish status: 'success'
notifier.runnerDidStop 255
describe 'When enabled', ->
beforeEach ->
notifier.enable()
it 'should send notification for success', ->
notifier.testDidFinish status: 'ok'
notifier.runnerDidStop 0
expect(notifications.addSuccess).toHaveBeenCalled()
it 'should send notification for failure', ->
notifier.testDidFinish status: 'not ok'
notifier.runnerDidStop 1
expect(notifications.addError).toHaveBeenCalled()
it 'should send notification for void', ->
notifier.testDidFinish status: 'void'
notifier.runnerDidStop 0
expect(notifications.addWarning).toHaveBeenCalled()
it 'should send notification for skip', ->
notifier.testDidFinish status: 'skip'
notifier.runnerDidStop 0
expect(notifications.addWarning).toHaveBeenCalled()
it 'should send notification for errors', ->
notifier.testDidFinish status: 'success'
notifier.runnerDidStop 255
expect(notifications.addError).toHaveBeenCalled()
it 'should dismiss outdated notification', ->
notifier.testDidFinish status: 'ok'
notifier.runnerDidStop 0
expect(notifications.addSuccess).toHaveBeenCalled()
notifier.reset()
expect(notification.dismiss).toHaveBeenCalled()
it 'should dismiss outdated notification even if it gets disabled', ->
notifier.testDidFinish status: 'ok'
notifier.runnerDidStop 0
expect(notifications.addSuccess).toHaveBeenCalled()
notifier.disable()
notifier.reset()
expect(notification.dismiss).toHaveBeenCalled()
describe 'Success notification', ->
beforeEach ->
notifier.testDidFinish status: 'ok'
afterEach ->
notifier.runnerDidStop 0
expect(notifications.addSuccess).toHaveBeenCalled()
it 'should be dismissable', ->
notifications.addSuccess.andCallFake (title, options) ->
expect(options.dismissable).toBe true
notification
it 'should have a check icon', ->
notifications.addSuccess.andCallFake (title, options) ->
expect(options.icon).toBe 'check'
notification
it 'should display a message with the number of tests', ->
notifications.addSuccess.andCallFake (title, options) ->
expect(options.detail).toBe '1 test passed!'
notification
describe 'Failure notification', ->
beforeEach ->
notifier.testDidFinish status: 'ok'
notifier.testDidFinish status: 'not ok'
afterEach ->
notifier.runnerDidStop 1
expect(notifications.addError).toHaveBeenCalled()
it 'should be dismissable', ->
notifications.addError.andCallFake (title, options) ->
expect(options.dismissable).toBe true
notification
it 'should have a flame icon', ->
notifications.addError.andCallFake (title, options) ->
expect(options.icon).toBe 'flame'
notification
it 'should display a message with the number of tests', ->
notifications.addError.andCallFake (title, options) ->
expect(options.detail).toBe '1 of 2 tests failed!'
notification
describe 'Void and skip notification', ->
beforeEach ->
notifier.testDidFinish status: 'ok'
notifier.testDidFinish status: 'void'
notifier.testDidFinish status: 'skip'
afterEach ->
notifier.runnerDidStop 0
expect(notifications.addWarning).toHaveBeenCalled()
it 'should be dismissable', ->
notifications.addWarning.andCallFake (title, options) ->
expect(options.dismissable).toBe true
notification
it 'should have a dot icon', ->
notifications.addWarning.andCallFake (title, options) ->
expect(options.icon).toBe 'primitive-dot'
notification
it 'should display a message with the number of tests', ->
notifications.addWarning.andCallFake (title, options) ->
expect(options.detail).toBe '1 test passed, 1 test was void and 1 test was skipped.'
notification
describe 'Error notification', ->
beforeEach ->
notifier.testDidFinish status: 'ok'
notifier.testDidFinish status: 'not ok'
notifier.testDidFinish status: 'void'
notifier.testDidFinish status: 'skip'
afterEach ->
notifier.runnerDidStop 255
expect(notifications.addError).toHaveBeenCalled()
it 'should be dismissable', ->
notifications.addError.andCallFake (title, options) ->
expect(options.dismissable).toBe true
notification
it 'should have a flame icon', ->
notifications.addError.andCallFake (title, options) ->
expect(options.icon).toBe 'flame'
notification
it 'should display a message with the number of tests', ->
notifications.addError.andCallFake (title, options) ->
expect(options.detail).toBe 'There was an error while running your tests!'
notification