Show artists for latest record
This commit is contained in:
@@ -46,7 +46,12 @@
|
|||||||
<p class="ml-16 truncate text-sm font-medium text-gray-500">Latest record</p>
|
<p class="ml-16 truncate text-sm font-medium text-gray-500">Latest record</p>
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="ml-16 flex items-baseline pb-6 sm:pb-7">
|
<dd class="ml-16 flex items-baseline pb-6 sm:pb-7">
|
||||||
<p class="text-2xl font-semibold text-gray-900"><%= @latest_record.title %></p>
|
<p class="font-semibold">
|
||||||
|
<span class="text-2xl text-gray-900">
|
||||||
|
<%= Enum.map(@latest_record.artists, fn a -> a.name end) %>
|
||||||
|
</span>
|
||||||
|
<span class="text-gray-600"><%= @latest_record.title %></span>
|
||||||
|
</p>
|
||||||
<div class="absolute inset-x-0 bottom-0 bg-gray-50 px-4 py-4 sm:px-6">
|
<div class="absolute inset-x-0 bottom-0 bg-gray-50 px-4 py-4 sm:px-6">
|
||||||
<div class="text-sm">
|
<div class="text-sm">
|
||||||
<a
|
<a
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
defmodule MusicLibraryWeb.StatsControllerTest do
|
||||||
|
use MusicLibraryWeb.ConnCase
|
||||||
|
|
||||||
|
import MusicLibrary.RecordsFixtures
|
||||||
|
|
||||||
|
defp create_records(_) do
|
||||||
|
records = Enum.map(1..30, fn _ -> record_fixture() end)
|
||||||
|
%{records: records}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp escape(string) do
|
||||||
|
string
|
||||||
|
|> Phoenix.HTML.html_escape()
|
||||||
|
|> Phoenix.HTML.safe_to_string()
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET /" do
|
||||||
|
setup [:create_records]
|
||||||
|
|
||||||
|
test "it shows the record count (total and by format)", %{conn: conn, records: records} do
|
||||||
|
conn = get(conn, "/")
|
||||||
|
|
||||||
|
assert html_response(conn, 200) =~ records |> length() |> Integer.to_string()
|
||||||
|
|
||||||
|
records
|
||||||
|
|> Enum.frequencies_by(& &1.format)
|
||||||
|
|> Enum.each(fn {format, count} ->
|
||||||
|
assert html_response(conn, 200) =~ "#{count} #{format}"
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it shows the latest record", %{conn: conn, records: records} do
|
||||||
|
latest_record = Enum.max_by(records, & &1.inserted_at)
|
||||||
|
|
||||||
|
conn = get(conn, "/")
|
||||||
|
|
||||||
|
assert html_response(conn, 200) =~ escape(latest_record.title)
|
||||||
|
|
||||||
|
for artist <- latest_record.artists do
|
||||||
|
assert html_response(conn, 200) =~ escape(artist["name"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4,6 +4,8 @@ defmodule MusicLibrary.RecordsFixtures do
|
|||||||
entities via the `MusicLibrary.Records` context.
|
entities via the `MusicLibrary.Records` context.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias MusicLibrary.Records.Record
|
||||||
|
|
||||||
@genres [
|
@genres [
|
||||||
"progressive rock",
|
"progressive rock",
|
||||||
"art rock",
|
"art rock",
|
||||||
@@ -43,7 +45,7 @@ defmodule MusicLibrary.RecordsFixtures do
|
|||||||
musicbrainz_id: musicbrainz_id,
|
musicbrainz_id: musicbrainz_id,
|
||||||
title: Enum.random(@titles),
|
title: Enum.random(@titles),
|
||||||
type: :album,
|
type: :album,
|
||||||
format: :cd,
|
format: Record.formats() |> Enum.random(),
|
||||||
release: Enum.random(1969..2024) |> Integer.to_string()
|
release: Enum.random(1969..2024) |> Integer.to_string()
|
||||||
})
|
})
|
||||||
|> MusicLibrary.Records.create_record()
|
|> MusicLibrary.Records.create_record()
|
||||||
|
|||||||
Reference in New Issue
Block a user