yak(behavior-tests-editorial-liveviews-microprints-editor-dashboard-llh3): behavior tests: editorial LiveViews (microprints, editor dashboard)
This commit is contained in:
@@ -3,6 +3,7 @@ alias FirehoseWeb.MicroprintsLive
|
||||
defmodule FirehoseWeb.MicroprintsLiveTest do
|
||||
use FirehoseWeb.ConnCase, async: true
|
||||
|
||||
import FirehoseWeb.MicroprintsCase
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
describe "scan_source_files/0" do
|
||||
@@ -81,18 +82,15 @@ defmodule FirehoseWeb.MicroprintsLiveTest do
|
||||
{:ok, view, _html} = live(conn, ~p"/microprints")
|
||||
|
||||
# Expand file A
|
||||
view
|
||||
|> element("button[phx-value-path=\"#{file_a}\"]", "Expand")
|
||||
|> render_click()
|
||||
expand_file(view, file_a)
|
||||
|
||||
# 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 by dispatching the highlight_line event
|
||||
# (microprint renders multiple rect segments per line, element() can't pick one)
|
||||
render_click(view, "highlight_line", %{"line" => "1", "path" => file_b})
|
||||
# Highlight a line in file B
|
||||
click_microprint_rect(view, file_b, 1)
|
||||
|
||||
# file A should be collapsed when highlighting a different file
|
||||
html = render(view)
|
||||
@@ -112,9 +110,7 @@ defmodule FirehoseWeb.MicroprintsLiveTest do
|
||||
{:ok, view, _html} = live(conn, ~p"/microprints")
|
||||
|
||||
# Expand file A
|
||||
view
|
||||
|> element("button[phx-value-path=\"#{file_a}\"]", "Expand")
|
||||
|> render_click()
|
||||
expand_file(view, file_a)
|
||||
|
||||
# Capture file A's source content from the rendered HTML
|
||||
html_a = render(view)
|
||||
@@ -123,9 +119,7 @@ defmodule FirehoseWeb.MicroprintsLiveTest do
|
||||
"File A source should be visible when expanded"
|
||||
|
||||
# Expand file B (should auto-collapse A)
|
||||
view
|
||||
|> element("button[phx-value-path=\"#{file_b}\"]", "Expand")
|
||||
|> render_click()
|
||||
expand_file(view, file_b)
|
||||
|
||||
# Capture file B's source content
|
||||
html_b = render(view)
|
||||
@@ -144,6 +138,34 @@ defmodule FirehoseWeb.MicroprintsLiveTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "collapsing an expanded file" do
|
||||
test "hides the source lines and brings the Expand control back", %{conn: conn} do
|
||||
# The URL route is used rather than clicking Expand: `restore_state_from_params/2`
|
||||
# validates the param against the scanned cards (Enum.find over @microprints),
|
||||
# so a real scanned path is required either way - see the "unknown expanded
|
||||
# path in URL is ignored" test for the other half of that contract.
|
||||
path = MicroprintsLive.scan_source_files() |> List.first()
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/microprints?expanded=#{path}")
|
||||
|
||||
assert has_element?(view, "#line-1"),
|
||||
"restored expansion should render the file's source lines"
|
||||
|
||||
assert has_element?(view, ~s(button[phx-value-path="#{path}"]), "Collapse")
|
||||
|
||||
collapse_file(view, path)
|
||||
|
||||
refute has_element?(view, "#line-1"),
|
||||
"collapsing should stop rendering the source viewer"
|
||||
|
||||
refute render(view) =~ "Collapse",
|
||||
"no card should still be expanded once the only expanded one is collapsed"
|
||||
|
||||
assert has_element?(view, ~s(button[phx-value-path="#{path}"]), "Expand"),
|
||||
"the card's control should be Expand again"
|
||||
end
|
||||
end
|
||||
|
||||
describe "app layout with menu" do
|
||||
test "renders the microprints page", %{conn: conn} do
|
||||
{:ok, _view, html} = live(conn, ~p"/microprints")
|
||||
@@ -190,9 +212,7 @@ defmodule FirehoseWeb.MicroprintsLiveTest do
|
||||
|
||||
{:ok, view, _html} = live(conn, ~p"/microprints")
|
||||
|
||||
view
|
||||
|> element("button[phx-value-path=\"#{file_a}\"]", "Expand")
|
||||
|> render_click()
|
||||
expand_file(view, file_a)
|
||||
|
||||
# URL should contain expanded param after clicking Expand
|
||||
html = render(view)
|
||||
|
||||
Reference in New Issue
Block a user