Remember microprint state on reload
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user