- Add contacts_inserted_at_desc_id_desc_idx so /contacts list runs as an Index Scan (~0.4ms) instead of a Seq Scan + top-N heapsort (~77ms on 58k rows) - Add Microwaveprop.Cache: tiny ETS-backed TTL cache for memoizing expensive-but-stale-tolerant values - Cache total_entries for unsearched /contacts page loads (30s TTL, invalidated on insert) - Cache the entire /contacts/map payload (pre-encoded JSON + band list), moving load_contacts into Radio.contact_map_payload; invalidated on new contact insert. Mount goes from ~150-300ms to ~5ms. - Fix /map overlay blinking on load: reuse the Leaflet GridLayer across renderScores calls and just redraw() against the updated ScoreGrid, instead of removeLayer + new layer which flashed between tile regens - Make mode optional on submission: schema change (null: true), submission_changeset no longer requires it, blank strings normalise to nil, CSV import accepts 6-column (no mode) or 7-column layouts - core_components .input adds a red asterisk to labels when required, giving users a visual cue for which fields must be filled on /submit
46 lines
1.4 KiB
Elixir
46 lines
1.4 KiB
Elixir
defmodule Microwaveprop.Radio.ContactTest do
|
|
use Microwaveprop.DataCase, async: true
|
|
|
|
alias Microwaveprop.Radio.Contact
|
|
|
|
@valid_attrs %{
|
|
station1: "W1AW",
|
|
station2: "K3LR",
|
|
qso_timestamp: ~U[2026-03-28 12:00:00Z],
|
|
grid1: "FN31pr",
|
|
grid2: "EN91jm",
|
|
pos1: %{lat: 41.714, lng: -72.727},
|
|
pos2: %{lat: 41.049, lng: -80.166},
|
|
mode: "SSB",
|
|
band: Decimal.new("144.2"),
|
|
distance_km: Decimal.new("623.4")
|
|
}
|
|
|
|
describe "changeset/2" do
|
|
test "valid attributes" do
|
|
changeset = Contact.changeset(%Contact{}, @valid_attrs)
|
|
assert changeset.valid?
|
|
end
|
|
|
|
test "requires station1, station2, qso_timestamp, and band (mode is optional)" do
|
|
changeset = Contact.changeset(%Contact{}, %{})
|
|
|
|
errors = errors_on(changeset)
|
|
assert errors.station1 == ["can't be blank"]
|
|
assert errors.station2 == ["can't be blank"]
|
|
assert errors.qso_timestamp == ["can't be blank"]
|
|
assert errors.band == ["can't be blank"]
|
|
refute Map.has_key?(errors, :mode)
|
|
end
|
|
|
|
test "persists to the database" do
|
|
changeset = Contact.changeset(%Contact{}, @valid_attrs)
|
|
assert {:ok, contact} = Repo.insert(changeset)
|
|
assert contact.station1 == "W1AW"
|
|
assert contact.station2 == "K3LR"
|
|
assert contact.mode == "SSB"
|
|
assert Decimal.equal?(contact.band, Decimal.new("144.2"))
|
|
assert Decimal.equal?(contact.distance_km, Decimal.new("623.4"))
|
|
end
|
|
end
|
|
end
|