From c3cb5108929660beb55f859f3d4f8c5cf8aebf98 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 6 Mar 2026 06:41:06 +0000 Subject: [PATCH] Convert phoenix_test assertions to simplified syntax --- .../live/artist_live/show_test.exs | 26 ++++---- .../live/collection_live/index_test.exs | 62 +++++++++---------- .../live/collection_live/show_test.exs | 36 +++++------ .../online_store_template_live/index_test.exs | 6 +- .../live/record_set_live/index_test.exs | 8 +-- .../live/record_set_live/show_test.exs | 12 ++-- .../live/scrobble_live/index_test.exs | 18 +++--- .../live/scrobble_live/show_test.exs | 16 ++--- .../live/scrobbled_tracks_live/index_test.exs | 24 +++---- .../live/stats_live/index_test.exs | 42 ++++++------- .../live/universal_search_live/index_test.exs | 26 ++++---- .../live/wishlist_live/index_test.exs | 2 +- .../live/wishlist_live/show_test.exs | 28 ++++----- 13 files changed, 153 insertions(+), 153 deletions(-) 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 07c19603..41f35297 100644 --- a/test/music_library_web/live/artist_live/show_test.exs +++ b/test/music_library_web/live/artist_live/show_test.exs @@ -43,8 +43,8 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do conn |> visit(~p"/artists/#{artist_musicbrainz_id}") |> unwrap(&render_async/1) - |> assert_has("span", text: "123") - |> assert_has("dt", text: "Biography") + |> assert_has("span", "123") + |> assert_has("dt", "Biography") end test "it gracefully handles errors in fetching bio and play count", %{ @@ -64,10 +64,10 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do conn |> visit(~p"/artists/#{artist_musicbrainz_id}") |> unwrap(&render_async/1) - |> refute_has("span", text: "123") - |> refute_has("summary", text: "Biography") - |> assert_has("div", text: "Error loading play count") - |> assert_has("div", text: "Error loading biography") + |> refute_has("span", "123") + |> refute_has("summary", "Biography") + |> assert_has("div", "Error loading play count") + |> assert_has("div", "Error loading biography") end test "it shows the artist country and MB id", %{ @@ -87,9 +87,9 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do conn |> visit(~p"/artists/#{artist_musicbrainz_id}") |> unwrap(&render_async/1) - |> assert_has("span", text: "United Kingdom") - |> assert_has("span", text: "🇬🇧") - |> assert_has("code", text: artist_musicbrainz_id) + |> assert_has("span", "United Kingdom") + |> assert_has("span", "🇬🇧") + |> assert_has("code", artist_musicbrainz_id) end test "it shows records from the collection and the wishlist", %{ @@ -119,10 +119,10 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do conn |> visit(~p"/artists/#{artist_musicbrainz_id}") |> unwrap(&render_async/1) - |> assert_has("#collection p", text: escape(collection_record.title)) - |> assert_has("#wishlist p", text: escape(wishlist_record.title)) - |> refute_has("#collection p", text: escape(other_collection_record.title)) - |> refute_has("#wishlist p", text: escape(other_collection_record.title)) + |> assert_has("#collection p", escape(collection_record.title)) + |> assert_has("#wishlist p", escape(wishlist_record.title)) + |> refute_has("#collection p", escape(other_collection_record.title)) + |> refute_has("#wishlist p", escape(other_collection_record.title)) end end end diff --git a/test/music_library_web/live/collection_live/index_test.exs b/test/music_library_web/live/collection_live/index_test.exs index a5903327..1d3ba452 100644 --- a/test/music_library_web/live/collection_live/index_test.exs +++ b/test/music_library_web/live/collection_live/index_test.exs @@ -59,17 +59,17 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do session |> assert_has("#records-#{record.id}") - |> assert_has("#records-#{record.id} h2", text: escape(record.title)) - |> assert_has("#records-#{record.id} p", text: record.release_date) - |> assert_has("#records-#{record.id} p", text: format_label(record.format)) - |> assert_has("#records-#{record.id} p", text: type_label(record.type)) + |> assert_has("#records-#{record.id} h2", escape(record.title)) + |> assert_has("#records-#{record.id} p", record.release_date) + |> assert_has("#records-#{record.id} p", format_label(record.format)) + |> assert_has("#records-#{record.id} p", type_label(record.type)) |> assert_has("#records-#{record.id} span", text: Record.format_as_date(record.purchased_at) ) |> assert_has("img[src='#{cover_url}']") 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 @@ -106,9 +106,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do end page_2_session - |> assert_has("#bottom_pagination a", text: "1") - |> refute_has("#bottom_pagination a", text: "2") - |> assert_has("#bottom_pagination a", text: "3") + |> assert_has("#bottom_pagination a", "1") + |> refute_has("#bottom_pagination a", "2") + |> assert_has("#bottom_pagination a", "3") {page_3_records, rest_of_records} = Enum.split(rest_of_records, page_size) @@ -128,9 +128,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do end page_3_session - |> assert_has("#bottom_pagination a", text: "1") - |> assert_has("#bottom_pagination a", text: "2") - |> refute_has("#bottom_pagination a", text: "3") + |> assert_has("#bottom_pagination a", "1") + |> assert_has("#bottom_pagination a", "2") + |> refute_has("#bottom_pagination a", "3") end end @@ -150,17 +150,17 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do session |> assert_has("#records-#{record.id}") - |> assert_has("#records-#{record.id} h2", text: escape(record.title)) - |> assert_has("#records-#{record.id} p", text: record.release_date) - |> assert_has("#records-#{record.id} p", text: format_label(record.format)) - |> assert_has("#records-#{record.id} p", text: type_label(record.type)) + |> assert_has("#records-#{record.id} h2", escape(record.title)) + |> assert_has("#records-#{record.id} p", record.release_date) + |> assert_has("#records-#{record.id} p", format_label(record.format)) + |> assert_has("#records-#{record.id} p", type_label(record.type)) |> assert_has("#records-#{record.id} span", text: Record.format_as_date(record.purchased_at) ) |> assert_has("img[src='#{cover_url}']") 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 @@ -194,17 +194,17 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do session |> assert_has("#records-#{record.id}") - |> assert_has("#records-#{record.id} h2", text: escape(record.title)) - |> assert_has("#records-#{record.id} p", text: record.release_date) - |> assert_has("#records-#{record.id} p", text: format_label(record.format)) - |> assert_has("#records-#{record.id} p", text: type_label(record.type)) + |> assert_has("#records-#{record.id} h2", escape(record.title)) + |> assert_has("#records-#{record.id} p", record.release_date) + |> assert_has("#records-#{record.id} p", format_label(record.format)) + |> assert_has("#records-#{record.id} p", type_label(record.type)) |> assert_has("#records-#{record.id} span", text: Record.format_as_date(record.purchased_at) ) |> assert_has("img[src='#{cover_url}']") 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 @@ -221,7 +221,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do conn |> visit(~p"/collection") |> 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") end @@ -238,7 +238,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do session |> upload("Cover art", raven_cover_fixture()) |> 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_cover_url = cover_url(updated_record, 460) @@ -253,8 +253,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do conn |> visit(~p"/collection") |> click_link("Add") - |> assert_has("label", text: "Search for a record") - |> assert_has("div", text: "No results") + |> assert_has("label", "Search for a record") + |> assert_has("div", "No results") |> assert_path(~p"/collection/import") end @@ -294,9 +294,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do result = ReleaseGroupSearchResult.from_api_response(release_group_search_result) session - |> assert_has("h1", text: result.artists) - |> assert_has("h2", text: result.title) - |> assert_has("p", text: Record.format_release_date(result.release_date)) + |> assert_has("h1", result.artists) + |> assert_has("h2", result.title) + |> assert_has("p", Record.format_release_date(result.release_date)) end session = @@ -352,7 +352,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do session = conn |> 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") session @@ -405,8 +405,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do conn |> visit(~p"/collection/scan") |> trigger_hook("#barcode-scanner", "barcode_scanned", %{"number" => barcode}) - |> assert_has("h2", text: "Marbles") - |> assert_has("span", text: "New") + |> assert_has("h2", "Marbles") + |> assert_has("span", "New") |> click_button("Add releases") [record] = MusicLibrary.Repo.all(MusicLibrary.Records.Record) 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 83ed3600..74d820d8 100644 --- a/test/music_library_web/live/collection_live/show_test.exs +++ b/test/music_library_web/live/collection_live/show_test.exs @@ -21,7 +21,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do conn |> visit(~p"/collection/#{record.id}") |> unwrap(&render_async/1) - |> assert_has("a", text: "Edit") + |> assert_has("a", "Edit") |> click_link("Edit") |> assert_path(~p"/collection/#{record}/show/edit") end @@ -44,26 +44,26 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do 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)) - |> assert_has("p", text: type_label(record.type)) - |> assert_has("dd", text: Record.format_as_date(record.purchased_at)) - |> assert_has("code#record-#{record.id}", text: record.id) - |> assert_has("code#mb-#{record.musicbrainz_id}", text: record.musicbrainz_id) - |> assert_has("span", text: "Multi") - |> assert_has("span", text: "03/05/2004") - |> assert_has("span", text: "🇬🇧") - |> assert_has("p", text: Record.format_as_date(record.inserted_at)) - |> assert_has("p", text: Record.format_as_date(record.updated_at)) + |> assert_has("h2", escape(record.title)) + |> assert_has("p", record.release_date) + |> assert_has("p", format_label(record.format)) + |> assert_has("p", type_label(record.type)) + |> assert_has("dd", Record.format_as_date(record.purchased_at)) + |> assert_has("code#record-#{record.id}", record.id) + |> assert_has("code#mb-#{record.musicbrainz_id}", record.musicbrainz_id) + |> assert_has("span", "Multi") + |> assert_has("span", "03/05/2004") + |> assert_has("span", "🇬🇧") + |> assert_has("p", Record.format_as_date(record.inserted_at)) + |> assert_has("p", Record.format_as_date(record.updated_at)) |> assert_has("img[src='#{cover_url}']") for artist <- record.artists do - assert_has(session, "a", text: escape(artist.name)) + assert_has(session, "a", escape(artist.name)) end for genre <- record.genres do - assert_has(session, "a", text: genre) + assert_has(session, "a", genre) end end end @@ -81,9 +81,9 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do session = conn |> visit(~p"/collection/#{record.id}") - |> assert_has("button", text: "Show Tracks") + |> assert_has("button", "Show Tracks") |> unwrap(&render_async/1) - |> assert_has("a", text: "Connect your Last.fm account") + |> assert_has("a", "Connect your Last.fm account") release = MusicBrainz.Release.from_api_response(release_response) @@ -93,7 +93,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do |> within("#disc-#{medium.number}", fn inner_session -> for track <- medium.tracks do inner_session - |> assert_has("li", text: escape(track.title)) + |> assert_has("li", escape(track.title)) end inner_session diff --git a/test/music_library_web/live/online_store_template_live/index_test.exs b/test/music_library_web/live/online_store_template_live/index_test.exs index d484d610..f1d05362 100644 --- a/test/music_library_web/live/online_store_template_live/index_test.exs +++ b/test/music_library_web/live/online_store_template_live/index_test.exs @@ -13,9 +13,9 @@ defmodule MusicLibraryWeb.OnlineStoreTemplateLive.IndexTest do conn |> visit(~p"/online-store-templates") - |> assert_has("h1", text: "Online Store Templates") - |> assert_has("p", text: "Amazon UK") - |> assert_has("p", text: "Bandcamp") + |> assert_has("h1", "Online Store Templates") + |> assert_has("p", "Amazon UK") + |> assert_has("p", "Bandcamp") end end diff --git a/test/music_library_web/live/record_set_live/index_test.exs b/test/music_library_web/live/record_set_live/index_test.exs index 1efb0ac5..408610c6 100644 --- a/test/music_library_web/live/record_set_live/index_test.exs +++ b/test/music_library_web/live/record_set_live/index_test.exs @@ -12,13 +12,13 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do conn |> visit(~p"/record-sets") - |> assert_has("h2", text: "My Favorites") + |> assert_has("h2", "My Favorites") end test "shows empty state when no sets exist", %{conn: conn} do conn |> visit(~p"/record-sets") - |> assert_has("p", text: "No record sets yet") + |> assert_has("p", "No record sets yet") end end @@ -29,8 +29,8 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do conn |> visit(~p"/record-sets?query=Road") - |> assert_has("h2", text: "Road Trip") - |> refute_has("h2", text: "Unrelated Set") + |> assert_has("h2", "Road Trip") + |> refute_has("h2", "Unrelated Set") end end diff --git a/test/music_library_web/live/record_set_live/show_test.exs b/test/music_library_web/live/record_set_live/show_test.exs index 150640e5..90867899 100644 --- a/test/music_library_web/live/record_set_live/show_test.exs +++ b/test/music_library_web/live/record_set_live/show_test.exs @@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do conn |> visit(~p"/record-sets/#{set}") - |> assert_has("h1", text: "My Favorites") + |> assert_has("h1", "My Favorites") end test "displays collected/total count", %{conn: conn} do @@ -20,7 +20,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do conn |> visit(~p"/record-sets/#{set}") - |> assert_has("span", text: "2/2 records") + |> assert_has("span", "2/2 records") end test "displays records in the set", %{conn: conn} do @@ -28,8 +28,8 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do conn |> visit(~p"/record-sets/#{set}") - |> assert_has("h2", text: escape(r1.title)) - |> assert_has("h2", text: escape(r2.title)) + |> assert_has("h2", escape(r1.title)) + |> assert_has("h2", escape(r2.title)) end test "shows add record tile when set has no records", %{conn: conn} do @@ -45,7 +45,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do conn |> visit(~p"/record-sets/#{set}") - |> assert_has("article strong", text: "bold") + |> assert_has("article strong", "bold") end end @@ -117,7 +117,7 @@ defmodule MusicLibraryWeb.RecordSetLive.ShowTest do conn |> visit(~p"/record-sets") |> click_link("Linked Set") - |> assert_has("h1", text: "Linked Set") + |> assert_has("h1", "Linked Set") |> assert_path(~p"/record-sets/#{set}") end end diff --git a/test/music_library_web/live/scrobble_live/index_test.exs b/test/music_library_web/live/scrobble_live/index_test.exs index 49a1425b..2e0ef3fe 100644 --- a/test/music_library_web/live/scrobble_live/index_test.exs +++ b/test/music_library_web/live/scrobble_live/index_test.exs @@ -48,7 +48,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do test "shows connect Last.fm button when not authenticated", %{conn: conn} do conn |> visit(~p"/scrobble") - |> assert_has("a", text: "Connect your Last.fm account") + |> assert_has("a", "Connect your Last.fm account") end 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 render(view) end) - |> assert_has("h3", text: "Release Groups") - |> assert_has("p", text: "Marbles") + |> assert_has("h3", "Release Groups") + |> assert_has("p", "Marbles") end 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: ""}) |> render_submit() end) - |> refute_has("h3", text: "Release Groups") + |> refute_has("h3", "Release Groups") end 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 render(view) end) - |> assert_has("h3", text: "Releases for") - |> assert_has("button", text: "Back") + |> assert_has("h3", "Releases for") + |> assert_has("button", "Back") end test "clear selection goes back to release groups", %{conn: conn} do @@ -130,8 +130,8 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do view |> render_click("clear_selection", %{}) end) - |> assert_has("h3", text: "Release Groups") - |> refute_has("h3", text: "Releases for") + |> assert_has("h3", "Release Groups") + |> refute_has("h3", "Releases for") end end @@ -149,7 +149,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.IndexTest do render(view) end) - |> assert_has("p", text: "No release groups found") + |> assert_has("p", "No release groups found") end end end diff --git a/test/music_library_web/live/scrobble_live/show_test.exs b/test/music_library_web/live/scrobble_live/show_test.exs index 3a6e3e34..21b6a963 100644 --- a/test/music_library_web/live/scrobble_live/show_test.exs +++ b/test/music_library_web/live/scrobble_live/show_test.exs @@ -49,20 +49,20 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do test "renders release details", %{conn: conn} do conn |> visit(~p"/scrobble/#{@release_id}") - |> assert_has("h2", text: "Marbles") - |> assert_has("a", text: "Back to search") + |> assert_has("h2", "Marbles") + |> assert_has("a", "Back to search") end test "shows Last.fm not connected alert when no session key", %{conn: conn} do conn |> 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 test "displays tracks", %{conn: conn} do conn |> visit(~p"/scrobble/#{@release_id}") - |> assert_has("h3", text: "Tracks") + |> assert_has("h3", "Tracks") end end @@ -72,7 +72,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do test "does not show Last.fm not connected alert", %{conn: conn} do conn |> 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 test "scrobble full release", %{conn: conn} do @@ -82,7 +82,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do |> unwrap(fn view -> render_click(view, "scrobble_release", %{}) end) - |> assert_has("#toast-group", text: "Release scrobbled successfully") + |> assert_has("#toast-group", "Release scrobbled successfully") end test "scrobble single medium", %{conn: conn} do @@ -92,7 +92,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do |> unwrap(fn view -> render_click(view, "scrobble_medium", %{"medium_number" => "1"}) end) - |> assert_has("#toast-group", text: "Disc scrobbled successfully") + |> assert_has("#toast-group", "Disc scrobbled successfully") end test "toggle track selection", %{conn: conn} do @@ -120,7 +120,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ShowTest do # Then scrobble selected render_click(view, "scrobble_selected_tracks", %{}) end) - |> assert_has("#toast-group", text: "Selected tracks scrobbled successfully") + |> assert_has("#toast-group", "Selected tracks scrobbled successfully") end end diff --git a/test/music_library_web/live/scrobbled_tracks_live/index_test.exs b/test/music_library_web/live/scrobbled_tracks_live/index_test.exs index 431e5162..85c520b8 100644 --- a/test/music_library_web/live/scrobbled_tracks_live/index_test.exs +++ b/test/music_library_web/live/scrobbled_tracks_live/index_test.exs @@ -31,9 +31,9 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do test "lists scrobbled tracks", %{conn: conn, track: track} do conn |> visit(~p"/scrobbled-tracks") - |> assert_has("p", text: track.title) - |> assert_has("p", text: track.artist.name) - |> assert_has("p", text: track.album.title) + |> assert_has("p", track.title) + |> assert_has("p", track.artist.name) + |> assert_has("p", track.album.title) end test "shows empty state when no tracks", %{conn: conn} do @@ -42,7 +42,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do conn |> visit(~p"/scrobbled-tracks") - |> assert_has("p", text: "No scrobbled tracks found") + |> assert_has("p", "No scrobbled tracks found") end end @@ -60,7 +60,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do |> form("form[phx-submit='search']", %{query: "Unique Track"}) |> render_submit() end) - |> assert_has("p", text: "Unique Track Title") + |> assert_has("p", "Unique Track Title") end 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"}) |> render_submit() end) - |> assert_has("p", text: "Unique Artist Name") + |> assert_has("p", "Unique Artist Name") end 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"}) |> render_submit() end) - |> assert_has("p", text: "Unique Album Title") + |> assert_has("p", "Unique Album Title") end end @@ -99,7 +99,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do session = conn |> 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") # 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("Cover Image URL (optional)", with: @valid_track_attrs.cover_url) |> click_button("Update Track") - |> assert_has("p", text: "Track updated successfully") - |> assert_has("p", text: "Updated Track Title") + |> assert_has("p", "Track updated successfully") + |> assert_has("p", "Updated Track Title") end test "shows validation errors", %{conn: conn, track: track} do @@ -144,7 +144,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do conn |> visit(~p"/scrobbled-tracks") - |> assert_has("a", text: "Next") + |> assert_has("a", "Next") |> assert_has("#bottom_pagination") |> click_link("a[href*='page=2']", "2") end @@ -156,7 +156,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLiveTest do conn |> visit(~p"/scrobbled-tracks?query=Special") - |> assert_has("p", text: "Special Track") + |> assert_has("p", "Special Track") end test "handles page parameter", %{conn: conn} do diff --git a/test/music_library_web/live/stats_live/index_test.exs b/test/music_library_web/live/stats_live/index_test.exs index ddfceddd..5187c04e 100644 --- a/test/music_library_web/live/stats_live/index_test.exs +++ b/test/music_library_web/live/stats_live/index_test.exs @@ -35,20 +35,20 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do session = conn |> visit("/") - |> assert_has("dd", text: collection |> length() |> Integer.to_string()) + |> assert_has("dd", collection |> length() |> Integer.to_string()) collection |> Enum.frequencies_by(& &1.format) |> Enum.each(fn {format, count} -> - assert_has(session, "a", text: to_string(count)) - assert_has(session, "dt", text: format_label(format)) + assert_has(session, "a", to_string(count)) + assert_has(session, "dt", format_label(format)) end) collection |> Enum.frequencies_by(& &1.type) |> Enum.each(fn {type, count} -> - assert_has(session, "a", text: to_string(count)) - assert_has(session, "dt", text: type_label(type)) + assert_has(session, "a", to_string(count)) + assert_has(session, "dt", type_label(type)) end) end @@ -58,17 +58,17 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do session = conn |> visit("/") - |> assert_has("span", text: escape(latest_record.title)) + |> assert_has("span", escape(latest_record.title)) for artist <- latest_record.artists do - assert_has(session, "a", text: escape(artist.name)) + assert_has(session, "a", escape(artist.name)) end end test "it shows the wishlist total count", %{conn: conn, wishlist: wishlist} do conn |> visit("/") - |> assert_has("dd", text: wishlist |> length() |> Integer.to_string()) + |> assert_has("dd", wishlist |> length() |> Integer.to_string()) end 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}", text: "Wishlisted" ) - |> assert_has("[hidden] p", text: machinarium_soundtrack_track.title) - |> assert_has("p", text: machinarium_soundtrack_track.album.title) - |> assert_has("#album-#{the_last_flight_track.scrobbled_at_uts}", text: "Collected") + |> assert_has("[hidden] p", machinarium_soundtrack_track.title) + |> assert_has("p", machinarium_soundtrack_track.album.title) + |> assert_has("#album-#{the_last_flight_track.scrobbled_at_uts}", "Collected") |> assert_has("#album-#{the_mystery_of_time_track.scrobbled_at_uts}", text: "Choose which format to import" ) @@ -192,9 +192,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do |> assert_has("#track-#{machinarium_soundtrack_track.scrobbled_at_uts}", text: "Wishlisted" ) - |> assert_has("p", text: machinarium_soundtrack_track.title) - |> assert_has("p", text: machinarium_soundtrack_track.album.title) - |> assert_has("#track-#{the_last_flight_track.scrobbled_at_uts}", text: "Collected") + |> assert_has("p", machinarium_soundtrack_track.title) + |> assert_has("p", machinarium_soundtrack_track.album.title) + |> assert_has("#track-#{the_last_flight_track.scrobbled_at_uts}", "Collected") |> assert_has("#track-#{the_mystery_of_time_track.scrobbled_at_uts}", text: "Choose which format to import" ) @@ -267,11 +267,11 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do 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 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("/") - 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 |> unwrap(fn view -> @@ -310,9 +310,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do |> render_change() 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 diff --git a/test/music_library_web/live/universal_search_live/index_test.exs b/test/music_library_web/live/universal_search_live/index_test.exs index a29cca13..db9b9cbf 100644 --- a/test/music_library_web/live/universal_search_live/index_test.exs +++ b/test/music_library_web/live/universal_search_live/index_test.exs @@ -38,7 +38,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do conn |> visit(~p"/collection") |> click_button("Search (Cmd/Ctrl+K)") - |> assert_has("p", text: "to open this search") + |> assert_has("p", "to open this search") end end @@ -48,8 +48,8 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do |> visit(~p"/collection") |> click_button("Search (Cmd/Ctrl+K)") |> fill_in("Universal Search", with: "nonexistent query xyz") - |> assert_has("p", text: "No results found for 'nonexistent query xyz'") - |> assert_has("a", text: "Add a record instead") + |> assert_has("p", "No results found for 'nonexistent query xyz'") + |> assert_has("a", "Add a record instead") end 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)") |> fill_in("Universal Search", with: "test query") |> fill_in("Universal Search", with: "") - |> assert_has("p", text: "to open this search") + |> assert_has("p", "to open this search") end test "searches collection records", %{ @@ -69,7 +69,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do |> visit(~p"/collection") |> click_button("Search (Cmd/Ctrl+K)") |> fill_in("Universal Search", with: collection_record.title) - |> assert_has("p", text: collection_record.title) + |> assert_has("p", collection_record.title) end test "searches wishlist records", %{ @@ -80,7 +80,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do |> visit(~p"/collection") |> click_button("Search (Cmd/Ctrl+K)") |> fill_in("Universal Search", with: wishlist_record.title) - |> assert_has("p", text: wishlist_record.title) + |> assert_has("p", wishlist_record.title) end test "searches artists", %{ @@ -93,7 +93,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do |> visit(~p"/collection") |> click_button("Search (Cmd/Ctrl+K)") |> fill_in("Universal Search", with: artist.name) - |> assert_has("p", text: artist.name) + |> assert_has("p", artist.name) end test "displays results count in footer", %{ @@ -104,7 +104,7 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do |> visit(~p"/collection") |> click_button("Search (Cmd/Ctrl+K)") |> fill_in("Universal Search", with: collection_record.title) - |> assert_has("div", text: "1 result") + |> assert_has("div", "1 result") end end @@ -117,11 +117,11 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do |> visit(~p"/collection") |> click_button("Search (Cmd/Ctrl+K)") |> fill_in("Universal Search", with: collection_record.title) - |> assert_has("kbd", text: "↑") - |> assert_has("kbd", text: "↓") - |> assert_has("span", text: "Navigate") - |> assert_has("kbd", text: "Enter") - |> assert_has("span", text: "Select") + |> assert_has("kbd", "↑") + |> assert_has("kbd", "↓") + |> assert_has("span", "Navigate") + |> assert_has("kbd", "Enter") + |> assert_has("span", "Select") end test "search results have role=option for keyboard navigation", %{ diff --git a/test/music_library_web/live/wishlist_live/index_test.exs b/test/music_library_web/live/wishlist_live/index_test.exs index a4556eb2..719cad81 100644 --- a/test/music_library_web/live/wishlist_live/index_test.exs +++ b/test/music_library_web/live/wishlist_live/index_test.exs @@ -20,7 +20,7 @@ defmodule MusicLibraryWeb.WishlistLive.IndexTest do conn |> visit(~p"/wishlist") |> 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) diff --git a/test/music_library_web/live/wishlist_live/show_test.exs b/test/music_library_web/live/wishlist_live/show_test.exs index bcfd663d..b2a58ced 100644 --- a/test/music_library_web/live/wishlist_live/show_test.exs +++ b/test/music_library_web/live/wishlist_live/show_test.exs @@ -13,7 +13,7 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do conn |> visit(~p"/wishlist/#{record.id}") - |> assert_has("a", text: "Edit") + |> assert_has("a", "Edit") |> click_link("Edit") |> assert_path(~p"/wishlist/#{record}/show/edit") end @@ -29,25 +29,25 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do session = conn |> visit(~p"/wishlist/#{record.id}") - |> assert_has("h2", text: escape(record.title)) - |> assert_has("p", text: record.release_date) - |> assert_has("p", text: format_label(record.format)) - |> assert_has("p", text: type_label(record.type)) - |> assert_has("code#record-#{record.id}", text: record.id) - |> assert_has("code#mb-#{record.musicbrainz_id}", text: record.musicbrainz_id) - |> assert_has("span", text: "Multi") - |> assert_has("span", text: "03/05/2004") - |> assert_has("span", text: "🇬🇧") - |> assert_has("p", text: Record.format_as_date(record.inserted_at)) - |> assert_has("p", text: Record.format_as_date(record.updated_at)) + |> assert_has("h2", escape(record.title)) + |> assert_has("p", record.release_date) + |> assert_has("p", format_label(record.format)) + |> assert_has("p", type_label(record.type)) + |> assert_has("code#record-#{record.id}", record.id) + |> assert_has("code#mb-#{record.musicbrainz_id}", record.musicbrainz_id) + |> assert_has("span", "Multi") + |> assert_has("span", "03/05/2004") + |> assert_has("span", "🇬🇧") + |> assert_has("p", Record.format_as_date(record.inserted_at)) + |> assert_has("p", Record.format_as_date(record.updated_at)) |> assert_has("img[src='#{cover_url}']") for artist <- record.artists do - assert_has(session, "a", text: escape(artist.name)) + assert_has(session, "a", escape(artist.name)) end for genre <- record.genres do - assert_has(session, "a", text: genre) + assert_has(session, "a", genre) end end end