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:
@@ -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
|
||||
|
||||
@@ -2,12 +2,9 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|
||||
use MusicLibraryWeb.ConnCase
|
||||
|
||||
import MusicLibrary.ScrobbledTracksFixtures
|
||||
import Phoenix.LiveViewTest, only: [render_submit: 1, render_change: 1, form: 3]
|
||||
|
||||
alias MusicLibrary.ListeningStats
|
||||
|
||||
# Test data
|
||||
@invalid_track_attrs %{title: "", artist: %{name: ""}, album: %{title: ""}}
|
||||
@valid_track_attrs %{
|
||||
title: "Updated Track Title",
|
||||
artist: %{name: "Updated Artist", musicbrainz_id: "9a5cf59b-5da0-4021-b885-b6b78dd6886e"},
|
||||
@@ -51,14 +48,8 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|
||||
test "filters results by search query", %{conn: conn} do
|
||||
track_fixture(%{title: "Unique Track Title"})
|
||||
|
||||
session = visit(conn, ~p"/scrobbled-tracks")
|
||||
|
||||
session
|
||||
|> unwrap(fn view ->
|
||||
view
|
||||
|> form("form[phx-submit='search']:not([phx-target])", %{query: "Unique Track"})
|
||||
|> render_submit()
|
||||
end)
|
||||
conn
|
||||
|> visit(~p"/scrobbled-tracks?#{[query: "Unique Track"]}")
|
||||
|> assert_has("p", "Unique Track Title")
|
||||
end
|
||||
end
|
||||
@@ -73,14 +64,6 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|
||||
|> assert_has("h1", "Edit Scrobbled Track")
|
||||
|> assert_path(~p"/scrobbled-tracks/#{track.scrobbled_at_uts}/edit")
|
||||
|
||||
# Test validation errors with invalid attrs
|
||||
session
|
||||
|> unwrap(fn view ->
|
||||
view
|
||||
|> form("#track-form", track: @invalid_track_attrs)
|
||||
|> render_change()
|
||||
end)
|
||||
|
||||
# Submit valid changes
|
||||
session
|
||||
|> fill_in("Track Title", with: @valid_track_attrs.title)
|
||||
@@ -97,15 +80,9 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|
||||
test "shows validation errors", %{conn: conn, track: track} do
|
||||
conn
|
||||
|> visit(~p"/scrobbled-tracks/#{track.scrobbled_at_uts}/edit")
|
||||
|> unwrap(fn view ->
|
||||
html =
|
||||
view
|
||||
|> form("#track-form", track: @invalid_track_attrs)
|
||||
|> render_change()
|
||||
|
||||
assert html =~ "can't be blank"
|
||||
html
|
||||
end)
|
||||
|> fill_in("Track Title", with: "")
|
||||
|> click_button("Update Track")
|
||||
|> assert_has("[data-part='error']", "can't be blank")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user