fix(microprints): collapse expanded file when highlighting a different file

- Add test in microprints_live_test.exs that documents the uncoupled state bug
- Fix handle_event("highlight_line") to collapse expanded_path when
  highlighting a line in a different file
- All 159 tests pass
This commit is contained in:
Firehose Bot
2026-05-18 17:28:30 +01:00
parent eb97015dc0
commit 36bdc0610e
4 changed files with 74 additions and 2 deletions
@@ -105,10 +105,18 @@ defmodule FirehoseWeb.MicroprintsLive do
_ -> String.to_integer(line)
end
# Collapse any currently expanded file when highlighting a different file
expanded =
case socket.assigns.expanded_path do
^path -> socket.assigns.expanded_path
_ -> nil
end
{:noreply,
socket
|> assign(:highlighted_path, path)
|> assign(:highlighted_line, highlighted)}
|> assign(:highlighted_line, highlighted)
|> assign(:expanded_path, expanded)}
end
@impl true
@@ -1,5 +1,9 @@
alias FirehoseWeb.MicroprintsLive
defmodule FirehoseWeb.MicroprintsLiveTest do
use ExUnit.Case, async: true
use FirehoseWeb.ConnCase, async: true
import Phoenix.LiveViewTest
describe "scan_source_files/0" do
test "returns exactly 2 files" do
@@ -64,4 +68,36 @@ defmodule FirehoseWeb.MicroprintsLiveTest do
assert is_list(blogex_files)
end
end
describe "expanded_path and highlighted_path coupling" do
test "expanding file A and highlighting a line in file B should collapse file A", %{conn: conn} do
files = MicroprintsLive.scan_source_files()
assert length(files) >= 2, "Need at least 2 files to test coupling"
[file_a, file_b | _] = files
{:ok, view, _html} = live(conn, ~p"/microprints")
# Expand file A
view
|> element("button[phx-value-path=\"#{file_a}\"]", "Expand")
|> render_click()
# Verify file A shows "Collapse" button (it's expanded)
html = render(view)
assert html =~ ~s(phx-value-path="#{file_a}")
assert html =~ "Collapse"
# Highlight a line in file B (rect elements inside SVG)
view
|> element("svg rect[phx-value-line=\"1\"][phx-value-path=\"#{file_b}\"]")
|> render_click()
# BUG: file A should be collapsed when highlighting a different file
# Currently file A stays expanded while the highlight is on file B
html = render(view)
refute html =~ "Collapse",
"file A should be collapsed after highlighting a different file, but the Collapse button is still visible (expanded_path is uncoupled from highlighted_path)"
end
end
end