Extend testing of artist page

This commit is contained in:
Claudio Ortolina
2024-12-13 14:13:45 +03:00
parent ed86ef7b5a
commit f7045a9f14
3 changed files with 79 additions and 8 deletions
@@ -62,6 +62,7 @@
</h2>
<%!-- TODO: replace with OSS version --%>
<ul
id="collection"
role="list"
class="mt-4 grid grid-cols-2 gap-x-4 gap-y-8 sm:grid-cols-3 sm:gap-x-6 lg:grid-cols-4 xl:gap-x-8"
>
@@ -101,6 +102,7 @@
</h2>
<%!-- TODO: replace with OSS version --%>
<ul
id="wishlist"
role="list"
class="mt-4 grid grid-cols-2 gap-x-4 gap-y-8 sm:grid-cols-3 sm:gap-x-6 lg:grid-cols-4 xl:gap-x-8"
>
+3 -3
View File
@@ -326,7 +326,7 @@ msgid "Welcome to your Music Library"
msgstr ""
#: lib/music_library_web/components/layouts/app.html.heex:20
#: lib/music_library_web/live/artist_live/show.html.heex:100
#: lib/music_library_web/live/artist_live/show.html.heex:101
#: lib/music_library_web/live/wishlist_live/index.ex:76
#: lib/music_library_web/live/wishlist_live/show.ex:138
#, elixir-autogen, elixir-format
@@ -453,8 +453,8 @@ msgstr ""
msgid "Dev dashboard"
msgstr ""
#: lib/music_library_web/live/artist_live/show.html.heex:80
#: lib/music_library_web/live/artist_live/show.html.heex:119
#: lib/music_library_web/live/artist_live/show.html.heex:81
#: lib/music_library_web/live/artist_live/show.html.heex:121
#, elixir-autogen, elixir-format
msgid "View details"
msgstr ""
@@ -10,16 +10,19 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
setup :verify_on_exit!
defp escape(string) do
string
|> Phoenix.HTML.html_escape()
|> Phoenix.HTML.safe_to_string()
end
describe "Show artist" do
test "it shows records from the collection", %{conn: conn} do
test "it shows the artist bio and play count", %{conn: conn} do
current_time = DateTime.utc_now()
collection_record =
record_fixture_with_artist("Steven Wilson", %{purchased_at: current_time})
_wishlist_record = record_fixture_with_artist("Steven Wilson", %{purchased_at: nil})
_other_record = record_fixture_with_artist("Porcupine Tree", %{purchased_at: current_time})
[artist] = collection_record.artists
artist_musicbrainz_id = artist.musicbrainz_id
@@ -33,7 +36,73 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
{:ok, show_live, _html} = live(conn, ~p"/artists/#{artist_musicbrainz_id}")
assert render_async(show_live) =~ "Steven Wilson"
render_async(show_live)
# play count
assert has_element?(show_live, "span", "123")
assert has_element?(show_live, "summary", "Biography")
assert element(show_live, "details")
end
test "it gracefully handles errors in fetching bio and play count", %{conn: conn} do
current_time = DateTime.utc_now()
collection_record =
record_fixture_with_artist("Steven Wilson", %{purchased_at: current_time})
[artist] = collection_record.artists
artist_musicbrainz_id = artist.musicbrainz_id
expect(APIBehaviourMock, :get_artist_info, fn {:musicbrainz_id, ^artist_musicbrainz_id},
_config ->
{:error, :timeout}
end)
{:ok, show_live, _html} = live(conn, ~p"/artists/#{artist_musicbrainz_id}")
render_async(show_live)
# play count
refute has_element?(show_live, "span", "123")
assert has_element?(show_live, "div", "There was an error loading the play count")
refute has_element?(show_live, "summary", "Biography")
assert has_element?(show_live, "div", "There was an error loading the biography")
end
test "it shows records from the collection and the wishlist", %{conn: conn} do
current_time = DateTime.utc_now()
collection_record =
record_fixture_with_artist("Steven Wilson", %{
title: "The Raven that refused to sing",
purchased_at: current_time
})
wishlist_record =
record_fixture_with_artist("Steven Wilson", %{
title: "Grace for drowning",
purchased_at: nil
})
other_record = record_fixture_with_artist("Porcupine Tree", %{purchased_at: current_time})
[artist] = collection_record.artists
artist_musicbrainz_id = artist.musicbrainz_id
{:ok, show_live, _html} = live(conn, ~p"/artists/#{artist_musicbrainz_id}")
# collection records
assert has_element?(show_live, "#collection p", escape(collection_record.title))
# wishlist records
assert has_element?(show_live, "#wishlist p", escape(wishlist_record.title))
# other records
refute has_element?(show_live, "#collection p", escape(other_record.title))
refute has_element?(show_live, "#wishlist p", escape(other_record.title))
end
end
end