]> git.openstreetmap.org Git - rails.git/blob - test/system/issues_test.rb
Unify lat/lon formatting for json output
[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("users.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?("Forbidden")
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, :assigned_role => "moderator")
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_not page.has_content?(I18n.t("issues.index.user_not_found"))
57     assert page.has_content?(I18n.t("issues.index.issues_not_found"))
58
59     # User doesn't exist
60     visit issues_path
61     fill_in "search_by_user", :with => "Nonexistant User"
62     click_on "Search"
63     assert page.has_content?(I18n.t("issues.index.user_not_found"))
64     assert page.has_content?(I18n.t("issues.index.issues_not_found"))
65
66     # Find Issue against bad_user
67     visit issues_path
68     fill_in "search_by_user", :with => bad_user.display_name
69     click_on "Search"
70     assert_not page.has_content?(I18n.t("issues.index.user_not_found"))
71     assert_not page.has_content?(I18n.t("issues.index.issues_not_found"))
72   end
73
74   def test_commenting
75     issue = create(:issue)
76     sign_in_as(create(:moderator_user))
77
78     visit issue_path(issue)
79
80     fill_in :issue_comment_body, :with => "test comment"
81     click_on "Add Comment"
82     assert page.has_content?(I18n.t("issue_comments.create.comment_created"))
83     assert page.has_content?("test comment")
84
85     issue.reload
86     assert_equal issue.comments.first.body, "test comment"
87   end
88
89   def test_reassign_issue
90     issue = create(:issue)
91     assert_equal "administrator", issue.assigned_role
92     sign_in_as(create(:administrator_user))
93
94     visit issue_path(issue)
95
96     fill_in :issue_comment_body, :with => "reassigning to moderators"
97     check :reassign
98     click_on "Add Comment"
99
100     issue.reload
101     assert_equal "moderator", issue.assigned_role
102   end
103
104   def test_issue_index_with_multiple_roles
105     user1 = create(:user)
106     user2 = create(:user)
107     issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator")
108     issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator")
109
110     user = create(:administrator_user)
111     create(:user_role, :user => user, :role => "moderator")
112     sign_in_as(user)
113
114     visit issues_path
115
116     assert page.has_link?(I18n.t("issues.index.reports_count", :count => issue1.reports_count), :href => issue_path(issue1))
117     assert page.has_link?(I18n.t("issues.index.reports_count", :count => issue2.reports_count), :href => issue_path(issue2))
118   end
119 end