-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathnotifications_test.rb
434 lines (391 loc) · 17.9 KB
/
notifications_test.rb
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# frozen_string_literal: true
require 'application_system_test_case'
class NotificationsTest < ApplicationSystemTestCase
include ActiveJob::TestHelper
setup do
@delivery_mode = AbstractNotifier.delivery_mode
AbstractNotifier.delivery_mode = :normal
end
teardown do
AbstractNotifier.delivery_mode = @delivery_mode
end
test 'do not send mail if user deny mail' do
visit_with_auth "/reports/#{reports(:report8).id}", 'kimura'
within('.thread-comment-form__form') do
fill_in('new_comment[description]', with: 'test')
end
click_button 'コメントする'
if ActionMailer::Base.deliveries.present?
last_mail = ActionMailer::Base.deliveries.last
assert_not_equal '[FBC] kimuraさんからコメントが届きました。', last_mail.subject
end
end
test "don't notify the same report" do
visit_with_auth '/notifications', 'komagata'
click_link '全て既読にする'
visit_with_auth '/reports/new', 'kensyu'
fill_in 'report_title', with: 'テスト日報'
fill_in 'report_description', with: 'none'
select '23', from: :report_learning_times_attributes_0_started_at_4i
select '00', from: :report_learning_times_attributes_0_started_at_5i
select '00', from: :report_learning_times_attributes_0_finished_at_4i
select '00', from: :report_learning_times_attributes_0_finished_at_5i
click_button '提出'
perform_enqueued_jobs do
find('#js-new-comment').set("login_nameの補完テスト: @komagata\n")
click_button 'コメントする'
assert_text 'login_nameの補完テスト: @komagata'
assert_selector :css, "a[href='/users/komagata']"
end
visit_with_auth '/notifications', 'komagata'
assert_no_text 'kensyuさんがはじめての日報を書きました!'
assert_text 'kensyuさんからメンションがきました。'
end
test 'do not show read notification on the unread notifications' do
Notification.create(message: '1番新しい既読の通知',
read: true,
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:mentormentaro),
sender: users(:machida))
visit_with_auth '/notifications?status=unread', 'mentormentaro'
assert_no_text '1番新しい既読の通知'
end
test 'click on the pager button' do
# 1ページに表示する通知の数は20件なのでtimesメソッドを使って19件作成し、一番新しい通知、古い通知を個別に作成する
19.times do |n|
Notification.create(message: "machidaさんからメンションが届きました#{n}",
kind: 'mentioned',
link: "/reports/#{n}",
user: users(:mentormentaro),
sender: users(:machida))
end
Notification.create(message: '1番新しい通知',
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:mentormentaro),
sender: users(:machida))
Notification.create(message: '1番古い通知',
created_at: '2000-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20000118',
user: users(:mentormentaro),
sender: users(:machida))
login_user 'mentormentaro', 'testtest'
visit '/notifications'
within first('nav.pagination') do
find('button', text: '2').click
end
# 2ページ目に1番古い通知が表示されることを確認
assert_text '1番古い通知'
# 2ページ目に1番新しい通知が表示されないことを確認
assert_no_text '1番新しい通知'
all('.pagination .is-active').each do |active_button|
assert active_button.has_text? '2'
end
assert_current_path('/notifications?page=2')
end
test 'show 20 notifications in first page' do
25.times do |n|
Notification.create(message: "machidaさんからメンションが届きました#{n}",
kind: 'mentioned',
link: "/reports/#{n}",
user: users(:mentormentaro),
sender: users(:machida))
end
Notification.create(message: '1番新しい通知',
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:mentormentaro),
sender: users(:machida))
login_user 'mentormentaro', 'testtest'
visit '/notifications'
assert_text '1番新しい通知'
assert_equal 20, all('.card-list-item').size
visit '/notifications?status=unread'
assert_text '1番新しい通知'
assert_equal 20, all('.card-list-item').size
end
test 'click on the pager button with query string' do
19.times do |n|
Notification.create(message: "machidaさんからメンションが届きました#{n}",
kind: 'mentioned',
link: "/reports/#{n}",
user: users(:mentormentaro),
sender: users(:machida))
end
Notification.create(message: '1番新しい通知',
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:mentormentaro),
sender: users(:machida))
Notification.create(message: '1番古い通知',
created_at: '2000-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20000118',
user: users(:mentormentaro),
sender: users(:machida))
login_user 'mentormentaro', 'testtest'
visit '/notifications?status=unread'
within first('nav.pagination') do
find('button', text: '2').click
end
assert_text '1番古い通知'
assert_no_text '1番新しい通知'
all('.pagination .is-active').each do |active_button|
assert active_button.has_text? '2'
end
assert_current_path('/notifications?status=unread&page=2')
end
test 'click on the pager button with multiple query string' do
19.times do |n|
Notification.create(message: "machidaさんからメンションが届きました#{n}",
kind: 'mentioned',
link: "/reports/#{n}",
user: users(:mentormentaro),
sender: users(:machida))
end
Notification.create(message: '1番新しい通知',
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:mentormentaro),
sender: users(:machida))
Notification.create(message: '1番古い通知',
created_at: '2000-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20000118',
user: users(:mentormentaro),
sender: users(:machida))
login_user 'mentormentaro', 'testtest'
visit '/notifications?status=unread&target=mention'
within first('nav.pagination') do
find('button', text: '2').click
end
assert_text '1番古い通知'
assert_no_text '1番新しい通知'
all('.pagination .is-active').each do |active_button|
assert active_button.has_text? '2'
end
assert_current_path('/notifications?status=unread&target=mention&page=2')
end
test 'specify the page number in the URL' do
19.times do |n|
Notification.create(message: "machidaさんからメンションが届きました#{n}",
kind: 'mentioned',
link: "/reports/#{n}",
user: users(:mentormentaro),
sender: users(:machida))
end
Notification.create(message: '1番新しい通知',
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:mentormentaro),
sender: users(:machida))
Notification.create(message: '1番古い通知',
created_at: '2000-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20000118',
user: users(:mentormentaro),
sender: users(:machida))
login_user 'mentormentaro', 'testtest'
visit '/notifications?page=2'
assert_text '1番古い通知'
assert_no_text '1番新しい通知'
all('.pagination .is-active').each do |active_button|
assert active_button.has_text? '2'
end
end
test 'clicking the browser back button will show the previous page' do
19.times do |n|
Notification.create(message: "machidaさんからメンションが届きました#{n}",
kind: 'mentioned',
link: "/reports/#{n}",
user: users(:mentormentaro),
sender: users(:machida))
end
Notification.create(message: '1番新しい通知',
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:mentormentaro),
sender: users(:machida))
Notification.create(message: '1番古い通知',
created_at: '2000-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20000118',
user: users(:mentormentaro),
sender: users(:machida))
login_user 'mentormentaro', 'testtest'
visit '/notifications?page=2'
within first('nav.pagination') do
find('button', text: '1').click
end
assert_text '1番新しい通知'
page.go_back
assert_text '1番古い通知'
assert_no_text '1番新しい通知'
all('.pagination .is-active').each do |active_button|
assert active_button.has_text? '2'
end
end
test 'notify comment and check' do
login_user 'hatsuno', 'testtest'
report = create_report 'コメントと', '確認があった', false
perform_enqueued_jobs do
visit_with_auth "/reports/#{report}", 'komagata'
visit "/reports/#{report}"
fill_in 'new_comment[description]', with: 'コメントと確認した'
click_button '確認OKにする'
assert_text 'コメントと確認した'
visit_with_auth "/reports/#{report}", 'hatsuno'
assert_text 'コメントと確認した'
find('.header-links__link.test-show-notifications').click
assert_text 'hatsunoさんの日報「コメントと」にkomagataさんがコメントしました。'
end
end
test 'notify user class name role contains' do
visit_with_auth '/', 'komagata'
assert_text '6日以上経過'
find('.header-links__link.test-show-notifications').click
assert_selector 'span.a-user-role.is-admin'
assert_selector 'span.a-user-role.is-student'
assert_selector 'span.a-user-role.is-mentor'
end
test 'show notification count' do
Notification.create(message: 'machidaさんからメンションが届きました',
created_at: '2040-01-18 06:06:42',
kind: 'mentioned',
link: '/reports/20400118',
user: users(:kananashi),
sender: users(:machida))
visit_with_auth '/notifications', 'kananashi'
assert_selector '.header-notification-count', text: '1'
20.times do |n|
Notification.create(message: "machidaさんからメンションが届きました#{n}",
kind: 'mentioned',
link: "/reports/#{n}",
user: users(:kananashi),
sender: users(:machida))
end
visit_with_auth '/notifications', 'kananashi'
assert_selector '.header-notification-count', text: '21'
end
test 'show listing unread notification' do
visit_with_auth '/notifications?status=unread', 'hatsuno'
assert_equal '通知 | FBC', title
end
test 'non-mentor can not see a button to open all unread notifications' do
Notification.create(message: 'machidaさんがコメントしました',
kind: 'came_comment',
link: '/reports/20400118',
user: users(:hatsuno),
sender: users(:machida))
visit_with_auth '/notifications?status=unread', 'hatsuno'
assert_no_button '未読の通知を一括で開く'
end
test 'mentor can see a button to open to open all unread notifications' do
Notification.create(message: 'machidaさんがコメントしました',
kind: 'came_comment',
link: '/reports/20400118',
user: users(:komagata),
sender: users(:machida))
visit_with_auth '/notifications?status=unread', 'komagata'
assert_button '未読の通知を一括で開く'
end
test 'show listing notification that target is all' do
Notification.create(message: 'お知らせの通知',
kind: 'announced',
link: '/announcements/1',
user: users(:komagata),
sender: users(:machida))
Notification.create(message: 'コメントの通知',
kind: 'came_comment',
link: '/reports/1',
user: users(:komagata),
sender: users(:machida))
visit_with_auth '/notifications', 'komagata'
assert_text 'コメントの通知'
assert_text 'お知らせの通知'
end
test 'show listing notification that target is announcements' do
Notification.create(message: 'お知らせの通知',
kind: 'announced',
link: '/announcements/1',
user: users(:komagata),
sender: users(:machida))
Notification.create(message: 'コメントの通知',
kind: 'came_comment',
link: '/reports/1',
user: users(:komagata),
sender: users(:machida))
visit_with_auth '/notifications?target=announcement', 'komagata'
assert_text 'お知らせの通知'
assert_no_text 'コメントの通知'
end
test 'show listing unread notification that target is announcements' do
Notification.create(message: '未読のお知らせの通知',
kind: 'announced',
link: '/announcements/1',
user: users(:komagata),
sender: users(:machida))
Notification.create(message: '既読のお知らせの通知',
kind: 'announced',
link: '/announcements/2',
user: users(:komagata),
sender: users(:machida),
read: true)
visit_with_auth '/notifications?status=unread&target=announcement', 'komagata'
assert_text '未読のお知らせの通知'
assert_no_text '既読のお知らせの通知'
end
test 'click on the category marks button' do
Notification.create(message: 'お知らせのテスト通知',
kind: 'announced',
link: '/announcements/1',
user: users(:komagata),
sender: users(:machida))
Notification.create(message: 'コメントのテスト通知',
kind: 'came_comment',
link: '/reports/1',
user: users(:komagata),
sender: users(:machida))
visit_with_auth '/notifications?status=unread&target=announcement', 'komagata'
click_link 'お知らせを既読にする'
visit_with_auth '/notifications?status=unread&target=announcement', 'komagata'
assert_no_text 'お知らせのテスト通知'
visit_with_auth '/notifications?status=unread&target=comment', 'komagata'
assert_text 'コメントのテスト通知'
visit_with_auth '/notifications?status=unread', 'komagata'
assert_text 'コメントのテスト通知'
end
test 'show the number of unread mentions on the badge of the mentioned tab' do
user = users(:kimura)
expected_number_of_unread_mentions = user.notifications.by_target(:mention).unreads.latest_of_each_link.size
visit_with_auth '/notifications', user.login_name
within '.page-tabs__item', text: 'メンション' do
actual_number_of_unread_mentions = find('.a-notification-count').text.to_i
assert_equal expected_number_of_unread_mentions, actual_number_of_unread_mentions
end
end
test 'don\'t show the badge on the mentioned tab if no unread mentions' do
user = users(:kimura)
user.notifications.by_target(:mention).where(read: false).update_all(read: true) # rubocop:disable Rails/SkipsModelValidations
visit_with_auth '/notifications', user.login_name
within '.page-tabs__item', text: 'メンション' do
assert_no_selector '.a-notification-count'
end
end
test 'Unread and All buttons should always be displayed' do
user = users(:kimura)
visit_with_auth '/notifications', user.login_name
assert_selector '.pill-nav__item-link.is-active'
visit '/notifications?status=unread&target=check'
assert_selector '.pill-nav__item-link.is-active'
end
end