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