1 require "application_system_test_case"
3 class CreateNoteTest < ApplicationSystemTestCase
4 include ActionMailer::TestHelper
7 OmniAuth.config.test_mode = true
9 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
13 OmniAuth.config.mock_auth[:google] = nil
14 OmniAuth.config.test_mode = false
17 test "can create note" do
18 visit new_note_path(:anchor => "map=18/0/0")
21 assert_button "Add Note", :disabled => true
23 fill_in "text", :with => "Some newly added note description"
26 assert_content "Unresolved note #"
27 assert_content "Some newly added note description"
31 test "cannot create new note when zoomed out" do
32 visit new_note_path(:anchor => "map=12/0/0")
35 assert_no_content "Zoom in to add a note"
36 assert_button "Add Note", :disabled => true
38 fill_in "text", :with => "Some newly added note description"
40 assert_no_content "Zoom in to add a note"
41 assert_button "Add Note", :disabled => false
49 assert_content "Zoom in to add a note"
50 assert_button "Add Note", :disabled => true
58 assert_no_content "Zoom in to add a note"
59 assert_button "Add Note", :disabled => false
63 assert_content "Unresolved note #"
64 assert_content "Some newly added note description"
68 test "can open new note page when zoomed out" do
69 visit new_note_path(:anchor => "map=11/0/0")
72 assert_content "Zoom in to add a note"
73 assert_button "Add Note", :disabled => true
75 fill_in "text", :with => "Some newly added note description"
77 assert_content "Zoom in to add a note"
78 assert_button "Add Note", :disabled => true
86 assert_no_content "Zoom in to add a note"
87 assert_button "Add Note", :disabled => false
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")
96 assert_no_button "Add Note", :disabled => true
101 test "encouragement to contribute appears after 10 created notes and disappears after login" do
102 check_encouragement_while_creating_notes(10)
104 sign_in_as(create(:user))
106 check_no_encouragement_while_logging_out
109 test "encouragement to contribute appears after 10 created notes and disappears after email signup" do
110 check_encouragement_while_creating_notes(10)
114 check_no_encouragement_while_logging_out
117 test "encouragement to contribute appears after 10 created notes and disappears after google signup" do
118 check_encouragement_while_creating_notes(10)
122 check_no_encouragement_while_logging_out
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}")
132 assert_no_content(/already posted at least \d+ anonymous note/)
134 fill_in "text", :with => "new note ##{n + 1}"
137 assert_content "new note ##{n + 1}"
141 visit new_note_path(:anchor => "map=16/0/#{0.001 * encouragement_threshold}")
144 assert_content(/already posted at least #{encouragement_threshold} anonymous note/)
148 def check_no_encouragement_while_logging_out
149 visit new_note_path(:anchor => "map=16/0/0")
152 assert_no_content(/already posted at least \d+ anonymous note/)
156 visit new_note_path(:anchor => "map=16/0/0")
159 assert_no_content(/already posted at least \d+ anonymous note/)
163 def sign_up_with_email
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"
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)
184 assert_content "Welcome!"
187 def sign_up_with_google
188 OmniAuth.config.add_mock(:google,
190 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
191 :info => { :email => "google_user_account@example.com", :name => "google_user_account" })
195 within_content_body do
196 click_on "Log in with Google"