Library phase 2: rename/recolor nodes, rename and move folders, split a layer into items; offline routing design

This commit is contained in:
randy committed 2026-11-13 21:16:35 +01:00
1 parent 4d838395b8
commit 6f5f11cb4d
9 files changed
+467 -39

No files matched your search

+45
View File
@@ -85,6 +85,51 @@ class LibraryTest < Minitest::Test
assert_raises(Maptool::Library::InvalidPath) { library.create_folder("../x") }
end
def test_renaming_and_recoloring_a_track_and_a_layer
@store.save(folder: "", filename: "ride.gpx", io: File.open(fixture_path("sample.gpx")))
library = open_library
layer = library.tree["children"].first["children"].first["path"]
track = library.import(folder: "t", filename: "ride.gpx", io: File.open(fixture_path("sample.gpx"))).first
library.update_node(track, name: "Morning ride", color: "#00ff00")
library.update_node(layer, color: "#0000ff")
nodes = library.tree["children"].flat_map { |f| f["children"].flat_map { |c| c["children"] || [c] } }
assert_includes nodes.map { |n| n.values_at("name", "color") }, ["Morning ride", "#00ff00"]
lines = JSON.parse(library.geojson(layer))["features"].reject { |f| f["geometry"]["type"] == "Point" }
assert_equal ["#0000ff"], lines.map { |f| f["properties"]["color"] }.uniq
library.update_node(track, color: "")
assert_nil JSON.parse(library.geojson(track))["features"].first["properties"]["color"]
assert_raises(Maptool::Library::InvalidValue) { library.update_node(track, color: "red") }
end
def test_splitting_a_layer_turns_it_into_items_and_keeps_note_ids
@store.append_feature(feature: note("Gate", "n1"), folder: "", name: "My Notes")
library = open_library
folder = library.tree["children"].first
key = folder["children"].first["path"]
keys = library.split_layer(key)
assert_equal ["Points (1)"], library.tree["children"].first["children"].map { |c| c["name"] }
assert_equal ["n1"], JSON.parse(library.geojson(keys.first))["features"].map { |f| f["properties"]["id"] }
assert_equal ["My Notes.geojson"], Dir.glob("*/*", base: File.join(@dir, "sources")).map { |f| File.basename(f) }
assert_raises(Maptool::Library::NotFound) { library.geojson(key) }
end
def test_renaming_and_moving_folders
library = open_library
key = library.add_note(note("Gate"), "a/b")
library.create_folder("c")
assert_equal "a/x", library.rename_folder("a/b", "x")
assert_equal "c/x", library.move_folder("a/x", "c")
assert_equal ["a", "c"], library.tree["children"].map { |f| f["name"] }
assert_equal ["Gate"], JSON.parse(library.geojson(key))["features"].map { |f| f["properties"]["name"] }
assert_raises(Maptool::Library::InvalidPath) { library.move_folder("c", "c/x") }
library.create_folder("a/x")
assert_raises(Maptool::Library::InvalidValue) { library.move_folder("c/x", "a") }
end
private
def open_library