1 # frozen_string_literal: true
3 require "application_system_test_case"
5 class CreateNoteTest < ApplicationSystemTestCase
6 include ActionMailer::TestHelper
9 OmniAuth.config.test_mode = true
11 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
15 OmniAuth.config.mock_auth[:google] = nil
16 OmniAuth.config.test_mode = false
19 test "can create note" do
20 visit new_note_path(:anchor => "map=18/0/0")
23 assert_button "Add Note", :disabled => true
25 fill_in "text", :with => "Some newly added note description"
28 assert_content "Unresolved note #"
29 assert_content "Some newly added note description"
33 test "cannot create new note when zoomed out" do
34 visit new_note_path(:anchor => "map=12/0/0")
37 assert_no_content "Zoom in to add a note"
38 assert_button "Add Note", :disabled => true
40 fill_in "text", :with => "Some newly added note description"
42 assert_no_content "Zoom in to add a note"
43 assert_button "Add Note", :disabled => false
51 assert_content "Zoom in to add a note"
52 assert_button "Add Note", :disabled => true
60 assert_no_content "Zoom in to add a note"
61 assert_button "Add Note", :disabled => false
65 assert_content "Unresolved note #"
66 assert_content "Some newly added note description"
70 test "can open new note page when zoomed out" do
71 visit new_note_path(:anchor => "map=11/0/0")
74 assert_content "Zoom in to add a note"
75 assert_button "Add Note", :disabled => true
77 fill_in "text", :with => "Some newly added note description"
79 assert_content "Zoom in to add a note"
80 assert_button "Add Note", :disabled => true
88 assert_no_content "Zoom in to add a note"
89 assert_button "Add Note", :disabled => false
93 test "cannot create note when api is readonly" do
94 with_settings(:status => "api_readonly") do
95 visit new_note_path(:anchor => "map=18/0/0")
98 assert_no_button "Add Note", :disabled => true
103 test "encouragement to contribute appears after 5 created notes and disappears after login" do
104 check_encouragement_while_creating_notes(5)
106 sign_in_as(create(:user))
108 check_no_encouragement_while_logging_out
111 test "encouragement to contribute appears after 5 created notes and disappears after email signup" do
112 check_encouragement_while_creating_notes(5)
116 check_no_encouragement_while_logging_out
119 test "encouragement to contribute appears after 5 created notes and disappears after google signup" do
120 check_encouragement_while_creating_notes(5)
124 check_no_encouragement_while_logging_out
127 test "strict encouragement to contribute appears after 10 created notes and disappears after login" do
128 check_strict_encouragement_while_creating_notes(5, 10)
130 sign_in_as(create(:user))
132 check_no_encouragement_while_logging_out
137 def check_encouragement_while_creating_notes(encouragement_threshold)
138 encouragement_threshold.times do |n|
139 visit new_note_path(:anchor => "map=16/0/#{0.001 * n}")
142 assert_no_content(/already posted at least \d+ anonymous note/)
144 fill_in "text", :with => "new note ##{n + 1}"
147 assert_content "new note ##{n + 1}"
151 visit new_note_path(:anchor => "map=16/0/#{0.001 * encouragement_threshold}")
154 assert_content(/already posted at least #{encouragement_threshold} anonymous note/)
158 def check_strict_encouragement_while_creating_notes(encouragement_threshold, strict_encouragement_threshold)
159 strict_encouragement_threshold.times do |n|
160 visit new_note_path(:anchor => "map=16/0/#{0.001 * n}")
163 if n < encouragement_threshold
164 assert_no_content(/already posted at least \d+ anonymous note/)
166 assert_content(/already posted at least \d+ anonymous note/)
169 fill_in "text", :with => "new note ##{n + 1}"
172 assert_content "new note ##{n + 1}"
176 visit new_note_path(:anchor => "map=16/0/#{0.001 * strict_encouragement_threshold}")
179 assert_content(/already posted at least #{strict_encouragement_threshold} anonymous note/)
180 assert_no_button "Add Note"
184 def check_no_encouragement_while_logging_out
185 visit new_note_path(:anchor => "map=16/0/0")
188 assert_no_content(/already posted at least \d+ anonymous note/)
192 visit new_note_path(:anchor => "map=16/0/0")
195 assert_no_content(/already posted at least \d+ anonymous note/)
199 def sign_up_with_email
202 within_content_body do
203 fill_in "Email", :with => "new_user_account@example.com"
204 fill_in "Display Name", :with => "new_user_account"
205 fill_in "Password", :with => "new_user_password"
206 fill_in "Confirm Password", :with => "new_user_password"
213 email = ActionMailer::Base.deliveries.first
214 email_text = email.parts[0].parts[0].decoded
215 match = %r{/user/new_user_account/confirm\?confirm_string=\S+}.match(email_text)
220 assert_content "Welcome!"
223 def sign_up_with_google
224 OmniAuth.config.add_mock(:google,
226 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
227 :info => { :email => "google_user_account@example.com", :name => "google_user_account" })
231 within_content_body do
232 click_on "Log in with Google"