Files
maptool/test/test_search.rb
T
randy f73badd107
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 17s
Drive as the Design canvas' Grid: the page as 16 × 10 cells from a screen profile (public/drive/road.json, {area, widget, …} per cell, to be edited in the app later), the map 13 × 8 with nothing over it; the manoeuvre, speed, limit, altitude, time, sun, status (online, rec), next stop with km / ETA to it and to the end, the route's elevation of the next 10 km, a compass; keys Trip, Points, Layers, Search, Menu, − + 3D Follow, Terrain, day/dusk/night. A menu opens in the right 7 × 8 as cells of its own and the map narrows to 9 × 8 (drive_menus.js): Trip and Search as GridTrip / GridSearch (a stop a row, ✓ ↑ ↓ ✕ a cell each; results with their pins on the map); Points as GridPoints (the library nearest the car — /api/search with no words and a center lists every saved feature nearest first — along the route ahead, shown, or one folder at a time; an eye per row, + a point as a stop); Layers as GridLayers (the On the map panel's own switches and Online | Offline, presets Road / Off-road / Overnight, + Keep); Terrain as GridTerrain (roll / pitch dials with the max held, climb and side slope ahead from the DEM, the next 2 km, Level here = can.json's levelling action in two taps), on by itself on an unpaved surface (/api/road now gives Valhalla's surface) or past 10° for 10 s, back after 2 km of paved road, automatic / by hand in the Menu. The dashboard polls for the grid without its overlay; the old drive bar and floating buttons gone
2026-12-03 10:47:40 +01:00

76 lines
3.1 KiB
Ruby

require_relative "test_helper"
require "maptool/gpx_store"
require "maptool/library"
require "maptool/search"
require "stringio"
class SearchTest < Minitest::Test
def setup
@data_dir = Dir.mktmpdir
@library = Maptool::Library.new(File.join(@data_dir, "library.sqlite"),
gpx_store: Maptool::GpxStore.new(File.join(@data_dir, "gpx")),
sources_dir: File.join(@data_dir, "sources"))
camp = { "type" => "FeatureCollection", "features" => [
point("Kemp Košice", 21.26, 48.72, "pitná voda"),
{ "type" => "Feature", "properties" => { "kind" => "track" },
"geometry" => { "type" => "LineString", "coordinates" => [[17.0, 48.0, 150], [18.0, 49.0, 300]] } },
] }
@library.import(folder: "trips", filename: "camps.geojson", io: StringIO.new(JSON.generate(camp)))
trails = File.join(@data_dir, "hiking_trails")
FileUtils.mkdir_p(trails)
File.write(File.join(trails, "SK.geojson"),
JSON.generate("type" => "FeatureCollection", "features" => [point("Cesta hrdinov SNP", 19.0, 48.8)]))
end
def test_finds_across_sources_ignoring_case_and_diacritics_and_says_where
layer = search("kosice")
assert_equal [["Kemp Košice", "layers", "trips / camps"]], layer.map { |r| r.values_at(:name, :source, :source_label) }
assert_match(/\Aitem:/, layer.first[:ref])
trail = search("snp hrdinov").first
assert_equal ["hiking_trails", "SK", "Hiking trails SK"], trail.values_at(:source, :ref, :source_label)
end
def test_matches_description_and_falls_back_to_node_label_with_bbox
assert_equal ["Kemp Košice"], search("voda").map { |r| r[:name] }
track = search("camps").find { |r| r[:name] == "camps" }
assert_equal [17.0, 48.0, 18.0, 49.0], track[:bbox]
end
def test_with_a_map_center_results_come_nearest_first_with_their_distance
camps = { "type" => "FeatureCollection", "features" => [
point("Kemp far", 21.0, 48.7), point("Kemp near", 17.1, 48.15),
] }
@library.import(folder: "", filename: "more.geojson", io: StringIO.new(JSON.generate(camps)))
results = search("kemp", center: [48.14, 17.10])
assert_equal ["Kemp near", "Kemp far", "Kemp Košice"], results.map { |r| r[:name] }
assert_in_delta 1.3, results.first[:distance_km], 0.2
end
def test_source_filter_and_blank_query
assert_empty search("snp", sources: ["layers"])
assert_empty search(" ")
end
def test_blank_query_with_a_center_lists_the_library_nearest_first
results = search("", center: [48.72, 21.26])
assert_equal "Kemp Košice", results.first[:name]
assert(results.all? { |r| r[:source] == "layers" })
assert_empty search("", center: [48.72, 21.26], sources: ["hiking_trails"])
end
private
def search(text, **opts)
Maptool::Search.query(text, library: @library, data_dir: @data_dir, **opts)
end
def point(name, lng, lat, description = nil)
{ "type" => "Feature", "geometry" => { "type" => "Point", "coordinates" => [lng, lat] },
"properties" => { "name" => name, "description" => description }.compact }
end
end