1 require "application_system_test_case"
3 class QueryFeaturesSystemTest < ApplicationSystemTestCase
4 test "sorts enclosing features correctly" do
5 visit "/#map=15/54.18315/7.88473"
8 click_on "Query features"
10 stub_overpass :enclosing_elements => [
15 "minlat" => 47.2701114,
16 "minlon" => 5.8663153,
17 "maxlat" => 55.0991610,
18 "maxlon" => 15.0419309
22 "border_type" => "country",
23 "boundary" => "administrative",
24 "name" => "Deutschland",
25 "name:de" => "Deutschland",
26 "name:en" => "Germany",
34 "minlat" => 53.3598160,
35 "minlon" => 7.5211615,
36 "maxlat" => 55.0991610,
37 "maxlon" => 11.6723860
41 "border_type" => "state",
42 "boundary" => "administrative",
43 "name" => "Schleswig-Holstein",
44 "name:de" => "Schleswig-Holstein",
45 "name:en" => "Schleswig-Holstein",
53 "minlat" => 54.1693099,
54 "minlon" => 7.8648436,
55 "maxlat" => 54.1907839,
59 "name" => "Helgoland",
60 "name:de" => "Helgoland",
61 "name:en" => "Heligoland",
71 assert_link "Heligoland"
72 assert_link "Schleswig-Holstein", :below => find_link("Heligoland")
73 assert_link "Germany", :below => find_link("Schleswig-Holstein")
77 test "sorts enclosing features correctly across antimeridian" do
78 visit "/#map=15/60/30"
81 click_on "Query features"
83 stub_overpass :enclosing_elements => [
88 "minlat" => 41.1850968,
89 "minlon" => 19.4041722,
90 "maxlat" => 82.0586232,
91 "maxlon" => -168.9769440
95 "border_type" => "nation",
96 "boundary" => "administrative",
98 "name:en" => "Russia",
99 "name:ru" => "Россия",
104 "type" => "relation",
107 "minlat" => 59.8587853,
108 "minlon" => 29.6720697,
109 "maxlat" => 60.0370554,
110 "maxlon" => 30.2307057
113 "name" => "Невская губа",
114 "name:en" => "Neva Bay",
115 "name:ru" => "Невская губа",
117 "type" => "multipolygon"
126 assert_link "Neva Bay"
127 assert_link "Russia", :below => find_link("Neva Bay")
131 test "sorts enclosing features correctly with multiple bboxes across antimeridian" do
132 visit "/#map=15/-16.155/179.995"
135 click_on "Query features"
137 stub_overpass :enclosing_elements => [
139 "type" => "relation",
142 "minlat" => -21.9434274,
143 "minlon" => 174.4214965,
144 "maxlat" => -12.2613866,
145 "maxlon" => -178.0034928
148 "admin_level" => "2",
149 "boundary" => "administrative",
157 "type" => "relation",
160 "minlat" => -17.0160140,
161 "minlon" => 178.4754914,
162 "maxlat" => -16.1243512,
163 "maxlon" => -179.6630100
166 "name" => "Vanua Levu Group",
167 "place" => "archipelago",
168 "type" => "multipolygon",
169 "wikidata" => "Q2756586"
173 "type" => "relation",
176 "minlat" => -17.0160140,
177 "minlon" => 178.4754914,
178 "maxlat" => -16.1243512,
179 "maxlon" => -179.9513876
182 "name" => "Vanua Levu",
184 "type" => "multipolygon",
185 "wikidata" => "Q327733"
194 assert_link "Vanua Levu"
195 assert_link "Vanua Levu Group", :below => find_link("Vanua Levu")
196 assert_link "Fiji", :below => find_link("Vanua Levu Group")
202 def stub_overpass(nearby_elements: [], enclosing_elements: [])
203 execute_script <<~SCRIPT
205 const originalFetch = fetch;
206 window.fetch = (...args) => {
207 const [resource, options] = args;
209 if (resource != OSM.OVERPASS_URL) return originalFetch(...args);
211 const data = options.body.get("data"),
212 elements = data.includes("is_in") ? #{enclosing_elements.to_json} : #{nearby_elements.to_json};
214 return Promise.resolve({
215 json: () => Promise.resolve({ elements })