1 require "application_system_test_case"
3 class SearchTest < ApplicationSystemTestCase
5 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/search\?})
6 .to_return(:status => 404)
8 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
9 .to_return(:status => 404)
11 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=$})
12 .to_return(:status => 400, :body => <<-BODY)
13 <?xml version="1.0" encoding="UTF-8"?>
16 <message>Parameter 'zoom' must be a number.</message>
20 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=15$})
21 .to_return(:status => 200, :body => <<-BODY)
22 <?xml version="1.0" encoding="UTF-8"?>
23 <reversegeocode timestamp="Sun, 01 Mar 15 22:49:45 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="accept-language=&lat=51.76320&lon=-0.00760&zoom=15">
24 <result place_id="150696" osm_type="node" osm_id="28825933" ref="Broxbourne" lat="51.7465723" lon="-0.0190782">Broxbourne, Hertfordshire, East of England, England, United Kingdom</result>
26 <suburb>Broxbourne</suburb>
27 <city>Broxbourne</city>
28 <county>Hertfordshire</county>
29 <state_district>East of England</state_district>
30 <state>England</state>
31 <country>United Kingdom</country>
32 <country_code>gb</country_code>
38 test "click on 'where is this' sets search input value and makes reverse geocoding request with zoom" do
39 visit "/#map=15/51.76320/-0.00760"
41 assert_field "Search", :with => ""
42 click_on "Where is this?"
44 assert_field "Search", :with => "51.76320, -0.00760"
45 assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
48 test "'Show address' from context menu makes reverse geocoding request with zoom" do
49 visit "/#map=15/51.76320/-0.00760"
51 find_by_id("map").right_click
52 click_on "Show address"
54 assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
57 test "query search link sets search input value" do
58 visit search_path(:query => "2.341, 7.896")
60 assert_field "Search", :with => "2.341, 7.896"
63 test "latlon search link sets search input value" do
64 visit search_path(:lat => "4.321", :lon => "9.876")
66 assert_field "Search", :with => "4.321, 9.876"
69 test "search adds viewbox param to Nominatim link" do
72 fill_in "query", :with => "paris"
75 assert_link "OpenStreetMap Nominatim", :href => /&viewbox=/
78 test "search adds zoom param to reverse Nominatim link" do
79 visit "/#map=7/1.234/6.789"
81 fill_in "query", :with => "60 30"
84 assert_link "OpenStreetMap Nominatim", :href => /&zoom=7/