1 # frozen_string_literal: true
3 require "application_system_test_case"
5 class SearchTest < ApplicationSystemTestCase
7 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/search\?})
8 .to_return(:status => 404)
10 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
11 .to_return(:status => 404)
13 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=$})
14 .to_return(:status => 400, :body => <<-BODY)
15 <?xml version="1.0" encoding="UTF-8"?>
18 <message>Parameter 'zoom' must be a number.</message>
22 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=15$})
23 .to_return(:status => 200, :body => <<-BODY)
24 <?xml version="1.0" encoding="UTF-8"?>
25 <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">
26 <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>
28 <suburb>Broxbourne</suburb>
29 <city>Broxbourne</city>
30 <county>Hertfordshire</county>
31 <state_district>East of England</state_district>
32 <state>England</state>
33 <country>United Kingdom</country>
34 <country_code>gb</country_code>
40 test "click on 'where is this' sets search input value and makes reverse geocoding request with zoom" do
41 visit "/#map=15/51.76320/-0.00760"
43 assert_field "Search", :with => ""
44 click_on "Where is this?"
46 assert_field "Search", :with => "51.76320, -0.00760"
47 assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
50 test "'Show address' from context menu makes reverse geocoding request with zoom" do
51 visit "/#map=15/51.76320/-0.00760"
53 find_by_id("map").right_click
54 click_on "Show address"
56 assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
59 test "query search link sets search input value" do
60 visit search_path(:query => "2.341, 7.896")
62 assert_field "Search", :with => "2.341, 7.896"
65 test "latlon search link sets search input value" do
66 visit search_path(:lat => "4.321", :lon => "9.876")
68 assert_field "Search", :with => "4.321, 9.876"
71 test "search adds viewbox param to Nominatim link" do
74 fill_in "query", :with => "paris"
78 assert_link "Nominatim", :href => /&viewbox=/
82 test "search adds zoom param to reverse Nominatim link" do
83 visit "/#map=7/1.234/6.789"
85 fill_in "query", :with => "60 30"
89 assert_link "Nominatim", :href => /&zoom=7/