]> git.openstreetmap.org Git - rails.git/blob - test/controllers/notifications/note_comment_view_test.rb
Merge remote-tracking branch 'upstream/pull/7294'
[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_commented_with_long_text
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         :body => read_fixture_file("lorem_ipsum.txt")
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 blockquote p", :count => 3
47     end
48
49     def test_render_closed_with_comment
50       comment_author = build_stubbed(
51         :user,
52         :display_name => "Helpful Commenter"
53       )
54       note = build_stubbed(:note)
55       note_comment = build_stubbed(
56         :note_comment,
57         :author => comment_author,
58         :note => note,
59         :event => "closed"
60       )
61       notification = build_stubbed(:notification, :record => note_comment)
62
63       render(
64         "notifications/notification",
65         :notification => notification
66       )
67
68       assert_dom ".web-notification" do
69         assert_dom "h2", "Note resolved"
70         assert_dom "time", "less than 1 minute ago"
71         assert_dom "blockquote", note_comment.body
72       end
73     end
74
75     def test_render_closed_without_comment
76       comment_author = build_stubbed(
77         :user,
78         :display_name => "Helpful Commenter"
79       )
80       note = build_stubbed(:note)
81       note_comment = build_stubbed(
82         :note_comment,
83         :author => comment_author,
84         :note => note,
85         :event => "closed",
86         :body => ""
87       )
88       notification = build_stubbed(:notification, :record => note_comment)
89
90       render(
91         "notifications/notification",
92         :notification => notification
93       )
94
95       assert_dom ".web-notification" do
96         assert_dom "h2", "Note resolved"
97         assert_dom "time", "less than 1 minute ago"
98         assert_not_dom "blockquote"
99       end
100     end
101
102     def test_render_reopened
103       comment_author = build_stubbed(
104         :user,
105         :display_name => "Helpful Commenter"
106       )
107       note = build_stubbed(:note)
108       note_comment = build_stubbed(
109         :note_comment,
110         :author => comment_author,
111         :note => note,
112         :event => "reopened",
113         :body => ""
114       )
115       notification = build_stubbed(:notification, :record => note_comment)
116
117       render(
118         "notifications/notification",
119         :notification => notification
120       )
121
122       assert_dom ".web-notification" do
123         assert_dom "h2", "Note reopened"
124         assert_dom "time", "less than 1 minute ago"
125         assert_not_dom "blockquote"
126       end
127     end
128   end
129 end