]> git.openstreetmap.org Git - rails.git/blob - test/system/search_test.rb
Add history changesets layer module
[rails.git] / test / system / search_test.rb
1 require "application_system_test_case"
2
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"?>
8         <error>
9           <code>400</code>
10           <message>Parameter 'zoom' must be a number.</message>
11         </error>
12       BODY
13
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=&amp;lat=51.76320&amp;lon=-0.00760&amp;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>
19           <addressparts>
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>
27           </addressparts>
28         </reversegeocode>
29       BODY
30
31     visit "/#map=15/51.76320/-0.00760"
32
33     assert_field "Search", :with => ""
34     click_on "Where is this?"
35
36     assert_field "Search", :with => "51.76320, -0.00760"
37     assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
38   end
39
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)
43
44     visit search_path(:query => "2.341, 7.896")
45
46     assert_field "Search", :with => "2.341, 7.896"
47   end
48
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)
52
53     visit search_path(:lat => "4.321", :lon => "9.876")
54
55     assert_field "Search", :with => "4.321, 9.876"
56   end
57
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)
61
62     visit "/"
63
64     fill_in "query", :with => "paris"
65     click_on "Go"
66
67     assert_link "OpenStreetMap Nominatim", :href => /&viewbox=/
68   end
69
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)
73
74     visit "/#map=7/1.234/6.789"
75
76     fill_in "query", :with => "60 30"
77     click_on "Go"
78
79     assert_link "OpenStreetMap Nominatim", :href => /&zoom=7/
80   end
81 end