towerops/test/towerops_web/live/weathermap_live_test.exs
Graham McIntire cd19e6626c fix(tests): replace Process.sleep with event-driven sync patterns
Replaced unbounded Process.sleep calls across the test suite with
event-driven alternatives: :sys.get_state sync barriers, assert_receive
with bounded timeouts, and Process.send_after + assert_receive.

Largest improvements:
- storm_detector_test: 120-150ms sleeps removed, uses assert_receive
- deferred_discovery_test: 500ms -> 50ms (timeout test simulation)
- event_logger_test: polling loop replaced with :sys.get_state barrier
- tcp_executor_test: 2000ms sleep replaced with bounded recv timeout
- rate_limit_test: sleeps replaced with send_after + assert_receive
- Various 5-50ms sleeps removed from live_view tests
- Unused require Logger removed from 2 test files
2026-06-02 15:16:53 -05:00

62 lines
1.6 KiB
Elixir

defmodule ToweropsWeb.WeathermapLiveTest do
use ToweropsWeb.ConnCase, async: true
import Phoenix.LiveViewTest
setup :register_and_log_in_user
setup %{user: user} do
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Weathermap Org"}, user.id)
%{organization: organization}
end
describe "mount" do
test "renders weathermap page", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/weathermap")
assert html =~ "Weathermap"
end
end
describe "handle_event" do
test "set_filter does not crash", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/weathermap")
render_click(view, "set_filter", %{"filter" => "wired"})
assert render(view)
end
test "search does not crash", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/weathermap")
render_click(view, "search", %{"query" => "router"})
assert render(view)
end
test "toggle_layout does not crash", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/weathermap")
render_click(view, "toggle_layout", %{"mode" => "hierarchical"})
assert render(view)
end
test "close_detail_panel does not crash", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/weathermap")
render_click(view, "close_detail_panel", %{})
assert render(view)
end
end
describe "handle_info" do
test "refresh_data does not crash", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/weathermap")
send(view.pid, :refresh_data)
assert render(view)
end
end
end