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 ##{Note.last.id}"
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
44 find(".control-button.zoomout").click
47 assert_content "Zoom in to add a note"
48 assert_button "Add Note", :disabled => true
51 find(".control-button.zoomin").click
54 assert_no_content "Zoom in to add a note"
55 assert_button "Add Note", :disabled => false
59 assert_content "Unresolved note ##{Note.last.id}"
60 assert_content "Some newly added note description"
64 test "can open new note page when zoomed out" do
65 visit new_note_path(:anchor => "map=11/0/0")
68 assert_content "Zoom in to add a note"
69 assert_button "Add Note", :disabled => true
71 fill_in "text", :with => "Some newly added note description"
73 assert_content "Zoom in to add a note"
74 assert_button "Add Note", :disabled => true
77 find(".control-button.zoomin").click
80 assert_no_content "Zoom in to add a note"
81 assert_button "Add Note", :disabled => false
85 test "cannot create note when api is readonly" do
86 with_settings(:status => "api_readonly") do
87 visit new_note_path(:anchor => "map=18/0/0")
90 assert_no_button "Add Note", :disabled => true
95 test "encouragement to contribute appears after 10 created notes and disappears after login" do
96 check_encouragement_while_creating_notes(10)
98 sign_in_as(create(:user))
100 check_no_encouragement_while_logging_out
103 test "encouragement to contribute appears after 10 created notes and disappears after email signup" do
104 check_encouragement_while_creating_notes(10)
108 check_no_encouragement_while_logging_out
111 test "encouragement to contribute appears after 10 created notes and disappears after google signup" do
112 check_encouragement_while_creating_notes(10)
116 check_no_encouragement_while_logging_out
121 def check_encouragement_while_creating_notes(encouragement_threshold)
122 encouragement_threshold.times do |n|
123 visit new_note_path(:anchor => "map=16/0/#{0.001 * n}")
126 assert_no_content(/already posted at least \d+ anonymous note/)
128 fill_in "text", :with => "new note ##{n + 1}"
131 assert_content "new note ##{n + 1}"
135 visit new_note_path(:anchor => "map=16/0/#{0.001 * encouragement_threshold}")
138 assert_content(/already posted at least #{encouragement_threshold} anonymous note/)
142 def check_no_encouragement_while_logging_out
143 visit new_note_path(:anchor => "map=16/0/0")
146 assert_no_content(/already posted at least \d+ anonymous note/)
150 visit new_note_path(:anchor => "map=16/0/0")
153 assert_no_content(/already posted at least \d+ anonymous note/)
157 def sign_up_with_email
160 within_content_body do
161 fill_in "Email", :with => "new_user_account@example.com"
162 fill_in "Display Name", :with => "new_user_account"
163 fill_in "Password", :with => "new_user_password"
164 fill_in "Confirm Password", :with => "new_user_password"
171 email = ActionMailer::Base.deliveries.first
172 email_text = email.parts[0].parts[0].decoded
173 match = %r{/user/new_user_account/confirm\?confirm_string=\S+}.match(email_text)
178 assert_content "Welcome!"
181 def sign_up_with_google
182 OmniAuth.config.add_mock(:google,
184 :extra => { :id_info => { :openid_id => "http://localhost:1123/new.tester" } },
185 :info => { :email => "google_user_account@example.com", :name => "google_user_account" })
189 within_content_body do
190 click_on "Log in with Google"