1 require "application_system_test_case"
3 class SearchTest < ApplicationSystemTestCase
4 test "click on 'where is this' sets search input value and makes reverse geocoding request with zoom" do
5 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=$})
6 .to_return(:status => 400, :body => <<-BODY)
7 <?xml version="1.0" encoding="UTF-8"?>
10 <message>Parameter 'zoom' must be a number.</message>
14 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=15$})
15 .to_return(:status => 200, :body => <<-BODY)
16 <?xml version="1.0" encoding="UTF-8"?>
17 <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">
18 <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>
20 <suburb>Broxbourne</suburb>
21 <city>Broxbourne</city>
22 <county>Hertfordshire</county>
23 <state_district>East of England</state_district>
24 <state>England</state>
25 <country>United Kingdom</country>
26 <country_code>gb</country_code>
31 visit "/#map=15/51.76320/-0.00760"
33 assert_field "Search", :with => ""
34 click_on "Where is this?"
36 assert_field "Search", :with => "51.76320, -0.00760"
37 assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
40 test "query search link sets search input value" do
41 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
42 .to_return(:status => 404)
44 visit search_path(:query => "2.341, 7.896")
46 assert_field "Search", :with => "2.341, 7.896"
49 test "latlon search link sets search input value" do
50 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
51 .to_return(:status => 404)
53 visit search_path(:lat => "4.321", :lon => "9.876")
55 assert_field "Search", :with => "4.321, 9.876"
58 test "search adds viewbox param to Nominatim link" do
59 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/search\?})
60 .to_return(:status => 404)
64 fill_in "query", :with => "paris"
67 assert_link "OpenStreetMap Nominatim", :href => /&viewbox=/
70 test "search adds zoom param to reverse Nominatim link" do
71 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
72 .to_return(:status => 404)
74 visit "/#map=7/1.234/6.789"
76 fill_in "query", :with => "60 30"
79 assert_link "OpenStreetMap Nominatim", :href => /&zoom=7/