prop/test/microwaveprop/format_test.exs
Graham McIntire a9a355be2a
feat(format): miles-primary distance formatting sitewide
Add Microwaveprop.Format.distance_km/1 and a matching formatDistanceKm
helper for the JS side. Both emit "X mi (Y km)" with one decimal under
10 mi and whole numbers above.

Replace the ad-hoc format_dist/format_km_mi helpers with the shared
formatter and update every user-facing distance render: contact
detail, contacts index column, user profile contact/involving tables,
path finder summary + sounding list, contacts map line popups, beacon
coverage tooltip, and propagation map range estimate + rain scatter
cell popup.
2026-04-18 15:53:40 -05:00

25 lines
724 B
Elixir

defmodule Microwaveprop.FormatTest do
use ExUnit.Case, async: true
alias Microwaveprop.Format
describe "distance_km/1" do
test "returns em-dash for nil" do
assert Format.distance_km(nil) == ""
end
test "formats large distances as whole numbers, miles first" do
assert Format.distance_km(235) == "146 mi (235 km)"
assert Format.distance_km(100.0) == "62 mi (100 km)"
end
test "formats short distances with one decimal" do
assert Format.distance_km(1.5) == "0.9 mi (1.5 km)"
assert Format.distance_km(9.6) == "6.0 mi (9.6 km)"
end
test "accepts Decimal input" do
assert Format.distance_km(Decimal.new("235")) == "146 mi (235 km)"
end
end
end