- Add 17 missing @spec annotations (layouts, error_json, error_html, skewt_svg) - Move 12+ nested alias/import/require to module top level - Add phx-change/id attributes to 11 raw HTML <form> tags - Remove 4 unused LiveView assigns (:bounds, :data_provider) - Add 3 missing doctest references (HrrrNativeClient, BulkFetch, Accounts) - Break 2 long lines (path_compute.ex:382) - Strengthen weak test assertions (is_binary→byte_size, is_list→!=[]) - Replace Module.concat with Module.safe_concat (2 occurrences) - Replace length/1 > 0 with list != [] (9 occurrences) - Remove no-op assert true, fix no-assertion tests Remaining: 24 socket.assigns introspection warnings (deliberate test pattern for observable behavior testing), 1 formatter-resistant long line, 3 app-code usage warnings.
64 lines
2 KiB
Elixir
64 lines
2 KiB
Elixir
defmodule Microwaveprop.Buildings.LoaderTest do
|
|
use ExUnit.Case, async: false
|
|
|
|
alias Microwaveprop.Buildings.Index
|
|
alias Microwaveprop.Buildings.Loader
|
|
|
|
setup do
|
|
Index.clear()
|
|
|
|
tmp = Path.join(System.tmp_dir!(), "buildings_cache_#{System.unique_integer([:positive])}")
|
|
prev = Application.get_env(:microwaveprop, :buildings_cache_dir)
|
|
Application.put_env(:microwaveprop, :buildings_cache_dir, tmp)
|
|
|
|
on_exit(fn ->
|
|
File.rm_rf(tmp)
|
|
|
|
if prev,
|
|
do: Application.put_env(:microwaveprop, :buildings_cache_dir, prev),
|
|
else: Application.delete_env(:microwaveprop, :buildings_cache_dir)
|
|
end)
|
|
|
|
:ok
|
|
end
|
|
|
|
describe "ensure_loaded/1" do
|
|
test "skips loading when quadkey is already loaded" do
|
|
Index.mark_loaded("023112330")
|
|
assert Loader.ensure_loaded("023112330") == :ok
|
|
end
|
|
|
|
test "marks quadkey as loaded when tile file doesn't exist" do
|
|
assert Loader.ensure_loaded("nonexistent_quadkey") == :ok
|
|
assert Index.loaded?("nonexistent_quadkey")
|
|
end
|
|
|
|
test "loads records from a real tile file" do
|
|
quadkey = "023112330"
|
|
cache_dir = Application.get_env(:microwaveprop, :buildings_cache_dir)
|
|
File.mkdir_p!(cache_dir)
|
|
|
|
geojsonl =
|
|
then(
|
|
~s|{"type": "Feature", "properties": {"height": 5.5}, "geometry": {"type": "Polygon", "coordinates": [[[-97.736, 32.221], [-97.736, 32.222], [-97.735, 32.222], [-97.735, 32.221], [-97.736, 32.221]]]}}|,
|
|
&:zlib.gzip/1
|
|
)
|
|
|
|
File.write!(Path.join(cache_dir, "#{quadkey}.csv.gz"), geojsonl)
|
|
|
|
assert Loader.ensure_loaded(quadkey) == :ok
|
|
assert Index.loaded?(quadkey)
|
|
assert Index.max_height_near(32.2215, -97.7355, 100) == 5.5
|
|
end
|
|
end
|
|
|
|
describe "ensure_loaded_for_bbox/1" do
|
|
test "returns list of quadkeys for the bbox" do
|
|
bbox = %{"south" => 32.5, "north" => 33.0, "west" => -97.5, "east" => -96.5}
|
|
keys = Loader.ensure_loaded_for_bbox(bbox)
|
|
|
|
assert keys != []
|
|
assert Enum.all?(keys, &is_binary/1)
|
|
end
|
|
end
|
|
end
|