]> git.openstreetmap.org Git - rails.git/blob - test/system/issues_test.rb
Merge branch 'master' into next
[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 page.has_content?(I18n.t("user.login.title"))
9   end
10
11   def test_view_issues_normal_user
12     sign_in_as(create(:user))
13
14     visit issues_path
15     assert page.has_content?(I18n.t("application.require_moderator_or_admin.not_a_moderator_or_admin"))
16   end
17
18   def test_view_no_issues
19     sign_in_as(create(:moderator_user))
20
21     visit issues_path
22     assert page.has_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 page.has_content?(issues.first.reported_user.display_name)
31   end
32
33   def test_view_issues_with_no_reported_user
34     sign_in_as(create(:moderator_user))
35     anonymous_note = create(:note_with_comments)
36     issue = create(:issue, :reportable => anonymous_note)
37
38     visit issues_path
39     assert page.has_content?(reportable_title(anonymous_note))
40
41     visit issue_path(issue)
42     assert page.has_content?(reportable_title(anonymous_note))
43   end
44
45   def test_search_issues_by_user
46     good_user = create(:user)
47     bad_user = create(:user)
48     create(:issue, :reportable => bad_user, :reported_user => bad_user, :assigned_role => "administrator")
49
50     sign_in_as(create(:administrator_user))
51
52     # No issues against the user
53     visit issues_path
54     fill_in "search_by_user", :with => good_user.display_name
55     click_on "Search"
56     assert page.has_content?(I18n.t("issues.index.issues_not_found"))
57
58     # User doesn't exist
59     visit issues_path
60     fill_in "search_by_user", :with => "Nonexistant User"
61     click_on "Search"
62     assert page.has_content?(I18n.t("issues.index.user_not_found"))
63
64     # Find Issue against bad_user
65     visit issues_path
66     fill_in "search_by_user", :with => bad_user.display_name
67     click_on "Search"
68     assert_not page.has_content?(I18n.t("issues.index.issues_not_found"))
69   end
70
71   def test_commenting
72     issue = create(:issue)
73     sign_in_as(create(:moderator_user))
74
75     visit issue_path(issue)
76
77     fill_in :issue_comment_body, :with => "test comment"
78     click_on "Submit"
79     assert page.has_content?(I18n.t("issue_comments.create.comment_created"))
80     assert page.has_content?("test comment")
81
82     issue.reload
83     assert_equal issue.comments.first.body, "test comment"
84   end
85
86   def test_reassign_issue
87     issue = create(:issue)
88     assert_equal "administrator", issue.assigned_role
89     sign_in_as(create(:administrator_user))
90
91     visit issue_path(issue)
92
93     fill_in :issue_comment_body, :with => "reassigning to moderators"
94     check :reassign
95     click_on "Submit"
96
97     issue.reload
98     assert_equal "moderator", issue.assigned_role
99   end
100
101   def test_issue_index_with_multiple_roles
102     user1 = create(:user)
103     user2 = create(:user)
104     issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator")
105     issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator")
106
107     user = create(:administrator_user)
108     create(:user_role, :user => user, :role => "moderator")
109     sign_in_as(user)
110
111     visit issues_path
112
113     assert page.has_link?(I18n.t("issues.index.reports_count", :count => issue1.reports_count), :href => issue_path(issue1))
114     assert page.has_link?(I18n.t("issues.index.reports_count", :count => issue2.reports_count), :href => issue_path(issue2))
115   end
116 end