]> git.openstreetmap.org Git - rails.git/blob - test/system/issues_test.rb
Teach database structure normalise to ignore btree_gist comment
[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_issues_with_no_reported_user
45     sign_in_as(create(:moderator_user))
46     anonymous_note = create(:note_with_comments)
47     issue = create(:issue, :reportable => anonymous_note, :assigned_role => "moderator")
48
49     visit issues_path
50     assert_content reportable_title(anonymous_note)
51
52     visit issue_path(issue)
53     assert_content reportable_title(anonymous_note)
54   end
55
56   def test_search_issues_by_user
57     good_user = create(:user)
58     bad_user = create(:user)
59     create(:issue, :reportable => bad_user, :reported_user => bad_user, :assigned_role => "administrator")
60
61     sign_in_as(create(:administrator_user))
62
63     # No issues against the user
64     visit issues_path
65     fill_in "search_by_user", :with => good_user.display_name
66     click_on "Search"
67     assert_no_content I18n.t("issues.index.user_not_found")
68     assert_content I18n.t("issues.index.issues_not_found")
69
70     # User doesn't exist
71     visit issues_path
72     fill_in "search_by_user", :with => "Nonexistent User"
73     click_on "Search"
74     assert_content I18n.t("issues.index.user_not_found")
75     assert_content I18n.t("issues.index.issues_not_found")
76
77     # Find Issue against bad_user
78     visit issues_path
79     fill_in "search_by_user", :with => bad_user.display_name
80     click_on "Search"
81     assert_no_content I18n.t("issues.index.user_not_found")
82     assert_no_content I18n.t("issues.index.issues_not_found")
83   end
84
85   def test_commenting
86     issue = create(:issue, :assigned_role => "moderator")
87     sign_in_as(create(:moderator_user))
88
89     visit issue_path(issue)
90
91     fill_in :issue_comment_body, :with => "test comment"
92     click_on "Add Comment"
93     assert_content I18n.t("issue_comments.create.comment_created")
94     assert_content "test comment"
95
96     issue.reload
97     assert_equal("test comment", issue.comments.first.body)
98   end
99
100   def test_reassign_issue
101     issue = create(:issue)
102     assert_equal "administrator", issue.assigned_role
103     sign_in_as(create(:administrator_user))
104
105     visit issue_path(issue)
106
107     fill_in :issue_comment_body, :with => "reassigning to moderators"
108     check :reassign
109     click_on "Add Comment"
110
111     issue.reload
112     assert_equal "moderator", issue.assigned_role
113   end
114
115   def test_issue_index_with_multiple_roles
116     user1 = create(:user)
117     user2 = create(:user)
118     issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator")
119     issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator")
120
121     user = create(:administrator_user)
122     create(:user_role, :user => user, :role => "moderator")
123     sign_in_as(user)
124
125     visit issues_path
126
127     assert_link I18n.t("issues.index.reports_count", :count => issue1.reports_count), :href => issue_path(issue1)
128     assert_link I18n.t("issues.index.reports_count", :count => issue2.reports_count), :href => issue_path(issue2)
129   end
130 end