Convert phoenix_test assertions to simplified syntax

This commit is contained in:
Claudio Ortolina
2026-03-06 06:41:06 +00:00
parent 348d062822
commit c3cb510892
13 changed files with 153 additions and 153 deletions
@@ -43,8 +43,8 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
conn conn
|> visit(~p"/artists/#{artist_musicbrainz_id}") |> visit(~p"/artists/#{artist_musicbrainz_id}")
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> assert_has("span", text: "123") |> assert_has("span", "123")
|> assert_has("dt", text: "Biography") |> assert_has("dt", "Biography")
end end
test "it gracefully handles errors in fetching bio and play count", %{ test "it gracefully handles errors in fetching bio and play count", %{
@@ -64,10 +64,10 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
conn conn
|> visit(~p"/artists/#{artist_musicbrainz_id}") |> visit(~p"/artists/#{artist_musicbrainz_id}")
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> refute_has("span", text: "123") |> refute_has("span", "123")
|> refute_has("summary", text: "Biography") |> refute_has("summary", "Biography")
|> assert_has("div", text: "Error loading play count") |> assert_has("div", "Error loading play count")
|> assert_has("div", text: "Error loading biography") |> assert_has("div", "Error loading biography")
end end
test "it shows the artist country and MB id", %{ test "it shows the artist country and MB id", %{
@@ -87,9 +87,9 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
conn conn
|> visit(~p"/artists/#{artist_musicbrainz_id}") |> visit(~p"/artists/#{artist_musicbrainz_id}")
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> assert_has("span", text: "United Kingdom") |> assert_has("span", "United Kingdom")
|> assert_has("span", text: "🇬🇧") |> assert_has("span", "🇬🇧")
|> assert_has("code", text: artist_musicbrainz_id) |> assert_has("code", artist_musicbrainz_id)
end end
test "it shows records from the collection and the wishlist", %{ test "it shows records from the collection and the wishlist", %{
@@ -119,10 +119,10 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
conn conn
|> visit(~p"/artists/#{artist_musicbrainz_id}") |> visit(~p"/artists/#{artist_musicbrainz_id}")
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> assert_has("#collection p", text: escape(collection_record.title)) |> assert_has("#collection p", escape(collection_record.title))
|> assert_has("#wishlist p", text: escape(wishlist_record.title)) |> assert_has("#wishlist p", escape(wishlist_record.title))
|> refute_has("#collection p", text: escape(other_collection_record.title)) |> refute_has("#collection p", escape(other_collection_record.title))
|> refute_has("#wishlist p", text: escape(other_collection_record.title)) |> refute_has("#wishlist p", escape(other_collection_record.title))
end end
end end
end end
@@ -59,17 +59,17 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
session session
|> assert_has("#records-#{record.id}") |> assert_has("#records-#{record.id}")
|> assert_has("#records-#{record.id} h2", text: escape(record.title)) |> assert_has("#records-#{record.id} h2", escape(record.title))
|> assert_has("#records-#{record.id} p", text: record.release_date) |> assert_has("#records-#{record.id} p", record.release_date)
|> assert_has("#records-#{record.id} p", text: format_label(record.format)) |> assert_has("#records-#{record.id} p", format_label(record.format))
|> assert_has("#records-#{record.id} p", text: type_label(record.type)) |> assert_has("#records-#{record.id} p", type_label(record.type))
|> assert_has("#records-#{record.id} span", |> assert_has("#records-#{record.id} span",
text: Record.format_as_date(record.purchased_at) text: Record.format_as_date(record.purchased_at)
) )
|> assert_has("img[src='#{cover_url}']") |> assert_has("img[src='#{cover_url}']")
for artist <- record.artists do for artist <- record.artists do
assert_has(session, "#records-#{record.id} a", text: escape(artist.name)) assert_has(session, "#records-#{record.id} a", escape(artist.name))
end end
end end
@@ -106,9 +106,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
end end
page_2_session page_2_session
|> assert_has("#bottom_pagination a", text: "1") |> assert_has("#bottom_pagination a", "1")
|> refute_has("#bottom_pagination a", text: "2") |> refute_has("#bottom_pagination a", "2")
|> assert_has("#bottom_pagination a", text: "3") |> assert_has("#bottom_pagination a", "3")
{page_3_records, rest_of_records} = Enum.split(rest_of_records, page_size) {page_3_records, rest_of_records} = Enum.split(rest_of_records, page_size)
@@ -128,9 +128,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
end end
page_3_session page_3_session
|> assert_has("#bottom_pagination a", text: "1") |> assert_has("#bottom_pagination a", "1")
|> assert_has("#bottom_pagination a", text: "2") |> assert_has("#bottom_pagination a", "2")
|> refute_has("#bottom_pagination a", text: "3") |> refute_has("#bottom_pagination a", "3")
end end
end end
@@ -150,17 +150,17 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
session session
|> assert_has("#records-#{record.id}") |> assert_has("#records-#{record.id}")
|> assert_has("#records-#{record.id} h2", text: escape(record.title)) |> assert_has("#records-#{record.id} h2", escape(record.title))
|> assert_has("#records-#{record.id} p", text: record.release_date) |> assert_has("#records-#{record.id} p", record.release_date)
|> assert_has("#records-#{record.id} p", text: format_label(record.format)) |> assert_has("#records-#{record.id} p", format_label(record.format))
|> assert_has("#records-#{record.id} p", text: type_label(record.type)) |> assert_has("#records-#{record.id} p", type_label(record.type))
|> assert_has("#records-#{record.id} span", |> assert_has("#records-#{record.id} span",
text: Record.format_as_date(record.purchased_at) text: Record.format_as_date(record.purchased_at)
) )
|> assert_has("img[src='#{cover_url}']") |> assert_has("img[src='#{cover_url}']")
for artist <- record.artists do for artist <- record.artists do
assert_has(session, "#records-#{record.id} a", text: escape(artist.name)) assert_has(session, "#records-#{record.id} a", escape(artist.name))
end end
end end
@@ -194,17 +194,17 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
session session
|> assert_has("#records-#{record.id}") |> assert_has("#records-#{record.id}")
|> assert_has("#records-#{record.id} h2", text: escape(record.title)) |> assert_has("#records-#{record.id} h2", escape(record.title))
|> assert_has("#records-#{record.id} p", text: record.release_date) |> assert_has("#records-#{record.id} p", record.release_date)
|> assert_has("#records-#{record.id} p", text: format_label(record.format)) |> assert_has("#records-#{record.id} p", format_label(record.format))
|> assert_has("#records-#{record.id} p", text: type_label(record.type)) |> assert_has("#records-#{record.id} p", type_label(record.type))
|> assert_has("#records-#{record.id} span", |> assert_has("#records-#{record.id} span",
text: Record.format_as_date(record.purchased_at) text: Record.format_as_date(record.purchased_at)
) )
|> assert_has("img[src='#{cover_url}']") |> assert_has("img[src='#{cover_url}']")
for artist <- record.artists do for artist <- record.artists do
assert_has(session, "#records-#{record.id} a", text: escape(artist.name)) assert_has(session, "#records-#{record.id} a", escape(artist.name))
end end
end end
@@ -221,7 +221,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
conn conn
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_link("#records-#{record.id} a", "Edit") |> click_link("#records-#{record.id} a", "Edit")
|> assert_has("h2", text: escape(record.title)) |> assert_has("h2", escape(record.title))
|> assert_path(~p"/collection/#{record}/edit") |> assert_path(~p"/collection/#{record}/edit")
end end
@@ -238,7 +238,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
session session
|> upload("Cover art", raven_cover_fixture()) |> upload("Cover art", raven_cover_fixture())
|> click_button("Save") |> click_button("Save")
|> assert_has("p", text: "Record updated successfully") |> assert_has("p", "Record updated successfully")
updated_record = MusicLibrary.Records.get_record!(record.id) updated_record = MusicLibrary.Records.get_record!(record.id)
updated_cover_url = cover_url(updated_record, 460) updated_cover_url = cover_url(updated_record, 460)
@@ -253,8 +253,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
conn conn
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_link("Add") |> click_link("Add")
|> assert_has("label", text: "Search for a record") |> assert_has("label", "Search for a record")
|> assert_has("div", text: "No results") |> assert_has("div", "No results")
|> assert_path(~p"/collection/import") |> assert_path(~p"/collection/import")
end end
@@ -294,9 +294,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
result = ReleaseGroupSearchResult.from_api_response(release_group_search_result) result = ReleaseGroupSearchResult.from_api_response(release_group_search_result)
session session
|> assert_has("h1", text: result.artists) |> assert_has("h1", result.artists)
|> assert_has("h2", text: result.title) |> assert_has("h2", result.title)
|> assert_has("p", text: Record.format_release_date(result.release_date)) |> assert_has("p", Record.format_release_date(result.release_date))
end end
session = session =
@@ -352,7 +352,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
session = session =
conn conn
|> visit(~p"/collection/scan") |> visit(~p"/collection/scan")
|> assert_has("h1", text: "Scan one or more barcodes") |> assert_has("h1", "Scan one or more barcodes")
|> assert_has("button#camera-button") |> assert_has("button#camera-button")
session session
@@ -405,8 +405,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
conn conn
|> visit(~p"/collection/scan") |> visit(~p"/collection/scan")
|> trigger_hook("#barcode-scanner", "barcode_scanned", %{"number" => barcode}) |> trigger_hook("#barcode-scanner", "barcode_scanned", %{"number" => barcode})
|> assert_has("h2", text: "Marbles") |> assert_has("h2", "Marbles")
|> assert_has("span", text: "New") |> assert_has("span", "New")
|> click_button("Add releases") |> click_button("Add releases")
[record] = MusicLibrary.Repo.all(MusicLibrary.Records.Record) [record] = MusicLibrary.Repo.all(MusicLibrary.Records.Record)
@@ -21,7 +21,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
conn conn
|> visit(~p"/collection/#{record.id}") |> visit(~p"/collection/#{record.id}")
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> assert_has("a", text: "Edit") |> assert_has("a", "Edit")
|> click_link("Edit") |> click_link("Edit")
|> assert_path(~p"/collection/#{record}/show/edit") |> assert_path(~p"/collection/#{record}/show/edit")
end end
@@ -44,26 +44,26 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
conn conn
|> visit(~p"/collection/#{record.id}") |> visit(~p"/collection/#{record.id}")
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> assert_has("h2", text: escape(record.title)) |> assert_has("h2", escape(record.title))
|> assert_has("p", text: record.release_date) |> assert_has("p", record.release_date)
|> assert_has("p", text: format_label(record.format)) |> assert_has("p", format_label(record.format))
|> assert_has("p", text: type_label(record.type)) |> assert_has("p", type_label(record.type))
|> assert_has("dd", text: Record.format_as_date(record.purchased_at)) |> assert_has("dd", Record.format_as_date(record.purchased_at))
|> assert_has("code#record-#{record.id}", text: record.id) |> assert_has("code#record-#{record.id}", record.id)
|> assert_has("code#mb-#{record.musicbrainz_id}", text: record.musicbrainz_id) |> assert_has("code#mb-#{record.musicbrainz_id}", record.musicbrainz_id)
|> assert_has("span", text: "Multi") |> assert_has("span", "Multi")
|> assert_has("span", text: "03/05/2004") |> assert_has("span", "03/05/2004")
|> assert_has("span", text: "🇬🇧") |> assert_has("span", "🇬🇧")
|> assert_has("p", text: Record.format_as_date(record.inserted_at)) |> assert_has("p", Record.format_as_date(record.inserted_at))
|> assert_has("p", text: Record.format_as_date(record.updated_at)) |> assert_has("p", Record.format_as_date(record.updated_at))
|> assert_has("img[src='#{cover_url}']") |> assert_has("img[src='#{cover_url}']")
for artist <- record.artists do for artist <- record.artists do
assert_has(session, "a", text: escape(artist.name)) assert_has(session, "a", escape(artist.name))
end end
for genre <- record.genres do for genre <- record.genres do
assert_has(session, "a", text: genre) assert_has(session, "a", genre)
end end
end end
end end
@@ -81,9 +81,9 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
session = session =
conn conn
|> visit(~p"/collection/#{record.id}") |> visit(~p"/collection/#{record.id}")
|> assert_has("button", text: "Show Tracks") |> assert_has("button", "Show Tracks")
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> assert_has("a", text: "Connect your Last.fm account") |> assert_has("a", "Connect your Last.fm account")
release = release =
MusicBrainz.Release.from_api_response(release_response) MusicBrainz.Release.from_api_response(release_response)
@@ -93,7 +93,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|> within("#disc-#{medium.number}", fn inner_session -> |> within("#disc-#{medium.number}", fn inner_session ->
for track <- medium.tracks do for track <- medium.tracks do
inner_session inner_session
|> assert_has("li", text: escape(track.title)) |> assert_has("li", escape(track.title))
end end
inner_session inner_session
@@ -13,9 +13,9 @@ defmodule MusicLibraryWeb.OnlineStoreTemplateLive.IndexTest do
conn conn
|> visit(~p"/online-store-templates") |> visit(~p"/online-store-templates")
|> assert_has("h1", text: "Online Store Templates") |> assert_has("h1", "Online Store Templates")
|> assert_has("p", text: "Amazon UK") |> assert_has("p", "Amazon UK")
|> assert_has("p", text: "Bandcamp") |> assert_has("p", "Bandcamp")
end end
end end
@@ -12,13 +12,13 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do
conn conn
|> visit(~p"/record-sets") |> visit(~p"/record-sets")
|> assert_has("h2", text: "My Favorites") |> assert_has("h2", "My Favorites")
end end
test "shows empty state when no sets exist", %{conn: conn} do test "shows empty state when no sets exist", %{conn: conn} do
conn conn
|> visit(~p"/record-sets") |> visit(~p"/record-sets")
|> assert_has("p", text: "No record sets yet") |> assert_has("p", "No record sets yet")
end end
end end
@@ -29,8 +29,8 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do
conn conn
|> visit(~p"/record-sets?query=Road") |> visit(~p"/record-sets?query=Road")
|> assert_has("h2", text: "Road Trip") |> assert_has("h2", "Road Trip")
|> refute_has("h2", text: "Unrelated Set") |> refute_has("h2", "Unrelated Set")
end end
end end
@@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do
conn conn
|> visit(~p"/record-sets/#{set}") |> visit(~p"/record-sets/#{set}")
|> assert_has("h1", text: "My Favorites") |> assert_has("h1", "My Favorites")
end end
test "displays collected/total count", %{conn: conn} do test "displays collected/total count", %{conn: conn} do
@@ -20,7 +20,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do
conn conn
|> visit(~p"/record-sets/#{set}") |> visit(~p"/record-sets/#{set}")
|> assert_has("span", text: "2/2 records") |> assert_has("span", "2/2 records")
end end
test "displays records in the set", %{conn: conn} do test "displays records in the set", %{conn: conn} do
@@ -28,8 +28,8 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do
conn conn
|> visit(~p"/record-sets/#{set}") |> visit(~p"/record-sets/#{set}")
|> assert_has("h2", text: escape(r1.title)) |> assert_has("h2", escape(r1.title))
|> assert_has("h2", text: escape(r2.title)) |> assert_has("h2", escape(r2.title))
end end
test "shows add record tile when set has no records", %{conn: conn} do test "shows add record tile when set has no records", %{conn: conn} do
@@ -45,7 +45,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do
conn conn
|> visit(~p"/record-sets/#{set}") |> visit(~p"/record-sets/#{set}")
|> assert_has("article strong", text: "bold") |> assert_has("article strong", "bold")
end end
end end
@@ -117,7 +117,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do
conn conn
|> visit(~p"/record-sets") |> visit(~p"/record-sets")
|> click_link("Linked Set") |> click_link("Linked Set")
|> assert_has("h1", text: "Linked Set") |> assert_has("h1", "Linked Set")
|> assert_path(~p"/record-sets/#{set}") |> assert_path(~p"/record-sets/#{set}")
end end
end end
@@ -48,7 +48,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
test "shows connect Last.fm button when not authenticated", %{conn: conn} do test "shows connect Last.fm button when not authenticated", %{conn: conn} do
conn conn
|> visit(~p"/scrobble") |> visit(~p"/scrobble")
|> assert_has("a", text: "Connect your Last.fm account") |> assert_has("a", "Connect your Last.fm account")
end end
test "search with results shows release groups", %{conn: conn} do test "search with results shows release groups", %{conn: conn} do
@@ -63,8 +63,8 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
# Process the {:perform_search, query} message # Process the {:perform_search, query} message
render(view) render(view)
end) end)
|> assert_has("h3", text: "Release Groups") |> assert_has("h3", "Release Groups")
|> assert_has("p", text: "Marbles") |> assert_has("p", "Marbles")
end end
test "search with empty query does not trigger search", %{conn: conn} do test "search with empty query does not trigger search", %{conn: conn} do
@@ -76,7 +76,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
|> form("form[phx-submit='search']", %{query: ""}) |> form("form[phx-submit='search']", %{query: ""})
|> render_submit() |> render_submit()
end) end)
|> refute_has("h3", text: "Release Groups") |> refute_has("h3", "Release Groups")
end end
test "select release group shows releases", %{conn: conn} do test "select release group shows releases", %{conn: conn} do
@@ -102,8 +102,8 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
# Process the {:fetch_releases, release_group} message # Process the {:fetch_releases, release_group} message
render(view) render(view)
end) end)
|> assert_has("h3", text: "Releases for") |> assert_has("h3", "Releases for")
|> assert_has("button", text: "Back") |> assert_has("button", "Back")
end end
test "clear selection goes back to release groups", %{conn: conn} do test "clear selection goes back to release groups", %{conn: conn} do
@@ -130,8 +130,8 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
view view
|> render_click("clear_selection", %{}) |> render_click("clear_selection", %{})
end) end)
|> assert_has("h3", text: "Release Groups") |> assert_has("h3", "Release Groups")
|> refute_has("h3", text: "Releases for") |> refute_has("h3", "Releases for")
end end
end end
@@ -149,7 +149,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do
render(view) render(view)
end) end)
|> assert_has("p", text: "No release groups found") |> assert_has("p", "No release groups found")
end end
end end
end end
@@ -49,20 +49,20 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do
test "renders release details", %{conn: conn} do test "renders release details", %{conn: conn} do
conn conn
|> visit(~p"/scrobble/#{@release_id}") |> visit(~p"/scrobble/#{@release_id}")
|> assert_has("h2", text: "Marbles") |> assert_has("h2", "Marbles")
|> assert_has("a", text: "Back to search") |> assert_has("a", "Back to search")
end end
test "shows Last.fm not connected alert when no session key", %{conn: conn} do test "shows Last.fm not connected alert when no session key", %{conn: conn} do
conn conn
|> visit(~p"/scrobble/#{@release_id}") |> visit(~p"/scrobble/#{@release_id}")
|> assert_has("div", text: "You need to connect your Last.fm account") |> assert_has("div", "You need to connect your Last.fm account")
end end
test "displays tracks", %{conn: conn} do test "displays tracks", %{conn: conn} do
conn conn
|> visit(~p"/scrobble/#{@release_id}") |> visit(~p"/scrobble/#{@release_id}")
|> assert_has("h3", text: "Tracks") |> assert_has("h3", "Tracks")
end end
end end
@@ -72,7 +72,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do
test "does not show Last.fm not connected alert", %{conn: conn} do test "does not show Last.fm not connected alert", %{conn: conn} do
conn conn
|> visit(~p"/scrobble/#{@release_id}") |> visit(~p"/scrobble/#{@release_id}")
|> refute_has("[data-part='title']", text: "Last.fm not connected") |> refute_has("[data-part='title']", "Last.fm not connected")
end end
test "scrobble full release", %{conn: conn} do test "scrobble full release", %{conn: conn} do
@@ -82,7 +82,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do
|> unwrap(fn view -> |> unwrap(fn view ->
render_click(view, "scrobble_release", %{}) render_click(view, "scrobble_release", %{})
end) end)
|> assert_has("#toast-group", text: "Release scrobbled successfully") |> assert_has("#toast-group", "Release scrobbled successfully")
end end
test "scrobble single medium", %{conn: conn} do test "scrobble single medium", %{conn: conn} do
@@ -92,7 +92,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do
|> unwrap(fn view -> |> unwrap(fn view ->
render_click(view, "scrobble_medium", %{"medium_number" => "1"}) render_click(view, "scrobble_medium", %{"medium_number" => "1"})
end) end)
|> assert_has("#toast-group", text: "Disc scrobbled successfully") |> assert_has("#toast-group", "Disc scrobbled successfully")
end end
test "toggle track selection", %{conn: conn} do test "toggle track selection", %{conn: conn} do
@@ -120,7 +120,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do
# Then scrobble selected # Then scrobble selected
render_click(view, "scrobble_selected_tracks", %{}) render_click(view, "scrobble_selected_tracks", %{})
end) end)
|> assert_has("#toast-group", text: "Selected tracks scrobbled successfully") |> assert_has("#toast-group", "Selected tracks scrobbled successfully")
end end
end end
@@ -31,9 +31,9 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
test "lists scrobbled tracks", %{conn: conn, track: track} do test "lists scrobbled tracks", %{conn: conn, track: track} do
conn conn
|> visit(~p"/scrobbled-tracks") |> visit(~p"/scrobbled-tracks")
|> assert_has("p", text: track.title) |> assert_has("p", track.title)
|> assert_has("p", text: track.artist.name) |> assert_has("p", track.artist.name)
|> assert_has("p", text: track.album.title) |> assert_has("p", track.album.title)
end end
test "shows empty state when no tracks", %{conn: conn} do test "shows empty state when no tracks", %{conn: conn} do
@@ -42,7 +42,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
conn conn
|> visit(~p"/scrobbled-tracks") |> visit(~p"/scrobbled-tracks")
|> assert_has("p", text: "No scrobbled tracks found") |> assert_has("p", "No scrobbled tracks found")
end end
end end
@@ -60,7 +60,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|> form("form[phx-submit='search']", %{query: "Unique Track"}) |> form("form[phx-submit='search']", %{query: "Unique Track"})
|> render_submit() |> render_submit()
end) end)
|> assert_has("p", text: "Unique Track Title") |> assert_has("p", "Unique Track Title")
end end
test "searches tracks by artist name", %{conn: conn} do test "searches tracks by artist name", %{conn: conn} do
@@ -74,7 +74,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|> form("form[phx-submit='search']", %{query: "Unique Artist"}) |> form("form[phx-submit='search']", %{query: "Unique Artist"})
|> render_submit() |> render_submit()
end) end)
|> assert_has("p", text: "Unique Artist Name") |> assert_has("p", "Unique Artist Name")
end end
test "searches tracks by album title", %{conn: conn} do test "searches tracks by album title", %{conn: conn} do
@@ -88,7 +88,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|> form("form[phx-submit='search']", %{query: "Unique Album"}) |> form("form[phx-submit='search']", %{query: "Unique Album"})
|> render_submit() |> render_submit()
end) end)
|> assert_has("p", text: "Unique Album Title") |> assert_has("p", "Unique Album Title")
end end
end end
@@ -99,7 +99,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
session = session =
conn conn
|> visit(~p"/scrobbled-tracks/#{track.scrobbled_at_uts}/edit") |> visit(~p"/scrobbled-tracks/#{track.scrobbled_at_uts}/edit")
|> assert_has("h1", text: "Edit Scrobbled Track") |> assert_has("h1", "Edit Scrobbled Track")
|> assert_path(~p"/scrobbled-tracks/#{track.scrobbled_at_uts}/edit") |> assert_path(~p"/scrobbled-tracks/#{track.scrobbled_at_uts}/edit")
# Test validation errors with invalid attrs # Test validation errors with invalid attrs
@@ -119,8 +119,8 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
|> fill_in("Album MusicBrainz ID", with: @valid_track_attrs.album.musicbrainz_id) |> fill_in("Album MusicBrainz ID", with: @valid_track_attrs.album.musicbrainz_id)
|> fill_in("Cover Image URL (optional)", with: @valid_track_attrs.cover_url) |> fill_in("Cover Image URL (optional)", with: @valid_track_attrs.cover_url)
|> click_button("Update Track") |> click_button("Update Track")
|> assert_has("p", text: "Track updated successfully") |> assert_has("p", "Track updated successfully")
|> assert_has("p", text: "Updated Track Title") |> assert_has("p", "Updated Track Title")
end end
test "shows validation errors", %{conn: conn, track: track} do test "shows validation errors", %{conn: conn, track: track} do
@@ -144,7 +144,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
conn conn
|> visit(~p"/scrobbled-tracks") |> visit(~p"/scrobbled-tracks")
|> assert_has("a", text: "Next") |> assert_has("a", "Next")
|> assert_has("#bottom_pagination") |> assert_has("#bottom_pagination")
|> click_link("a[href*='page=2']", "2") |> click_link("a[href*='page=2']", "2")
end end
@@ -156,7 +156,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do
conn conn
|> visit(~p"/scrobbled-tracks?query=Special") |> visit(~p"/scrobbled-tracks?query=Special")
|> assert_has("p", text: "Special Track") |> assert_has("p", "Special Track")
end end
test "handles page parameter", %{conn: conn} do test "handles page parameter", %{conn: conn} do
@@ -35,20 +35,20 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
session = session =
conn conn
|> visit("/") |> visit("/")
|> assert_has("dd", text: collection |> length() |> Integer.to_string()) |> assert_has("dd", collection |> length() |> Integer.to_string())
collection collection
|> Enum.frequencies_by(& &1.format) |> Enum.frequencies_by(& &1.format)
|> Enum.each(fn {format, count} -> |> Enum.each(fn {format, count} ->
assert_has(session, "a", text: to_string(count)) assert_has(session, "a", to_string(count))
assert_has(session, "dt", text: format_label(format)) assert_has(session, "dt", format_label(format))
end) end)
collection collection
|> Enum.frequencies_by(& &1.type) |> Enum.frequencies_by(& &1.type)
|> Enum.each(fn {type, count} -> |> Enum.each(fn {type, count} ->
assert_has(session, "a", text: to_string(count)) assert_has(session, "a", to_string(count))
assert_has(session, "dt", text: type_label(type)) assert_has(session, "dt", type_label(type))
end) end)
end end
@@ -58,17 +58,17 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
session = session =
conn conn
|> visit("/") |> visit("/")
|> assert_has("span", text: escape(latest_record.title)) |> assert_has("span", escape(latest_record.title))
for artist <- latest_record.artists do for artist <- latest_record.artists do
assert_has(session, "a", text: escape(artist.name)) assert_has(session, "a", escape(artist.name))
end end
end end
test "it shows the wishlist total count", %{conn: conn, wishlist: wishlist} do test "it shows the wishlist total count", %{conn: conn, wishlist: wishlist} do
conn conn
|> visit("/") |> visit("/")
|> assert_has("dd", text: wishlist |> length() |> Integer.to_string()) |> assert_has("dd", wishlist |> length() |> Integer.to_string())
end end
test "it shows the scrobble activity", %{conn: conn} do test "it shows the scrobble activity", %{conn: conn} do
@@ -178,9 +178,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|> assert_has("#album-#{machinarium_soundtrack_track.scrobbled_at_uts}", |> assert_has("#album-#{machinarium_soundtrack_track.scrobbled_at_uts}",
text: "Wishlisted" text: "Wishlisted"
) )
|> assert_has("[hidden] p", text: machinarium_soundtrack_track.title) |> assert_has("[hidden] p", machinarium_soundtrack_track.title)
|> assert_has("p", text: machinarium_soundtrack_track.album.title) |> assert_has("p", machinarium_soundtrack_track.album.title)
|> assert_has("#album-#{the_last_flight_track.scrobbled_at_uts}", text: "Collected") |> assert_has("#album-#{the_last_flight_track.scrobbled_at_uts}", "Collected")
|> assert_has("#album-#{the_mystery_of_time_track.scrobbled_at_uts}", |> assert_has("#album-#{the_mystery_of_time_track.scrobbled_at_uts}",
text: "Choose which format to import" text: "Choose which format to import"
) )
@@ -192,9 +192,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|> assert_has("#track-#{machinarium_soundtrack_track.scrobbled_at_uts}", |> assert_has("#track-#{machinarium_soundtrack_track.scrobbled_at_uts}",
text: "Wishlisted" text: "Wishlisted"
) )
|> assert_has("p", text: machinarium_soundtrack_track.title) |> assert_has("p", machinarium_soundtrack_track.title)
|> assert_has("p", text: machinarium_soundtrack_track.album.title) |> assert_has("p", machinarium_soundtrack_track.album.title)
|> assert_has("#track-#{the_last_flight_track.scrobbled_at_uts}", text: "Collected") |> assert_has("#track-#{the_last_flight_track.scrobbled_at_uts}", "Collected")
|> assert_has("#track-#{the_mystery_of_time_track.scrobbled_at_uts}", |> assert_has("#track-#{the_mystery_of_time_track.scrobbled_at_uts}",
text: "Choose which format to import" text: "Choose which format to import"
) )
@@ -267,11 +267,11 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
session = conn |> visit("/") session = conn |> visit("/")
assert_has(session, "h1", text: "On This day") assert_has(session, "h1", "On This day")
assert_has(session, "##{record_today.id} h2", text: escape(record_today.title)) assert_has(session, "##{record_today.id} h2", escape(record_today.title))
refute_has(session, "##{record_yesterday.id} h2", text: escape(record_yesterday.title)) refute_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title))
end end
test "it updates the 'On This Day' records when the date is changed", %{ test "it updates the 'On This Day' records when the date is changed", %{
@@ -299,9 +299,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
session = conn |> visit("/") session = conn |> visit("/")
assert_has(session, "##{record_today.id} h2", text: escape(record_today.title)) assert_has(session, "##{record_today.id} h2", escape(record_today.title))
refute_has(session, "##{record_yesterday.id} h2", text: escape(record_yesterday.title)) refute_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title))
session session
|> unwrap(fn view -> |> unwrap(fn view ->
@@ -310,9 +310,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|> render_change() |> render_change()
end) end)
refute_has(session, "##{record_today.id} h2", text: escape(record_today.title)) refute_has(session, "##{record_today.id} h2", escape(record_today.title))
assert_has(session, "##{record_yesterday.id} h2", text: escape(record_yesterday.title)) assert_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title))
end end
end end
end end
@@ -38,7 +38,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
conn conn
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> assert_has("p", text: "to open this search") |> assert_has("p", "to open this search")
end end
end end
@@ -48,8 +48,8 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: "nonexistent query xyz") |> fill_in("Universal Search", with: "nonexistent query xyz")
|> assert_has("p", text: "No results found for 'nonexistent query xyz'") |> assert_has("p", "No results found for 'nonexistent query xyz'")
|> assert_has("a", text: "Add a record instead") |> assert_has("a", "Add a record instead")
end end
test "resets results when query is cleared", %{conn: conn} do test "resets results when query is cleared", %{conn: conn} do
@@ -58,7 +58,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: "test query") |> fill_in("Universal Search", with: "test query")
|> fill_in("Universal Search", with: "") |> fill_in("Universal Search", with: "")
|> assert_has("p", text: "to open this search") |> assert_has("p", "to open this search")
end end
test "searches collection records", %{ test "searches collection records", %{
@@ -69,7 +69,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: collection_record.title) |> fill_in("Universal Search", with: collection_record.title)
|> assert_has("p", text: collection_record.title) |> assert_has("p", collection_record.title)
end end
test "searches wishlist records", %{ test "searches wishlist records", %{
@@ -80,7 +80,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: wishlist_record.title) |> fill_in("Universal Search", with: wishlist_record.title)
|> assert_has("p", text: wishlist_record.title) |> assert_has("p", wishlist_record.title)
end end
test "searches artists", %{ test "searches artists", %{
@@ -93,7 +93,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: artist.name) |> fill_in("Universal Search", with: artist.name)
|> assert_has("p", text: artist.name) |> assert_has("p", artist.name)
end end
test "displays results count in footer", %{ test "displays results count in footer", %{
@@ -104,7 +104,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: collection_record.title) |> fill_in("Universal Search", with: collection_record.title)
|> assert_has("div", text: "1 result") |> assert_has("div", "1 result")
end end
end end
@@ -117,11 +117,11 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
|> visit(~p"/collection") |> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)") |> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: collection_record.title) |> fill_in("Universal Search", with: collection_record.title)
|> assert_has("kbd", text: "") |> assert_has("kbd", "")
|> assert_has("kbd", text: "") |> assert_has("kbd", "")
|> assert_has("span", text: "Navigate") |> assert_has("span", "Navigate")
|> assert_has("kbd", text: "Enter") |> assert_has("kbd", "Enter")
|> assert_has("span", text: "Select") |> assert_has("span", "Select")
end end
test "search results have role=option for keyboard navigation", %{ test "search results have role=option for keyboard navigation", %{
@@ -20,7 +20,7 @@ defmodule MusicLibraryWeb.WishlistLive.IndexTest do
conn conn
|> visit(~p"/wishlist") |> visit(~p"/wishlist")
|> click_link("#records-#{record.id} a", "Purchased") |> click_link("#records-#{record.id} a", "Purchased")
|> assert_has("p", text: "Record added to the collection") |> assert_has("p", "Record added to the collection")
purchased_record = MusicLibrary.Records.get_record!(record.id) purchased_record = MusicLibrary.Records.get_record!(record.id)
@@ -13,7 +13,7 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
conn conn
|> visit(~p"/wishlist/#{record.id}") |> visit(~p"/wishlist/#{record.id}")
|> assert_has("a", text: "Edit") |> assert_has("a", "Edit")
|> click_link("Edit") |> click_link("Edit")
|> assert_path(~p"/wishlist/#{record}/show/edit") |> assert_path(~p"/wishlist/#{record}/show/edit")
end end
@@ -29,25 +29,25 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
session = session =
conn conn
|> visit(~p"/wishlist/#{record.id}") |> visit(~p"/wishlist/#{record.id}")
|> assert_has("h2", text: escape(record.title)) |> assert_has("h2", escape(record.title))
|> assert_has("p", text: record.release_date) |> assert_has("p", record.release_date)
|> assert_has("p", text: format_label(record.format)) |> assert_has("p", format_label(record.format))
|> assert_has("p", text: type_label(record.type)) |> assert_has("p", type_label(record.type))
|> assert_has("code#record-#{record.id}", text: record.id) |> assert_has("code#record-#{record.id}", record.id)
|> assert_has("code#mb-#{record.musicbrainz_id}", text: record.musicbrainz_id) |> assert_has("code#mb-#{record.musicbrainz_id}", record.musicbrainz_id)
|> assert_has("span", text: "Multi") |> assert_has("span", "Multi")
|> assert_has("span", text: "03/05/2004") |> assert_has("span", "03/05/2004")
|> assert_has("span", text: "🇬🇧") |> assert_has("span", "🇬🇧")
|> assert_has("p", text: Record.format_as_date(record.inserted_at)) |> assert_has("p", Record.format_as_date(record.inserted_at))
|> assert_has("p", text: Record.format_as_date(record.updated_at)) |> assert_has("p", Record.format_as_date(record.updated_at))
|> assert_has("img[src='#{cover_url}']") |> assert_has("img[src='#{cover_url}']")
for artist <- record.artists do for artist <- record.artists do
assert_has(session, "a", text: escape(artist.name)) assert_has(session, "a", escape(artist.name))
end end
for genre <- record.genres do for genre <- record.genres do
assert_has(session, "a", text: genre) assert_has(session, "a", genre)
end end
end end
end end