1 require "application_system_test_case"
3 class CreateNoteTest < ApplicationSystemTestCase
4 include ActionMailer::TestHelper
7 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
10 test "can create note" do
11 visit new_note_path(:anchor => "map=18/0/0")
14 assert_button "Add Note", :disabled => true
16 fill_in "text", :with => "Some newly added note description"
19 assert_content "Unresolved note ##{Note.last.id}"
20 assert_content "Some newly added note description"
24 test "cannot create new note when zoomed out" do
25 visit new_note_path(:anchor => "map=12/0/0")
28 assert_no_content "Zoom in to add a note"
29 assert_button "Add Note", :disabled => true
31 fill_in "text", :with => "Some newly added note description"
33 assert_no_content "Zoom in to add a note"
34 assert_button "Add Note", :disabled => false
37 find(".control-button.zoomout").click
40 assert_content "Zoom in to add a note"
41 assert_button "Add Note", :disabled => true
44 find(".control-button.zoomin").click
47 assert_no_content "Zoom in to add a note"
48 assert_button "Add Note", :disabled => false
52 assert_content "Unresolved note ##{Note.last.id}"
53 assert_content "Some newly added note description"
57 test "can open new note page when zoomed out" do
58 visit new_note_path(:anchor => "map=11/0/0")
61 assert_content "Zoom in to add a note"
62 assert_button "Add Note", :disabled => true
64 fill_in "text", :with => "Some newly added note description"
66 assert_content "Zoom in to add a note"
67 assert_button "Add Note", :disabled => true
70 find(".control-button.zoomin").click
73 assert_no_content "Zoom in to add a note"
74 assert_button "Add Note", :disabled => false
78 test "cannot create note when api is readonly" do
79 with_settings(:status => "api_readonly") do
80 visit new_note_path(:anchor => "map=18/0/0")
83 assert_no_button "Add Note", :disabled => true
88 test "encouragement to contribute appears after 10 created notes and disappears after login" do
89 check_encouragement_while_creating_notes(10)
91 sign_in_as(create(:user))
93 check_no_encouragement_while_logging_out
96 test "encouragement to contribute appears after 10 created notes and disappears after signup" do
97 check_encouragement_while_creating_notes(10)
101 check_no_encouragement_while_logging_out
106 def check_encouragement_while_creating_notes(encouragement_threshold)
107 encouragement_threshold.times do |n|
108 visit new_note_path(:anchor => "map=16/0/#{0.001 * n}")
111 assert_no_content(/already posted at least \d+ anonymous note/)
113 fill_in "text", :with => "new note ##{n + 1}"
116 assert_content "new note ##{n + 1}"
120 visit new_note_path(:anchor => "map=16/0/#{0.001 * encouragement_threshold}")
123 assert_content(/already posted at least #{encouragement_threshold} anonymous note/)
127 def check_no_encouragement_while_logging_out
128 visit new_note_path(:anchor => "map=16/0/0")
131 assert_no_content(/already posted at least \d+ anonymous note/)
135 visit new_note_path(:anchor => "map=16/0/0")
138 assert_no_content(/already posted at least \d+ anonymous note/)
142 def sign_up_with_email
145 within_content_body do
146 fill_in "Email", :with => "new_user_account@example.com"
147 fill_in "Display Name", :with => "new_user_account"
148 fill_in "Password", :with => "new_user_password"
149 fill_in "Confirm Password", :with => "new_user_password"
156 email = ActionMailer::Base.deliveries.first
157 email_text = email.parts[0].parts[0].decoded
158 match = %r{/user/new_user_account/confirm\?confirm_string=\S+}.match(email_text)
163 assert_content "Welcome!"