Remove some uses of List.last
This commit is contained in:
@@ -7,6 +7,8 @@ defmodule MusicLibrary.Records.TracklistPdf do
|
||||
alias MusicLibraryWeb.Duration
|
||||
alias Typst.Format
|
||||
|
||||
@fallback_config {4, 5, false}
|
||||
|
||||
@layout_configs [
|
||||
{1, 8, true},
|
||||
{2, 8, true},
|
||||
@@ -14,7 +16,7 @@ defmodule MusicLibrary.Records.TracklistPdf do
|
||||
{3, 7, true},
|
||||
{3, 6, true},
|
||||
{4, 6, false},
|
||||
{4, 5, false}
|
||||
@fallback_config
|
||||
]
|
||||
|
||||
# Empirically measured per-column capacities at block(spacing: 3pt),
|
||||
@@ -127,7 +129,7 @@ defmodule MusicLibrary.Records.TracklistPdf do
|
||||
|
||||
@doc false
|
||||
def layout_params(total_items, _media_count) do
|
||||
Enum.find(@layout_configs, List.last(@layout_configs), fn {columns, font_size, _} ->
|
||||
Enum.find(@layout_configs, @fallback_config, fn {columns, font_size, _} ->
|
||||
capacity(columns, font_size) >= total_items
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -96,45 +96,41 @@ defmodule MusicLibrary.ListeningStatsTest do
|
||||
scrobbled_at_uts: System.system_time(:second)
|
||||
})
|
||||
|
||||
tracks = list_tracks(%{order: :scrobbled_at})
|
||||
assert [track1, track2] = list_tracks(%{order: :scrobbled_at})
|
||||
|
||||
assert length(tracks) == 2
|
||||
# Should be ordered by scrobbled_at_uts descending (newest first)
|
||||
assert List.first(tracks).title == "Newer Track"
|
||||
assert List.last(tracks).title == "Older Track"
|
||||
assert track1.title == "Newer Track"
|
||||
assert track2.title == "Older Track"
|
||||
end
|
||||
|
||||
test "returns tracks ordered by title" do
|
||||
track_fixture(%{title: "Zebra Track"})
|
||||
track_fixture(%{title: "Alpha Track"})
|
||||
|
||||
tracks = list_tracks(%{order: :title})
|
||||
assert [track1, track2] = list_tracks(%{order: :title})
|
||||
|
||||
assert length(tracks) == 2
|
||||
assert List.first(tracks).title == "Alpha Track"
|
||||
assert List.last(tracks).title == "Zebra Track"
|
||||
assert track1.title == "Alpha Track"
|
||||
assert track2.title == "Zebra Track"
|
||||
end
|
||||
|
||||
test "returns tracks ordered by artist name" do
|
||||
track_fixture(%{artist_name: "Zebra Artist", title: "Track 1"})
|
||||
track_fixture(%{artist_name: "Alpha Artist", title: "Track 2"})
|
||||
|
||||
tracks = list_tracks(%{order: :artist})
|
||||
assert [track1, track2] = list_tracks(%{order: :artist})
|
||||
|
||||
assert length(tracks) == 2
|
||||
assert List.first(tracks).artist.name == "Alpha Artist"
|
||||
assert List.last(tracks).artist.name == "Zebra Artist"
|
||||
assert track1.artist.name == "Alpha Artist"
|
||||
assert track2.artist.name == "Zebra Artist"
|
||||
end
|
||||
|
||||
test "returns tracks ordered by album title" do
|
||||
track_fixture(%{album_title: "Zebra Album", title: "Track 1"})
|
||||
track_fixture(%{album_title: "Alpha Album", title: "Track 2"})
|
||||
|
||||
tracks = list_tracks(%{order: :album})
|
||||
assert [track1, track2] = list_tracks(%{order: :album})
|
||||
|
||||
assert length(tracks) == 2
|
||||
assert List.first(tracks).album.title == "Alpha Album"
|
||||
assert List.last(tracks).album.title == "Zebra Album"
|
||||
assert track1.album.title == "Alpha Album"
|
||||
assert track2.album.title == "Zebra Album"
|
||||
end
|
||||
|
||||
test "filters tracks by search query matching track title" do
|
||||
|
||||
Reference in New Issue
Block a user