]> git.openstreetmap.org Git - rails.git/blob - test/controllers/notifications/note_comment_view_test.rb
Merge remote-tracking branch 'upstream/pull/7289'
[rails.git] / test / controllers / notifications / note_comment_view_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Notifications
6   class NoteCommentViewTest < ActionView::TestCase
7     def test_render_commented
8       note_comment = build_stubbed(
9         :note_comment,
10         :author => build_stubbed(:user),
11         :event => "commented"
12       )
13       notification = build_stubbed(:notification, :record => note_comment)
14
15       render(
16         "notifications/notification",
17         :notification => notification
18       )
19
20       assert_dom ".web-notification" do
21         assert_dom "h2", "Note comment"
22         assert_dom "time", "less than 1 minute ago"
23         assert_dom "blockquote", note_comment.body
24       end
25     end
26
27     def test_render_closed_with_comment
28       comment_author = build_stubbed(
29         :user,
30         :display_name => "Helpful Commenter"
31       )
32       note = build_stubbed(:note)
33       note_comment = build_stubbed(
34         :note_comment,
35         :author => comment_author,
36         :note => note,
37         :event => "closed"
38       )
39       notification = build_stubbed(:notification, :record => note_comment)
40
41       render(
42         "notifications/notification",
43         :notification => notification
44       )
45
46       assert_dom ".web-notification" do
47         assert_dom "h2", "Note resolved"
48         assert_dom "time", "less than 1 minute ago"
49         assert_dom "blockquote", note_comment.body
50       end
51     end
52
53     def test_render_closed_without_comment
54       comment_author = build_stubbed(
55         :user,
56         :display_name => "Helpful Commenter"
57       )
58       note = build_stubbed(:note)
59       note_comment = build_stubbed(
60         :note_comment,
61         :author => comment_author,
62         :note => note,
63         :event => "closed",
64         :body => ""
65       )
66       notification = build_stubbed(:notification, :record => note_comment)
67
68       render(
69         "notifications/notification",
70         :notification => notification
71       )
72
73       assert_dom ".web-notification" do
74         assert_dom "h2", "Note resolved"
75         assert_dom "time", "less than 1 minute ago"
76         assert_not_dom "blockquote"
77       end
78     end
79
80     def test_render_reopened
81       comment_author = build_stubbed(
82         :user,
83         :display_name => "Helpful Commenter"
84       )
85       note = build_stubbed(:note)
86       note_comment = build_stubbed(
87         :note_comment,
88         :author => comment_author,
89         :note => note,
90         :event => "reopened",
91         :body => ""
92       )
93       notification = build_stubbed(:notification, :record => note_comment)
94
95       render(
96         "notifications/notification",
97         :notification => notification
98       )
99
100       assert_dom ".web-notification" do
101         assert_dom "h2", "Note reopened"
102         assert_dom "time", "less than 1 minute ago"
103         assert_not_dom "blockquote"
104       end
105     end
106   end
107 end