Tracker and ITS-G5 as separate overlays, Overlays grouped by category: the tracker gets a name/icon/color, charging from its USB power topic, a floating info card (per-device opacity), a trail of the last 1–24 h and optional position logging that survives restarts (LiveStore); hiking trails keep their main checkbox as an all-countries toggle
CI / check (push) Successful in 20s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-19 11:57:36 +01:00
1 parent 3fc8c75c60
commit 0e5f79f8e4
9 files changed
+801 -205

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
require_relative "test_helper"
require "tmpdir"
require_relative "../lib/maptool/live_store"
class LiveStoreTest < Minitest::Test
def setup
@dir = Dir.mktmpdir("maptool-live-test")
end
def teardown
FileUtils.remove_entry(@dir)
end
def position(lat, lon, extra = {})
{ "latitude" => lat, "longitude" => lon }.merge(extra)
end
def test_tracker_snapshot_with_age_power_and_settings
store = Maptool::LiveStore.new(@dir)
now = Time.now.to_f
store.record_tracker(position(48.1, 17.1, "battery_level" => 80), at: now - 30)
store.record_usb_power("ON")
tracker = store.snapshot(now: now)[:tracker]
assert_equal 48.1, tracker["latitude"]
assert_equal 30, tracker["age"]
assert_equal true, tracker["usb_power"]
refute tracker.key?("received_at")
assert_equal "Tracker", store.snapshot[:settings]["name"]
store.record_usb_power("OFF")
assert_equal false, store.snapshot(now: now)[:tracker]["usb_power"]
end
# A parked tracker repeating itself doesn't grow the trail; moving does,
# and the trail shown is only the last trail_hours.
def test_trail_grows_on_movement_and_is_cut_to_trail_hours
store = Maptool::LiveStore.new(@dir)
now = Time.now.to_f
store.record_tracker(position(48.0, 17.0), at: now - 7200)
store.record_tracker(position(48.0, 17.0), at: now - 7100) # same spot, 100 s later: skipped
store.record_tracker(position(48.01, 17.0), at: now - 600) # ~1.1 km on
store.record_tracker(position(48.02, 17.0), at: now - 60)
assert_equal [[17.0, 48.01], [17.0, 48.02]], store.snapshot(now: now)[:tracker]["trail"] # trail_hours 1
store.update_settings("trail_hours" => "4")
assert_equal 3, store.snapshot(now: now)[:tracker]["trail"].size
store.update_settings("trail_hours" => "0")
assert_empty store.snapshot(now: now)[:tracker]["trail"]
end
def test_logged_trail_survives_a_restart_and_unlogged_does_not
store = Maptool::LiveStore.new(@dir)
now = Time.now.to_f
store.record_tracker(position(48.0, 17.0), at: now - 120)
store.update_settings("logging" => "true")
store.record_tracker(position(48.01, 17.0), at: now - 60)
store.record_tracker(position(48.02, 17.0), at: now)
reloaded = Maptool::LiveStore.new(@dir)
reloaded.record_tracker(position(48.02, 17.0), at: now) # same spot: no new point
assert_equal [[17.0, 48.01], [17.0, 48.02]], reloaded.snapshot(now: now)[:tracker]["trail"]
assert_equal true, reloaded.settings["logging"]
end
def test_settings_are_sanitized_and_persisted
store = Maptool::LiveStore.new(@dir)
store.update_settings("name" => " Run ", "icon" => "walking", "color" => "#7cc957", "trail_hours" => "2", "evil" => "x")
store.update_settings("color" => "red", "trail_hours" => "3", "name" => "")
settings = Maptool::LiveStore.new(@dir).settings
assert_equal({ "name" => "Run", "icon" => "walking", "color" => "#7cc957", "logging" => false, "trail_hours" => 2 }, settings)
end
def test_its_stations_expire
store = Maptool::LiveStore.new(@dir)
now = Time.now.to_f
store.record_its({ "id" => "old", "lat" => 48, "lon" => 17 }, at: now - Maptool::LiveStore::ITS_STALE_AFTER - 5)
store.record_its({ "id" => "new", "lat" => 48, "lon" => 17 }, at: now)
store.record_its({ "lat" => 48 }, at: now) # no id: ignored
assert_equal ["new"], store.snapshot(now: now)[:its].map { |s| s["id"] }
end
end