Library phase 1: SQLite item library with folders, migration of old files as layers, import split into items
This commit is contained in:
1 parent
4216211a20
commit
ad8b72c3d3
16 files changed
+897
-499
No files matched your search
+11
-7
@@ -1,18 +1,21 @@
|
||||
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
|
||||
@store = Maptool::GpxStore.new(File.join(@data_dir, "gpx"))
|
||||
@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]] } },
|
||||
] }
|
||||
@store.save(folder: "trips", filename: "camps.geojson", io: StringIO.new(JSON.generate(camp)))
|
||||
@library.import(folder: "trips", filename: "camps.geojson", io: StringIO.new(JSON.generate(camp)))
|
||||
|
||||
trails = File.join(@data_dir, "hiking_trails")
|
||||
FileUtils.mkdir_p(trails)
|
||||
@@ -22,16 +25,17 @@ class SearchTest < Minitest::Test
|
||||
|
||||
def test_finds_across_sources_ignoring_case_and_diacritics_and_says_where
|
||||
layer = search("kosice")
|
||||
assert_equal [["Kemp Košice", "layers", "trips/camps.geojson"]], layer.map { |r| r.values_at(:name, :source, :ref) }
|
||||
assert_equal [["Kemp Košice", "layers", "trips / Track"]], 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_file_name_with_bbox
|
||||
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").first
|
||||
track = search("trips track").first
|
||||
assert_equal [17.0, 48.0, 18.0, 49.0], track[:bbox]
|
||||
end
|
||||
|
||||
@@ -39,7 +43,7 @@ class SearchTest < Minitest::Test
|
||||
camps = { "type" => "FeatureCollection", "features" => [
|
||||
point("Kemp far", 21.0, 48.7), point("Kemp near", 17.1, 48.15),
|
||||
] }
|
||||
@store.save(folder: "", filename: "more.geojson", io: StringIO.new(JSON.generate(camps)))
|
||||
@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] }
|
||||
@@ -54,7 +58,7 @@ class SearchTest < Minitest::Test
|
||||
private
|
||||
|
||||
def search(text, **opts)
|
||||
Maptool::Search.query(text, gpx_store: @store, data_dir: @data_dir, **opts)
|
||||
Maptool::Search.query(text, library: @library, data_dir: @data_dir, **opts)
|
||||
end
|
||||
|
||||
def point(name, lng, lat, description = nil)
|
||||
|
||||
Reference in new issue
Block a user