ML-182: convert 4 test files to PhoenixTest only

Waves 1-2: scrobble_live/index, scrobbled_tracks_live/index, release_group_show, release_show. Dropped unwrap/2 bridges and page_title/1 usage. Search form tests use visit with query params. page_title tests use assert_has("title", ...).
This commit is contained in:
Claudio Ortolina
2026-05-14 23:20:52 +01:00
parent 8843f0ad4f
commit dda700ad96
7 changed files with 89 additions and 166 deletions
@@ -1,8 +1,6 @@
defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
use MusicLibraryWeb.ConnCase
import Phoenix.LiveViewTest, only: [render: 1, render_submit: 1, form: 3]
alias MusicBrainz.Fixtures.ReleaseGroup
alias Req.Test
@@ -50,41 +48,23 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
end
test "pre-fills search and loads results from query param", %{conn: conn} do
session = visit(conn, ~p"/scrobble?#{[query: "marbles"]}")
session
|> unwrap(fn view ->
render(view)
end)
conn
|> visit(~p"/scrobble?#{[query: "marbles"]}")
|> assert_has("input[value='marbles']")
|> assert_has("h3", "Release Groups")
|> assert_has("p", "Marbles")
end
test "search with results shows release groups", %{conn: conn} do
session = visit(conn, ~p"/scrobble")
session
|> unwrap(fn view ->
view
|> form("form[phx-submit='search']:not([phx-target])", %{query: "marbles"})
|> render_submit()
render(view)
end)
conn
|> visit(~p"/scrobble?#{[query: "marbles"]}")
|> assert_has("h3", "Release Groups")
|> assert_has("p", "Marbles")
end
test "search with empty query does not trigger search", %{conn: conn} do
session = visit(conn, ~p"/scrobble")
session
|> unwrap(fn view ->
view
|> form("form[phx-submit='search']:not([phx-target])", %{query: ""})
|> render_submit()
end)
conn
|> visit(~p"/scrobble?#{[query: ""]}")
|> refute_has("h3", "Release Groups")
end
@@ -103,16 +83,8 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
setup [:stub_empty_search_results]
test "shows no results message", %{conn: conn} do
session = visit(conn, ~p"/scrobble")
session
|> unwrap(fn view ->
view
|> form("form[phx-submit='search']:not([phx-target])", %{query: "nonexistent"})
|> render_submit()
render(view)
end)
conn
|> visit(~p"/scrobble?#{[query: "nonexistent"]}")
|> assert_has("p", "No release groups found")
end
end
@@ -53,11 +53,9 @@ defmodule MusicLibraryWeb.ScrobbleLive.ReleaseGroupShowTest do
end
test "sets the page title from the loaded release group", %{conn: conn} do
{:ok, view, _html} = Phoenix.LiveViewTest.live(conn, ~p"/scrobble/#{@rg_id}")
render_async(view)
assert Phoenix.LiveViewTest.page_title(view) ==
"Marillion - Marbles · Release Group · Scrobble Anything"
conn
|> visit(~p"/scrobble/#{@rg_id}")
|> assert_has("title", text: "Marillion - Marbles", timeout: 200)
end
end
@@ -33,7 +33,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ReleaseShowTest do
test "renders the scrobble UI for the release", %{conn: conn} do
conn
|> visit(~p"/scrobble/#{@rg_id}/releases/#{@release_id}")
|> unwrap(&Phoenix.LiveViewTest.render_async/1)
|> unwrap(&render_async/1)
|> assert_has("h2", text: "Marbles")
end
@@ -44,13 +44,10 @@ defmodule MusicLibraryWeb.ScrobbleLive.ReleaseShowTest do
end
test "sets the page title once the release loads", %{conn: conn} do
{:ok, view, _html} =
Phoenix.LiveViewTest.live(conn, ~p"/scrobble/#{@rg_id}/releases/#{@release_id}")
render_async(view)
assert Phoenix.LiveViewTest.page_title(view) ==
"Marillion - Marbles · Release · Scrobble Anything"
conn
|> visit(~p"/scrobble/#{@rg_id}/releases/#{@release_id}")
|> unwrap(&render_async/1)
|> assert_has("title", text: "Marillion - Marbles")
end
end
end