diff --git a/lib/music_brainz/release.ex b/lib/music_brainz/release.ex
index 27684c38..48f4c1c9 100644
--- a/lib/music_brainz/release.ex
+++ b/lib/music_brainz/release.ex
@@ -37,10 +37,10 @@ defmodule MusicBrainz.Release do
%__MODULE__{
id: r["id"],
title: r["title"],
- artists: parse_artists(r["artist-credit"]),
+ artists: parse_artists(r["artist-credit"] || []),
date: r["date"],
barcode: r["barcode"],
- media: parse_media(r["media"])
+ media: parse_media(r["media"] || [])
}
end
diff --git a/lib/music_library_web/components/release_component.ex b/lib/music_library_web/components/release_component.ex
index ca2657bc..0b7ae6a0 100644
--- a/lib/music_library_web/components/release_component.ex
+++ b/lib/music_library_web/components/release_component.ex
@@ -15,8 +15,19 @@ defmodule MusicLibraryWeb.ReleaseComponent do
def mount(socket) do
{:ok,
socket
- |> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())
- |> assign(:release_with_tracks, nil)}
+ |> assign(:can_scrobble?, ScrobbleActivity.can_scrobble?())}
+ end
+
+ @impl true
+ def update(%{record: record} = assigns, socket) do
+ {:ok,
+ socket
+ |> assign(assigns)
+ |> assign_async(:release_with_tracks, fn ->
+ with {:ok, release} <- MusicBrainz.get_release(record.selected_release_id) do
+ {:ok, %{release_with_tracks: MusicBrainz.Release.from_api_response(release)}}
+ end
+ end)}
end
@impl true
@@ -27,7 +38,6 @@ defmodule MusicLibraryWeb.ReleaseComponent do
:if={@record.selected_release_id}
id={@sheet_id}
placement="right"
- on_open={JS.push("load_release_with_tracks", target: @myself)}
>
{gettext("Tracks")}
@@ -126,18 +136,6 @@ defmodule MusicLibraryWeb.ReleaseComponent do
end
@impl true
- def handle_event("load_release_with_tracks", _params, socket) do
- selected_release_id = socket.assigns.record.selected_release_id
-
- {:noreply,
- socket
- |> assign_async(:release_with_tracks, fn ->
- with {:ok, release} <- MusicBrainz.get_release(selected_release_id) do
- {:ok, %{release_with_tracks: MusicBrainz.Release.from_api_response(release)}}
- end
- end)}
- end
-
def handle_event("scrobble_release", _params, socket) do
release_with_tracks_async_result =
socket.assigns.release_with_tracks
diff --git a/test/music_library_web/live/collection_live/show_test.exs b/test/music_library_web/live/collection_live/show_test.exs
index 9cc3f353..910456bc 100644
--- a/test/music_library_web/live/collection_live/show_test.exs
+++ b/test/music_library_web/live/collection_live/show_test.exs
@@ -13,12 +13,15 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
test "can navigate to the record edit form", %{conn: conn} do
record = record()
+ release_response = Fixtures.Release.release(:marbles)
+
Req.Test.stub(MusicBrainz.API, fn conn ->
- Req.Test.json(conn, Fixtures.Release.release(:marbles))
+ Req.Test.json(conn, release_response)
end)
conn
|> visit(~p"/collection/#{record.id}")
+ |> unwrap(&render_async/1)
|> assert_has("a", text: "Edit")
|> click_link("Edit")
|> assert_path(~p"/collection/#{record}/show/edit")
@@ -30,13 +33,16 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
record = record()
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
+ release_response = Fixtures.Release.release(:marbles)
+
Req.Test.stub(MusicBrainz.API, fn conn ->
- Req.Test.json(conn, Fixtures.Release.release(:marbles))
+ Req.Test.json(conn, release_response)
end)
session =
conn
|> visit(~p"/collection/#{record.id}")
+ |> unwrap(&render_async/1)
|> assert_has("h2", text: escape(record.title))
|> assert_has("p", text: record.release_date)
|> assert_has("p", text: format_label(record.format))
@@ -60,7 +66,6 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
end
describe "Side panel" do
- @tag :skip
test "shows a record's tracks", %{conn: conn} do
record = record()
@@ -74,14 +79,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
conn
|> visit(~p"/collection/#{record.id}")
|> assert_has("button", text: "Show Tracks")
- |> unwrap(fn view ->
- # we can't directly click the "Show Tracks" button as
- # its phx-click event uses a JS command. Bit of a hack, but we can simulate
- # the click by pretending we're dealing with a JS hook, and trigger the event
- # that is sent by the JS command.
- view
- |> Phoenix.LiveViewTest.render_hook(:load_release_with_tracks, %{})
- end)
+ |> unwrap(&render_async/1)
|> assert_has("a", text: "Connect your Last.fm account")
release =