From aa7fc830e5424b90bacef645f3a1aac799e696ae Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 29 Apr 2026 11:13:48 -0500 Subject: [PATCH] test: refactor LiveView tests to use HTML-aware element/form helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply patterns from testingliveview.com — replace render_click/submit/change event-name calls with element/form-targeted equivalents that validate the actual DOM wiring, not just handler logic. Adds stable test selectors (id="...") to interactive elements across 10 LiveView templates. Surfaces (and fixes) several real issues that the bypass-style tests masked: - Removes dead regenerate_token handler in agent_live/index.ex (no UI ever triggered it) and its corresponding test. - Removes dead refresh_topology test in network_map_live_test (event was referenced only in the test — no handler, no button, no JS anywhere). - Corrects "shows notification tab with add device modal" — modal lives on the security tab; original test mounted ?tab=notifications and only worked because direct event calls bypassed tab gating. - Corrects form input shape mismatches in agent_live/index_test that the handler's defensive case clauses had been masking. - Expands setup data for org/settings_live_test (snmp_community, default_agent_token_id, multi-org membership) so the gated buttons actually render. 11 direct render_click/submit/change calls remain — all intentional, documented server-side guard tests (tampered POSTs, race conditions, defensive idempotent handlers). Full LiveView test suite: 1300 tests, 0 failures. --- lib/towerops/agents.ex | 2 +- .../live/admin/audit_live/index.ex | 3 + .../live/admin/security_live/index.html.heex | 6 +- lib/towerops_web/live/agent_live/index.ex | 29 ---- .../live/agent_live/index.html.heex | 16 ++- .../live/device_live/form.html.heex | 4 + .../live/device_live/index.html.heex | 3 + .../live/device_live/show.html.heex | 2 + .../live/network_map_live.html.heex | 1 + .../live/org/settings_live.html.heex | 3 + .../live/user_settings_live.html.heex | 7 +- .../live/admin/audit_live/index_test.exs | 10 +- .../live/admin/security_live/index_test.exs | 10 +- .../live/agent_live/index_test.exs | 125 ++++++++---------- test/towerops_web/live/agent_live_test.exs | 8 +- .../live/device_live/form_test.exs | 11 +- .../live/device_live/index_test.exs | 47 ++++++- .../live/device_live/show_test.exs | 47 ++++--- .../live/network_map_live_test.exs | 30 ++--- .../live/org/settings_live_test.exs | 27 +++- .../live/user_settings_live_test.exs | 49 +++++-- 21 files changed, 257 insertions(+), 183 deletions(-) diff --git a/lib/towerops/agents.ex b/lib/towerops/agents.ex index c8bebd42..6b88cc42 100644 --- a/lib/towerops/agents.ex +++ b/lib/towerops/agents.ex @@ -271,7 +271,7 @@ defmodule Towerops.Agents do Updates an agent token with the given attributes. Currently only supports updating the name and allow_remote_debug fields. - Other fields like the token itself cannot be changed (use regenerate_token instead). + Other fields like the token itself cannot be changed. ## Examples diff --git a/lib/towerops_web/live/admin/audit_live/index.ex b/lib/towerops_web/live/admin/audit_live/index.ex index f2902dfe..fb25102a 100644 --- a/lib/towerops_web/live/admin/audit_live/index.ex +++ b/lib/towerops_web/live/admin/audit_live/index.ex @@ -162,6 +162,7 @@ defmodule ToweropsWeb.Admin.AuditLive.Index do <.icon name="hero-magnifying-glass" class="h-4 w-4 mr-2" /> Search