]> git.openstreetmap.org Git - rails.git/blob - test/system/create_note_test.rb
Localisation updates from https://translatewiki.net.
[rails.git] / test / system / create_note_test.rb
1 require "application_system_test_case"
2
3 class CreateNoteTest < ApplicationSystemTestCase
4   include ActionMailer::TestHelper
5
6   def setup
7     OmniAuth.config.test_mode = true
8
9     stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
10   end
11
12   def teardown
13     OmniAuth.config.mock_auth[:google] = nil
14     OmniAuth.config.test_mode = false
15   end
16
17   test "can create note" do
18     visit new_note_path(:anchor => "map=18/0/0")
19
20     within_sidebar do
21       assert_button "Add Note", :disabled => true
22
23       fill_in "text", :with => "Some newly added note description"
24       click_on "Add Note"
25
26       assert_content "Unresolved note #"
27       assert_content "Some newly added note description"
28     end
29   end
30
31   test "cannot create new note when zoomed out" do
32     visit new_note_path(:anchor => "map=12/0/0")
33
34     within_sidebar do
35       assert_no_content "Zoom in to add a note"
36       assert_button "Add Note", :disabled => true
37
38       fill_in "text", :with => "Some newly added note description"
39
40       assert_no_content "Zoom in to add a note"
41       assert_button "Add Note", :disabled => false
42     end
43
44     within "#map" do
45       click_on "Zoom Out"
46     end
47
48     within_sidebar do
49       assert_content "Zoom in to add a note"
50       assert_button "Add Note", :disabled => true
51     end
52
53     within "#map" do
54       click_on "Zoom In"
55     end
56
57     within_sidebar do
58       assert_no_content "Zoom in to add a note"
59       assert_button "Add Note", :disabled => false
60
61       click_on "Add Note"
62
63       assert_content "Unresolved note #"
64       assert_content "Some newly added note description"
65     end
66   end
67
68   test "can open new note page when zoomed out" do
69     visit new_note_path(:anchor => "map=11/0/0")
70
71     within_sidebar do
72       assert_content "Zoom in to add a note"
73       assert_button "Add Note", :disabled => true
74
75       fill_in "text", :with => "Some newly added note description"
76
77       assert_content "Zoom in to add a note"
78       assert_button "Add Note", :disabled => true
79     end
80
81     within "#map" do
82       click_on "Zoom In"
83     end
84
85     within_sidebar do
86       assert_no_content "Zoom in to add a note"
87       assert_button "Add Note", :disabled => false
88     end
89   end
90
91   test "cannot create note when api is readonly" do
92     with_settings(:status => "api_readonly") do
93       visit new_note_path(:anchor => "map=18/0/0")
94
95       within_sidebar do
96         assert_no_button "Add Note", :disabled => true
97       end
98     end
99   end
100
101   test "encouragement to contribute appears after 10 created notes and disappears after login" do
102     check_encouragement_while_creating_notes(10)
103
104     sign_in_as(create(:user))
105
106     check_no_encouragement_while_logging_out
107   end
108
109   test "encouragement to contribute appears after 10 created notes and disappears after email signup" do
110     check_encouragement_while_creating_notes(10)
111
112     sign_up_with_email
113
114     check_no_encouragement_while_logging_out
115   end
116
117   test "encouragement to contribute appears after 10 created notes and disappears after google signup" do
118     check_encouragement_while_creating_notes(10)
119
120     sign_up_with_google
121
122     check_no_encouragement_while_logging_out
123   end
124
125   private
126
127   def check_encouragement_while_creating_notes(encouragement_threshold)
128     encouragement_threshold.times do |n|
129       visit new_note_path(:anchor => "map=16/0/#{0.001 * n}")
130
131       within_sidebar do
132         assert_no_content(/already posted at least \d+ anonymous note/)
133
134         fill_in "text", :with => "new note ##{n + 1}"
135         click_on "Add Note"
136
137         assert_content "new note ##{n + 1}"
138       end
139     end
140
141     visit new_note_path(:anchor => "map=16/0/#{0.001 * encouragement_threshold}")
142
143     within_sidebar do
144       assert_content(/already posted at least #{encouragement_threshold} anonymous note/)
145     end
146   end
147
148   def check_no_encouragement_while_logging_out
149     visit new_note_path(:anchor => "map=16/0/0")
150
151     within_sidebar do
152       assert_no_content(/already posted at least \d+ anonymous note/)
153     end
154
155     sign_out
156     visit new_note_path(:anchor => "map=16/0/0")
157
158     within_sidebar do
159       assert_no_content(/already posted at least \d+ anonymous note/)
160     end
161   end
162
163   def sign_up_with_email
164     click_on "Sign Up"
165
166     within_content_body do
167       fill_in "Email", :with => "new_user_account@example.com"
168       fill_in "Display Name", :with => "new_user_account"
169       fill_in "Password", :with => "new_user_password"
170       fill_in "Confirm Password", :with => "new_user_password"
171
172       assert_emails 1 do
173         click_on "Sign Up"
174       end
175     end
176
177     email = ActionMailer::Base.deliveries.first
178     email_text = email.parts[0].parts[0].decoded
179     match = %r{/user/new_user_account/confirm\?confirm_string=\S+}.match(email_text)
180     assert_not_nil match
181
182     visit match[0]
183
184     assert_content "Welcome!"
185   end
186
187   def sign_up_with_google
188     OmniAuth.config.add_mock(:google,
189                              :uid => "123454321",
190                              :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
191                              :info => { :email => "google_user_account@example.com", :name => "google_user_account" })
192
193     click_on "Sign Up"
194
195     within_content_body do
196       click_on "Log in with Google"
197       click_on "Sign Up"
198     end
199   end
200 end