ML-193: add secondary parser, search, and API coverage tests

Add ~80 focused tests across 10 files covering:

- Record set search by name, description, contained record title, artist name
- Navigation events for records, artists, record sets, links, and view-all actions
- MusicBrainz.ReleaseGroup parser (artist credits, included RGs, release IDs, types)
- MusicBrainz.ReleaseSearchResult edge cases (missing RG, unknown formats)
- LastFm.Session XML edge cases (non-subscriber, missing nodes)
- MusicLibrary.HttpError default status-kind mapping
- Discogs.API.ErrorResponse fallback message and retry-delay behavior
- ArtistRefreshWikipediaData {:cancel, :no_english_wikipedia} worker path
- StatsComponents grouped on-this-day records and anniversary labels
This commit is contained in:
Claudio Ortolina
2026-05-21 10:45:29 +01:00
parent e99597dc7e
commit ec6980eea0
10 changed files with 961 additions and 16 deletions
@@ -2,6 +2,13 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
use MusicLibraryWeb.ConnCase
import MusicLibrary.Fixtures.Records
import MusicLibrary.Fixtures.RecordSets
import Phoenix.LiveViewTest,
only: [
render_click: 1,
element: 2
]
setup do
collection_record = record(%{title: "Dark Side of the Moon"})
@@ -12,10 +19,18 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
artist_info(artist_record.artists |> List.first() |> Map.get(:musicbrainz_id), %{})
# Create a record set for navigation testing
{:ok, record_set} =
MusicLibrary.RecordSets.create_record_set(%{
name: "Prog Favorites",
description: "Best prog albums"
})
%{
collection_record: collection_record,
wishlist_record: wishlist_record,
artist_record: artist_record
artist_record: artist_record,
record_set: record_set
}
end
@@ -125,6 +140,173 @@ defmodule MusicLibraryWeb.UniversalSearchLive.IndexTest do
end
end
describe "Navigation events" do
setup do
Req.Test.set_req_test_to_shared()
# Return valid-enough shapes so async task parsers don't crash
Req.Test.stub(LastFm.API, fn conn ->
Req.Test.json(conn, %{
"artist" => %{
"name" => "test",
"mbid" => "",
"bio" => %{"summary" => "", "content" => ""},
"image" => [%{"#text" => "", "size" => "large"}],
"url" => ""
},
"similarartists" => %{"artist" => []}
})
end)
Req.Test.stub(MusicBrainz.API, fn conn ->
Req.Test.json(conn, %{
"media" => [],
"track-count" => 0
})
end)
on_exit(fn ->
Req.Test.stub(MusicBrainz.API, nil)
Req.Test.stub(LastFm.API, nil)
end)
:ok
end
test "navigates to collection record on click", %{
conn: conn,
collection_record: collection_record
} do
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: collection_record.title)
|> unwrap(fn view ->
view
|> element("div[phx-click='navigate_to_record'][phx-value-type='collection']")
|> render_click()
end)
|> assert_path(~p"/collection/#{collection_record.id}")
end
test "navigates to wishlist record on click", %{
conn: conn,
wishlist_record: wishlist_record
} do
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: wishlist_record.title)
|> unwrap(fn view ->
view
|> element("div[phx-click='navigate_to_record'][phx-value-type='wishlist']")
|> render_click()
end)
|> assert_path(~p"/wishlist/#{wishlist_record.id}")
end
test "navigates to artist on click", %{
conn: conn,
artist_record: artist_record
} do
artist = List.first(artist_record.artists)
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: artist.name)
|> unwrap(fn view ->
view
|> element("div[phx-click='navigate_to_artist']")
|> render_click()
end)
|> assert_path(~p"/artists/#{artist.musicbrainz_id}")
end
test "navigates to record set on click", %{
conn: conn,
record_set: record_set
} do
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: record_set.name)
|> unwrap(fn view ->
view
|> element("div[phx-click='navigate_to_record_set']")
|> render_click()
end)
|> assert_path(~p"/record-sets/#{record_set.id}")
end
test "navigates via navigation link to collection chat", %{conn: conn} do
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: "chat")
|> unwrap(fn view ->
view
|> element("div[phx-click='navigate_to_link']")
|> render_click()
end)
|> assert_path(~p"/collection", query_params: %{"chat" => "open"})
end
test "record sets appear in search results", %{
conn: conn,
record_set: record_set
} do
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: record_set.name)
|> assert_has("p", record_set.name)
|> assert_has("h3", "Record Sets")
end
test "view-all-collection navigates to collection with query param", %{conn: conn} do
# Create 7 records sharing a common prefix so > 5 results exist
Enum.each(1..7, fn i ->
record(%{title: "ViewAllTest #{i}"})
end)
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: "ViewAllTest")
|> click_button("button[phx-click='navigate_to_collection']", "View all")
|> assert_path(~p"/collection", query_params: %{"query" => "ViewAllTest"})
end
test "view-all-wishlist navigates to wishlist with query param", %{conn: conn} do
# Create 7 wishlist records with a common prefix
Enum.each(1..7, fn i ->
record(%{title: "WishlistAll #{i}", purchased_at: nil})
end)
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: "WishlistAll")
|> click_button("button[phx-click='navigate_to_wishlist']", "View all")
|> assert_path(~p"/wishlist", query_params: %{"query" => "WishlistAll"})
end
test "view-all-record-sets navigates to record sets with query param", %{conn: conn} do
# Create 7 record sets with a common prefix
Enum.each(1..7, fn i ->
record_set(%{name: "SetAll #{i}"})
end)
conn
|> visit(~p"/collection")
|> click_button("Search (Cmd/Ctrl+K)")
|> fill_in("Universal Search", with: "SetAll")
|> click_button("button[phx-click='navigate_to_record_sets']", "View all")
|> assert_path(~p"/record-sets", query_params: %{"query" => "SetAll"})
end
end
describe "Keyboard navigation" do
test "displays keyboard navigation hints when results are present", %{
conn: conn,