1 require "application_system_test_case"
3 class IssuesTest < ApplicationSystemTestCase
6 def test_view_issues_not_logged_in
8 assert_content I18n.t("sessions.new.title")
11 def test_view_issues_normal_user
12 sign_in_as(create(:user))
15 assert_content "Forbidden"
18 def test_view_no_issues
19 sign_in_as(create(:moderator_user))
22 assert_content I18n.t("issues.page.issues_not_found")
26 sign_in_as(create(:moderator_user))
27 issues = create_list(:issue, 3, :assigned_role => "moderator")
30 assert_content issues.first.reported_user.display_name
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**")
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"
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")
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
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")
67 assert_content reportable_title(anonymous_note)
69 visit issue_path(issue)
70 assert_content reportable_title(anonymous_note)
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")
78 sign_in_as(create(:administrator_user))
80 # No issues against the user
82 fill_in "search_by_user", :with => good_user.display_name
84 assert_no_content I18n.t("issues.page.user_not_found")
85 assert_content I18n.t("issues.page.issues_not_found")
89 fill_in "search_by_user", :with => "Nonexistent User"
91 assert_content I18n.t("issues.page.user_not_found")
92 assert_no_content I18n.t("issues.page.issues_not_found")
94 # Find Issue against bad_user
96 fill_in "search_by_user", :with => bad_user.display_name
98 assert_no_content I18n.t("issues.page.user_not_found")
99 assert_no_content I18n.t("issues.page.issues_not_found")
103 issue = create(:issue, :assigned_role => "moderator")
104 sign_in_as(create(:moderator_user))
106 visit issue_path(issue)
108 fill_in :issue_comment_body, :with => "test comment"
109 click_on "Add Comment"
110 assert_content I18n.t("issue_comments.create.comment_created")
111 assert_content "test comment"
114 assert_equal("test comment", issue.comments.first.body)
117 def test_reassign_issue
118 issue = create(:issue)
119 assert_equal "administrator", issue.assigned_role
120 sign_in_as(create(:administrator_user))
122 visit issue_path(issue)
124 fill_in :issue_comment_body, :with => "reassigning to moderators"
126 click_on "Add Comment"
128 assert_content "and the issue was reassigned"
129 assert_current_path issues_path(:status => "open")
132 assert_equal "moderator", issue.assigned_role
135 def test_reassign_issue_as_super_user
136 issue = create(:issue)
137 sign_in_as(create(:super_user))
139 visit issue_path(issue)
141 fill_in :issue_comment_body, :with => "reassigning to moderators"
143 click_on "Add Comment"
145 assert_content "and the issue was reassigned"
146 assert_current_path issue_path(issue)
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")
155 user = create(:administrator_user)
156 create(:user_role, :user => user, :role => "moderator")
161 assert_link I18n.t("issues.page.reports_count", :count => issue1.reports_count), :href => issue_path(issue1)
162 assert_link I18n.t("issues.page.reports_count", :count => issue2.reports_count), :href => issue_path(issue2)
165 def test_issues_pagination
168 create(:issue, :reportable => user, :reported_user => user, :assigned_role => "administrator")
171 sign_in_as(create(:administrator_user))
176 assert_no_content I18n.t("issues.page.user_not_found")
177 assert_no_content I18n.t("issues.page.issues_not_found")
178 assert_css "tr", :count => 51
181 click_on I18n.t("issues.page.older_issues")
182 assert_no_content I18n.t("issues.page.user_not_found")
183 assert_no_content I18n.t("issues.page.issues_not_found")
184 assert_css "tr", :count => 31
187 click_on I18n.t("issues.page.newer_issues")
188 assert_no_content I18n.t("issues.page.user_not_found")
189 assert_no_content I18n.t("issues.page.issues_not_found")
190 assert_css "tr", :count => 51