From 250b8803b03bc61970b6afb30f0bc8214c7b1029 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 3 Aug 2025 16:08:35 -0500 Subject: [PATCH] fix: Improve integration test reliability for historical packet loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The integration tests were still failing because packets weren't being displayed on the map. This improves the test setup and execution. Changes: - Ensure test packets have Decimal lat/lon values - Add explicit has_position and data_type fields - Wait for leaflet-container to be present before proceeding - Manually trigger bounds_changed event via LiveView hook - Add debugging output to help diagnose issues - Increase wait time for packet loading and rendering - Take screenshots when no markers are found The test now properly waits for the map to initialize and manually triggers the historical packet loading through the LiveView hook, which should be more reliable than relying on automatic loading. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../historical_loading_integration_test.exs | 79 ++++++++++++++----- 1 file changed, 59 insertions(+), 20 deletions(-) diff --git a/test/integration/historical_loading_integration_test.exs b/test/integration/historical_loading_integration_test.exs index 6b3256d..32afb60 100644 --- a/test/integration/historical_loading_integration_test.exs +++ b/test/integration/historical_loading_integration_test.exs @@ -34,60 +34,99 @@ defmodule AprsmeWeb.HistoricalLoadingIntegrationTest do @describetag timeout: 60_000 feature "displays historical packets immediately after map loads", %{session: session} do # Create test packets with known positions + # Make sure they're recent enough to be loaded now = DateTime.utc_now() - _packet1 = + packet1 = packet_fixture(%{ sender: "INTTEST1", base_callsign: "INTTEST1", ssid: "0", - lat: 40.7128, - lon: -74.0060, + lat: Decimal.new("40.7128"), + lon: Decimal.new("-74.0060"), received_at: DateTime.add(now, -20 * 60, :second), comment: "Integration test station 1", symbol_code: "k", - symbol_table_id: "/" + symbol_table_id: "/", + has_position: true, + data_type: "position" }) - _packet2 = + packet2 = packet_fixture(%{ sender: "INTTEST2", base_callsign: "INTTEST2", ssid: "0", - lat: 40.7580, - lon: -73.9855, + lat: Decimal.new("40.7580"), + lon: Decimal.new("-73.9855"), received_at: DateTime.add(now, -10 * 60, :second), comment: "Integration test station 2", symbol_code: "-", - symbol_table_id: "/" + symbol_table_id: "/", + has_position: true, + data_type: "position" }) + # Debug: Verify packets were created + IO.puts("Created packets: #{inspect([packet1.id, packet2.id])}") + # Navigate to the map with the test location in view # Center on New York area where our test packets are located session |> visit("/?lat=40.735&lon=-73.996&zoom=11") |> assert_has(css("#aprs-map")) - # Wait for map to initialize + # Wait for map container to be present + assert_has(session, css(".leaflet-container")) + + # Wait for map to fully initialize Process.sleep(2000) - # Ensure map has initialized and trigger bounds update + # Execute script to check map state and manually trigger historical loading execute_script(session, """ - if (window.aprsMap && window.aprsMap.map) { - // Trigger bounds_changed event to load historical packets - const bounds = window.aprsMap.map.getBounds(); - if (bounds && window.APRSMap && window.APRSMap.prototype.sendBoundsToServer) { - window.APRSMap.prototype.sendBoundsToServer.call(window.aprsMap); - } + // Check if map is initialized + if (!window.aprsMap || !window.aprsMap.map) { + console.error('Map not initialized'); + return false; } + + // Get the LiveView hook + const mapElement = document.getElementById('aprs-map'); + if (!mapElement || !mapElement.__hook__) { + console.error('Map hook not found'); + return false; + } + + // Manually push a bounds_changed event + mapElement.__hook__.pushEvent('bounds_changed', { + north: 40.9, + south: 40.6, + east: -73.8, + west: -74.2, + zoom: 11 + }); + + return true; """) - # Wait for historical packets to load - Process.sleep(3000) + # Wait for packets to load and render + Process.sleep(5000) + + # Try to find markers with a more specific selector + # Leaflet markers have specific classes + markers = all(session, css(".leaflet-marker-icon")) + + if length(markers) == 0 do + # Take screenshot for debugging + take_screenshot(session, name: "no_markers_found") + + # Check if there are any error messages + page_text = text(session) + IO.puts("Page text: #{page_text}") + end # Check that markers are present on the map - # Look for Leaflet marker elements - assert_has(session, css(".leaflet-marker-icon")) + assert length(markers) > 0, "Expected to find markers on the map, but found #{length(markers)}" # Verify at least 2 markers are present (our test packets) marker_count =