Consolidate datetime as date formatting
This commit is contained in:
@@ -229,7 +229,7 @@ defmodule MusicLibrary.Records.Record do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_purchased_at(purchased_at) do
|
def format_as_date(purchased_at) do
|
||||||
"#{purchased_at.day}/#{purchased_at.month}/#{purchased_at.year}"
|
"#{purchased_at.day}/#{purchased_at.month}/#{purchased_at.year}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ defmodule MusicLibraryWeb.RecordComponents do
|
|||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
data-slot="icon"
|
data-slot="icon"
|
||||||
/>
|
/>
|
||||||
{Records.Record.format_purchased_at(record.purchased_at)}
|
{Records.Record.format_as_date(record.purchased_at)}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -90,7 +90,7 @@ defmodule MusicLibraryWeb.RecordComponents do
|
|||||||
{gettext("Purchased on")}
|
{gettext("Purchased on")}
|
||||||
</span>
|
</span>
|
||||||
<.icon name="hero-banknotes" class="-mt-1 h-4 w-4" aria-hidden="true" data-slot="icon" />
|
<.icon name="hero-banknotes" class="-mt-1 h-4 w-4" aria-hidden="true" data-slot="icon" />
|
||||||
{Records.Record.format_purchased_at(record.purchased_at)}
|
{Records.Record.format_as_date(record.purchased_at)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<%!-- TODO: replace with OSS version --%>
|
<%!-- TODO: replace with OSS version --%>
|
||||||
|
|||||||
@@ -138,10 +138,6 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
|
|||||||
defp title_segment(:show), do: gettext("Show")
|
defp title_segment(:show), do: gettext("Show")
|
||||||
defp title_segment(:edit), do: gettext("Edit")
|
defp title_segment(:edit), do: gettext("Edit")
|
||||||
|
|
||||||
defp human_datetime(dt) do
|
|
||||||
"#{dt.day}/#{dt.month}/#{dt.year}"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp toggle_actions_menu(record_id) do
|
defp toggle_actions_menu(record_id) do
|
||||||
JS.toggle(to: "#actions-#{record_id}")
|
JS.toggle(to: "#actions-#{record_id}")
|
||||||
|> JS.toggle_class("pointer-events-none", to: "#records > li")
|
|> JS.toggle_class("pointer-events-none", to: "#records > li")
|
||||||
|
|||||||
@@ -181,7 +181,7 @@
|
|||||||
{gettext("Purchased on")}
|
{gettext("Purchased on")}
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
||||||
{human_datetime(@record.purchased_at)}
|
{Records.Record.format_as_date(@record.purchased_at)}
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
{gettext("Inserted at")}
|
{gettext("Inserted at")}
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
||||||
{human_datetime(@record.inserted_at)}
|
{Records.Record.format_as_date(@record.inserted_at)}
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
|
<div class="py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
|
||||||
@@ -212,7 +212,7 @@
|
|||||||
{gettext("Updated at")}
|
{gettext("Updated at")}
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
||||||
{human_datetime(@record.updated_at)}
|
{Records.Record.format_as_date(@record.updated_at)}
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -135,10 +135,6 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
|
|||||||
defp title_segment(:show), do: gettext("Show")
|
defp title_segment(:show), do: gettext("Show")
|
||||||
defp title_segment(:edit), do: gettext("Edit")
|
defp title_segment(:edit), do: gettext("Edit")
|
||||||
|
|
||||||
defp human_datetime(dt) do
|
|
||||||
"#{dt.day}/#{dt.month}/#{dt.year}"
|
|
||||||
end
|
|
||||||
|
|
||||||
defp toggle_actions_menu(record_id) do
|
defp toggle_actions_menu(record_id) do
|
||||||
JS.toggle(to: "#actions-#{record_id}")
|
JS.toggle(to: "#actions-#{record_id}")
|
||||||
|> JS.toggle_class("pointer-events-none", to: "#records > li")
|
|> JS.toggle_class("pointer-events-none", to: "#records > li")
|
||||||
|
|||||||
@@ -214,7 +214,7 @@
|
|||||||
{gettext("Inserted at")}
|
{gettext("Inserted at")}
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
||||||
{human_datetime(@record.inserted_at)}
|
{Records.Record.format_as_date(@record.inserted_at)}
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
|
<div class="py-2 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
|
||||||
@@ -222,7 +222,7 @@
|
|||||||
{gettext("Updated at")}
|
{gettext("Updated at")}
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
<dd class="mt-1 text-sm leading-6 text-zinc-700 dark:text-zinc-300 sm:col-span-2 sm:mt-0">
|
||||||
{human_datetime(@record.updated_at)}
|
{Records.Record.format_as_date(@record.updated_at)}
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
|> Phoenix.HTML.safe_to_string()
|
|> Phoenix.HTML.safe_to_string()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp human_datetime(dt) do
|
|
||||||
"#{dt.day}/#{dt.month}/#{dt.year}"
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Collection" do
|
describe "Collection" do
|
||||||
setup [:fill_collection, :fill_wishlist]
|
setup [:fill_collection, :fill_wishlist]
|
||||||
|
|
||||||
@@ -61,7 +57,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
|> assert_has("#records-#{record.id} p", text: record.release)
|
|> assert_has("#records-#{record.id} p", text: record.release)
|
||||||
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|
||||||
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
|
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
|
||||||
|> assert_has("#records-#{record.id} span", text: human_datetime(record.purchased_at))
|
|> assert_has("#records-#{record.id} span",
|
||||||
|
text: Record.format_as_date(record.purchased_at)
|
||||||
|
)
|
||||||
|
|
||||||
for artist <- record.artists do
|
for artist <- record.artists do
|
||||||
assert_has(session, "#records-#{record.id} a", text: escape(artist.name))
|
assert_has(session, "#records-#{record.id} a", text: escape(artist.name))
|
||||||
@@ -152,7 +150,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
|> assert_has("#records-#{record.id} p", text: record.release)
|
|> assert_has("#records-#{record.id} p", text: record.release)
|
||||||
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|
||||||
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
|
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
|
||||||
|> assert_has("#records-#{record.id} span", text: human_datetime(record.purchased_at))
|
|> assert_has("#records-#{record.id} span",
|
||||||
|
text: Record.format_as_date(record.purchased_at)
|
||||||
|
)
|
||||||
|> unwrap(fn collection_view ->
|
|> unwrap(fn collection_view ->
|
||||||
html = render(collection_view)
|
html = render(collection_view)
|
||||||
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
||||||
@@ -194,7 +194,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|
|||||||
|> assert_has("#records-#{record.id} p", text: record.release)
|
|> assert_has("#records-#{record.id} p", text: record.release)
|
||||||
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|
|> assert_has("#records-#{record.id} p", text: Record.format_long_label(record.format))
|
||||||
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
|
|> assert_has("#records-#{record.id} p", text: Record.type_long_label(record.type))
|
||||||
|> assert_has("#records-#{record.id} span", text: human_datetime(record.purchased_at))
|
|> assert_has("#records-#{record.id} span",
|
||||||
|
text: Record.format_as_date(record.purchased_at)
|
||||||
|
)
|
||||||
|> unwrap(fn collection_view ->
|
|> unwrap(fn collection_view ->
|
||||||
html = render(collection_view)
|
html = render(collection_view)
|
||||||
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
|||||||
|> Phoenix.HTML.safe_to_string()
|
|> Phoenix.HTML.safe_to_string()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp human_datetime(dt) do
|
|
||||||
"#{dt.day}/#{dt.month}/#{dt.year}"
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Edit record from show page" do
|
describe "Edit record from show page" do
|
||||||
test "can navigate to the record edit form", %{conn: conn} do
|
test "can navigate to the record edit form", %{conn: conn} do
|
||||||
record = record_fixture()
|
record = record_fixture()
|
||||||
@@ -37,9 +33,9 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
|||||||
|> assert_has("p", text: record.release)
|
|> assert_has("p", text: record.release)
|
||||||
|> assert_has("p", text: Record.format_long_label(record.format))
|
|> assert_has("p", text: Record.format_long_label(record.format))
|
||||||
|> assert_has("p", text: Record.type_long_label(record.type))
|
|> assert_has("p", text: Record.type_long_label(record.type))
|
||||||
|> assert_has("dd", text: human_datetime(record.purchased_at))
|
|> assert_has("dd", text: Record.format_as_date(record.purchased_at))
|
||||||
|> assert_has("dd", text: human_datetime(record.inserted_at))
|
|> assert_has("dd", text: Record.format_as_date(record.inserted_at))
|
||||||
|> assert_has("dd", text: human_datetime(record.updated_at))
|
|> assert_has("dd", text: Record.format_as_date(record.updated_at))
|
||||||
|> unwrap(fn show_view ->
|
|> unwrap(fn show_view ->
|
||||||
html = render(show_view)
|
html = render(show_view)
|
||||||
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
assert html =~ ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
|
||||||
|
|||||||
Reference in New Issue
Block a user