Remember microprint state on reload

This commit is contained in:
Firehose Bot
2026-05-18 20:17:38 +01:00
parent 7afe5c1fe8
commit 790d2f0e1d
3 changed files with 167 additions and 31 deletions
@@ -139,4 +139,42 @@ defmodule FirehoseWeb.MicroprintsLiveTest do
"file B should show Collapse button when expanded"
end
end
describe "URL state persistence" do
test "expanded path is restored from query param on mount", %{conn: conn} do
files = MicroprintsLive.scan_source_files()
file_a = List.first(files)
{:ok, view, _html} = live(conn, ~p"/microprints?expanded=#{file_a}")
html = render(view)
assert html =~ "Collapse",
"Expanded file should show Collapse button when restored from URL param"
assert html =~ ~s(phx-value-path="#{file_a}")
end
test "unknown expanded path in URL is ignored gracefully", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/microprints?expanded=nonexistent.ex")
html = render(view)
refute html =~ "Collapse",
"Nonexistent expanded path should not show Collapse"
end
test "expand updates URL with expanded param", %{conn: conn} do
files = MicroprintsLive.scan_source_files()
file_a = List.first(files)
{:ok, view, _html} = live(conn, ~p"/microprints")
view
|> element("button[phx-value-path=\"#{file_a}\"]", "Expand")
|> render_click()
# URL should contain expanded param after clicking Expand
html = render(view)
assert html =~ "Collapse",
"File should remain expanded after push_patch updates URL"
end
end
end