diff --git a/backlog/tasks/ml-182.4 - Wave-4-Convert-mixed-usage-files-artist_live-show-stats_live-top_albums.md b/backlog/tasks/ml-182.4 - Wave-4-Convert-mixed-usage-files-artist_live-show-stats_live-top_albums.md index 0ec0d6cc..06628ab2 100644 --- a/backlog/tasks/ml-182.4 - Wave-4-Convert-mixed-usage-files-artist_live-show-stats_live-top_albums.md +++ b/backlog/tasks/ml-182.4 - Wave-4-Convert-mixed-usage-files-artist_live-show-stats_live-top_albums.md @@ -1,9 +1,10 @@ --- id: ML-182.4 title: "Wave 4: Convert mixed-usage files (artist_live/show, stats_live/top_albums)" -status: To Do +status: Done assignee: [] created_date: "2026-05-14 22:14" +updated_date: "2026-05-16 15:30" labels: - testing - refactoring diff --git a/test/music_library_web/live/artist_live/show_test.exs b/test/music_library_web/live/artist_live/show_test.exs index 0a2e2684..fe06e9d4 100644 --- a/test/music_library_web/live/artist_live/show_test.exs +++ b/test/music_library_web/live/artist_live/show_test.exs @@ -2,6 +2,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do use MusicLibraryWeb.ConnCase import MusicLibrary.Fixtures.Records + import Phoenix.LiveViewTest alias LastFm.Fixtures @@ -181,14 +182,14 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do Test.json(conn, BraveSearch.Fixtures.search_images_response()) end) - {:ok, view, _html} = live(conn, ~p"/artists/#{musicbrainz_id}/edit") - - view - |> element("#image-search-button") - |> render_click() - - html = render_async(view) + session = + conn + |> visit(~p"/artists/#{musicbrainz_id}/edit") + |> unwrap(&render_async/1) + |> click_button("#image-search-button", "Search") + |> unwrap(&render_async/1) + html = Phoenix.LiveViewTest.render(session.view) assert html =~ "https://thumbnails.example.com/raven-thumb.jpg" end @@ -201,14 +202,14 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do Test.transport_error(conn, :timeout) end) - {:ok, view, _html} = live(conn, ~p"/artists/#{musicbrainz_id}/edit") - - view - |> element("#image-search-button") - |> render_click() - - html = render_async(view) + session = + conn + |> visit(~p"/artists/#{musicbrainz_id}/edit") + |> unwrap(&render_async/1) + |> click_button("#image-search-button", "Search") + |> unwrap(&render_async/1) + html = Phoenix.LiveViewTest.render(session.view) assert html =~ "Search failed" end @@ -217,18 +218,21 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do artist_musicbrainz_id: musicbrainz_id, artist_info: artist_info } do - {:ok, view, _html} = live(conn, ~p"/artists/#{musicbrainz_id}/edit") + conn + |> visit(~p"/artists/#{musicbrainz_id}/edit") + |> unwrap(&render_async/1) + |> unwrap(fn view -> + image = + file_input(view, "#artist-info-form", :image_data, [ + %{name: "raven.jpg", content: raven_cover_data(), type: "image/jpeg"} + ]) - image = - file_input(view, "#artist-info-form", :image_data, [ - %{name: "raven.jpg", content: raven_cover_data(), type: "image/jpeg"} - ]) + render_upload(image, "raven.jpg") - render_upload(image, "raven.jpg") - - view - |> form("#artist-info-form") - |> render_submit() + view + |> form("#artist-info-form") + |> render_submit() + end) updated = Artists.get_artist_info!(artist_info.id) assert updated.image_data_hash != artist_info.image_data_hash @@ -254,18 +258,19 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do end end) - {:ok, view, _html} = live(conn, ~p"/artists/#{musicbrainz_id}/edit") - - view |> element("#image-search-button") |> render_click() - render_async(view, 300) - - view - |> element( - "button[phx-click='select_image'][phx-value-url='https://images.example.com/raven-cover.jpg']" - ) - |> render_click() - - render_async(view, 300) + conn + |> visit(~p"/artists/#{musicbrainz_id}/edit") + |> unwrap(&render_async/1) + |> click_button("#image-search-button", "Search") + |> unwrap(&render_async/1) + |> unwrap(fn view -> + view + |> element( + "button[phx-click='select_image'][phx-value-url='https://images.example.com/raven-cover.jpg']" + ) + |> render_click() + end) + |> unwrap(&render_async/1) updated = Artists.get_artist_info!(artist_info.id) assert updated.image_data_hash != artist_info.image_data_hash diff --git a/test/music_library_web/live/stats_live/top_albums_test.exs b/test/music_library_web/live/stats_live/top_albums_test.exs index da29209c..da8b7e5c 100644 --- a/test/music_library_web/live/stats_live/top_albums_test.exs +++ b/test/music_library_web/live/stats_live/top_albums_test.exs @@ -3,7 +3,6 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do import MusicLibrary.Fixtures.Records import MusicLibrary.ScrobbledTracksFixtures - import Phoenix.LiveViewTest # Any release_id from the marbles release-group fixture. Records created by # `record/0` include `musicbrainz_data: ReleaseGroup.release_group(:marbles)`, @@ -74,8 +73,12 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do %{conn: conn} do _record = record(%{purchased_at: DateTime.utc_now()}) - {:ok, view, _html} = live(conn, ~p"/") - html = render_async(view) + session = + conn + |> visit("/") + |> unwrap(&render_async/1) + + html = Phoenix.LiveViewTest.render(session.view) assert html =~ ~r|]+src="/assets/[^"]+"[^>]+alt="Marbles"| refute html =~ ~s|src="https://example.com/cover.jpg"| @@ -88,8 +91,12 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do test "single collected record: success badge and navigation to collection show", %{conn: conn} do collected = record(%{purchased_at: DateTime.utc_now()}) - {:ok, view, _html} = live(conn, ~p"/") - html = render_async(view) + session = + conn + |> visit("/") + |> unwrap(&render_async/1) + + html = Phoenix.LiveViewTest.render(session.view) # The whole row is clickable, navigating to the collection show route. assert html =~ ~s|/collection/#{collected.id}| @@ -103,8 +110,12 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do %{conn: conn} do wishlisted = record(%{purchased_at: nil}) - {:ok, view, _html} = live(conn, ~p"/") - html = render_async(view) + session = + conn + |> visit("/") + |> unwrap(&render_async/1) + + html = Phoenix.LiveViewTest.render(session.view) assert html =~ ~s|/wishlist/#{wishlisted.id}| assert html =~ "cursor-pointer" @@ -145,7 +156,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do |> refute_has("#top-albums div.cursor-pointer") end - test "no matching record: renders a plain badge and row is not navigable", %{conn: _conn} do + test "no matching record: renders a plain badge and row is not navigable", %{conn: conn} do # Replace the Marbles scrobbles with an orphan album that has no record. # The base setup created Marbles scrobbles — add one that will outrank # them in play_count so it appears first. @@ -162,8 +173,12 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do }) end - {:ok, view, _html} = live(build_conn() |> init_test_session(%{logged_in: true}), ~p"/") - html = render_async(view) + session = + conn + |> visit("/") + |> unwrap(&render_async/1) + + html = Phoenix.LiveViewTest.render(session.view) assert html =~ "Orphan Album" # Plain badge is primary/surface — no success/warning color classes on