Improve test coverage
Files Created (8 files, 54 new tests) Fixtures 1. test/support/fixtures/music_library/record_sets.ex — record_set/1 and record_set_with_records/2 helpers 2. test/support/fixtures/music_library/online_store_templates.ex — online_store_template/1 helper Context Tests 3. test/music_library/record_sets_test.exs — 20 tests covering search, count, CRUD, add/remove/move records 4. test/music_library/online_store_templates_test.exs — 8 tests covering list, CRUD, URL generation, validation 5. test/music_library/search_test.exs — 5 tests covering universal search and search counts 6. test/music_library/notes_test.exs — 4 tests covering get, create, update LiveView Tests 7. test/music_library_web/live/record_set_live/index_test.exs — 11 tests covering listing, empty state, search, ordering, create/edit/delete sets, remove records, reorder records 8. test/music_library_web/live/online_store_template_live/index_test.exs — 6 tests covering listing, create/edit/delete, toggle enabled Results - 297 tests, 0 failures (up from 243 — 54 new tests added) - All existing tests continue to pass There's a remaining gettext warning that needs to be investigated
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
defmodule MusicLibrary.SearchTest do
|
||||
use MusicLibrary.DataCase
|
||||
|
||||
import MusicLibrary.Fixtures.Records
|
||||
|
||||
alias MusicLibrary.Search
|
||||
|
||||
defp create_records(_) do
|
||||
collected =
|
||||
record_with_artist("Marillion", %{title: "Brave", purchased_at: DateTime.utc_now()})
|
||||
|
||||
wishlisted =
|
||||
record_with_artist("Marillion", %{title: "Afraid of Sunlight", purchased_at: nil})
|
||||
|
||||
# Create artist info so search_artists can find artists
|
||||
[artist] = collected.artists
|
||||
artist_info(artist.musicbrainz_id)
|
||||
|
||||
%{collected: collected, wishlisted: wishlisted}
|
||||
end
|
||||
|
||||
describe "universal_search/2" do
|
||||
setup [:create_records]
|
||||
|
||||
test "returns collection, wishlist, and artist results", %{
|
||||
collected: collected,
|
||||
wishlisted: wishlisted
|
||||
} do
|
||||
results = Search.universal_search("Marillion")
|
||||
|
||||
collection_ids = Enum.map(results.collection, & &1.id)
|
||||
assert collected.id in collection_ids
|
||||
|
||||
wishlist_ids = Enum.map(results.wishlist, & &1.id)
|
||||
assert wishlisted.id in wishlist_ids
|
||||
|
||||
artist_names = Enum.map(results.artists, fn a -> a.artist.name end)
|
||||
assert "Marillion" in artist_names
|
||||
end
|
||||
|
||||
test "returns empty results for no matches" do
|
||||
results = Search.universal_search("zzz_nonexistent_zzz")
|
||||
|
||||
assert results.collection == []
|
||||
assert results.wishlist == []
|
||||
assert results.artists == []
|
||||
end
|
||||
|
||||
test "respects limit", %{collected: _collected} do
|
||||
results = Search.universal_search("Marillion", limit: 1)
|
||||
|
||||
assert length(results.collection) <= 1
|
||||
assert length(results.wishlist) <= 1
|
||||
assert length(results.artists) <= 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "search_counts/1" do
|
||||
setup [:create_records]
|
||||
|
||||
test "returns counts per category" do
|
||||
counts = Search.search_counts("Marillion")
|
||||
|
||||
assert counts.collection_count >= 1
|
||||
assert counts.wishlist_count >= 1
|
||||
assert counts.artists_count >= 1
|
||||
end
|
||||
|
||||
test "returns zero counts for no matches" do
|
||||
counts = Search.search_counts("zzz_nonexistent_zzz")
|
||||
|
||||
assert counts.collection_count == 0
|
||||
assert counts.wishlist_count == 0
|
||||
assert counts.artists_count == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user