]> git.openstreetmap.org Git - rails.git/blob - test/system/issues_test.rb
Merge pull request #4249 from AntonKhorev/no-traces-nav-empty-li
[rails.git] / test / system / issues_test.rb
1 require "application_system_test_case"
2
3 class IssuesTest < ApplicationSystemTestCase
4   include IssuesHelper
5
6   def test_view_issues_not_logged_in
7     visit issues_path
8     assert_content I18n.t("sessions.new.title")
9   end
10
11   def test_view_issues_normal_user
12     sign_in_as(create(:user))
13
14     visit issues_path
15     assert_content "Forbidden"
16   end
17
18   def test_view_no_issues
19     sign_in_as(create(:moderator_user))
20
21     visit issues_path
22     assert_content I18n.t("issues.index.issues_not_found")
23   end
24
25   def test_view_issues
26     sign_in_as(create(:moderator_user))
27     issues = create_list(:issue, 3, :assigned_role => "moderator")
28
29     visit issues_path
30     assert_content issues.first.reported_user.display_name
31   end
32
33   def test_view_issue_with_report
34     sign_in_as(create(:moderator_user))
35     issue = create(:issue, :assigned_role => "moderator")
36     issue.reports << create(:report, :details => "test report text **with kramdown**")
37
38     visit issue_path(issue)
39     assert_content I18n.t("issues.show.reports", :count => 1)
40     assert_content "test report text with kramdown"
41     assert_selector "strong", :text => "with kramdown"
42   end
43
44   def test_view_issue_rich_text_container
45     sign_in_as(create(:moderator_user))
46     issue = create(:issue, :assigned_role => "moderator")
47     issue.reports << create(:report, :details => "paragraph one\n\n---\n\nparagraph two")
48
49     visit issue_path(issue)
50     assert_content I18n.t("issues.show.reports", :count => 1)
51     richtext = find "div.richtext"
52     richtext_elements = richtext.all "*"
53     assert_equal 3, richtext_elements.size
54     assert_equal "p", richtext_elements[0].tag_name
55     assert_equal "paragraph one", richtext_elements[0].text
56     assert_equal "hr", richtext_elements[1].tag_name
57     assert_equal "p", richtext_elements[2].tag_name
58     assert_equal "paragraph two", richtext_elements[2].text
59   end
60
61   def test_view_issues_with_no_reported_user
62     sign_in_as(create(:moderator_user))
63     anonymous_note = create(:note_with_comments)
64     issue = create(:issue, :reportable => anonymous_note, :assigned_role => "moderator")
65
66     visit issues_path
67     assert_content reportable_title(anonymous_note)
68
69     visit issue_path(issue)
70     assert_content reportable_title(anonymous_note)
71   end
72
73   def test_search_issues_by_user
74     good_user = create(:user)
75     bad_user = create(:user)
76     create(:issue, :reportable => bad_user, :reported_user => bad_user, :assigned_role => "administrator")
77
78     sign_in_as(create(:administrator_user))
79
80     # No issues against the user
81     visit issues_path
82     fill_in "search_by_user", :with => good_user.display_name
83     click_button "Search"
84     assert_no_content I18n.t("issues.index.user_not_found")
85     assert_content I18n.t("issues.index.issues_not_found")
86
87     # User doesn't exist
88     visit issues_path
89     fill_in "search_by_user", :with => "Nonexistent User"
90     click_button "Search"
91     assert_content I18n.t("issues.index.user_not_found")
92     assert_content I18n.t("issues.index.issues_not_found")
93
94     # Find Issue against bad_user
95     visit issues_path
96     fill_in "search_by_user", :with => bad_user.display_name
97     click_button "Search"
98     assert_no_content I18n.t("issues.index.user_not_found")
99     assert_no_content I18n.t("issues.index.issues_not_found")
100   end
101
102   def test_commenting
103     issue = create(:issue, :assigned_role => "moderator")
104     sign_in_as(create(:moderator_user))
105
106     visit issue_path(issue)
107
108     fill_in :issue_comment_body, :with => "test comment"
109     click_button "Add Comment"
110     assert_content I18n.t("issue_comments.create.comment_created")
111     assert_content "test comment"
112
113     issue.reload
114     assert_equal("test comment", issue.comments.first.body)
115   end
116
117   def test_reassign_issue
118     issue = create(:issue)
119     assert_equal "administrator", issue.assigned_role
120     sign_in_as(create(:administrator_user))
121
122     visit issue_path(issue)
123
124     fill_in :issue_comment_body, :with => "reassigning to moderators"
125     check :reassign
126     click_button "Add Comment"
127
128     assert_content "and the issue was reassigned"
129     assert_current_path issues_path(:status => "open")
130
131     issue.reload
132     assert_equal "moderator", issue.assigned_role
133   end
134
135   def test_reassign_issue_as_super_user
136     issue = create(:issue)
137     sign_in_as(create(:super_user))
138
139     visit issue_path(issue)
140
141     fill_in :issue_comment_body, :with => "reassigning to moderators"
142     check :reassign
143     click_button "Add Comment"
144
145     assert_content "and the issue was reassigned"
146     assert_current_path issue_path(issue)
147   end
148
149   def test_issue_index_with_multiple_roles
150     user1 = create(:user)
151     user2 = create(:user)
152     issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator")
153     issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator")
154
155     user = create(:administrator_user)
156     create(:user_role, :user => user, :role => "moderator")
157     sign_in_as(user)
158
159     visit issues_path
160
161     assert_link I18n.t("issues.index.reports_count", :count => issue1.reports_count), :href => issue_path(issue1)
162     assert_link I18n.t("issues.index.reports_count", :count => issue2.reports_count), :href => issue_path(issue2)
163   end
164 end