Refactor type/format labels to enable translations

This commit is contained in:
Claudio Ortolina
2025-01-29 11:04:19 +00:00
parent 96bd453900
commit 9e1f00c9a8
16 changed files with 193 additions and 132 deletions
@@ -3,6 +3,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
import MusicLibrary.RecordsFixtures
import MusicLibrary.ReleaseGroupsFixtures
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
import Mox
alias MusicLibrary.Records.{Cover, Record}
alias MusicBrainz.APIBehaviourMock
@@ -51,8 +52,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> assert_has("#records-#{record.id}")
|> assert_has("#records-#{record.id} h2", text: escape(record.title))
|> 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.type_long_label(record.type))
|> assert_has("#records-#{record.id} p", text: format_label(record.format))
|> assert_has("#records-#{record.id} p", text: type_label(record.type))
|> assert_has("#records-#{record.id} span",
text: Record.format_as_date(record.purchased_at)
)
@@ -136,8 +137,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> assert_has("#records-#{record.id}")
|> assert_has("#records-#{record.id} h2", text: escape(record.title))
|> 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.type_long_label(record.type))
|> assert_has("#records-#{record.id} p", text: format_label(record.format))
|> assert_has("#records-#{record.id} p", text: type_label(record.type))
|> assert_has("#records-#{record.id} span",
text: Record.format_as_date(record.purchased_at)
)
@@ -178,8 +179,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> assert_has("#records-#{record.id}")
|> assert_has("#records-#{record.id} h2", text: escape(record.title))
|> 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.type_long_label(record.type))
|> assert_has("#records-#{record.id} p", text: format_label(record.format))
|> assert_has("#records-#{record.id} p", text: type_label(record.type))
|> assert_has("#records-#{record.id} span",
text: Record.format_as_date(record.purchased_at)
)
@@ -2,6 +2,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
use MusicLibraryWeb.ConnCase
import MusicLibrary.RecordsFixtures
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
alias MusicLibrary.Records.Record
describe "Edit record from show page" do
@@ -26,8 +27,8 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|> visit(~p"/collection/#{record.id}")
|> assert_has("h2", text: escape(record.title))
|> assert_has("p", text: record.release)
|> assert_has("p", text: Record.format_long_label(record.format))
|> assert_has("p", text: Record.type_long_label(record.type))
|> assert_has("p", text: format_label(record.format))
|> assert_has("p", text: type_label(record.type))
|> assert_has("dd", text: Record.format_as_date(record.purchased_at))
|> assert_has("dd", text: record.id)
|> assert_has("a", text: record.musicbrainz_id)
@@ -2,8 +2,8 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
use MusicLibraryWeb.ConnCase
alias MusicLibrary.{Records, Repo, Wishlist}
alias MusicLibrary.Records.Record
alias MusicBrainz.APIBehaviourMock
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
import MusicLibrary.RecordsFixtures
import MusicLibrary.ReleaseGroupsFixtures
import Mox
@@ -36,14 +36,14 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|> Enum.frequencies_by(& &1.format)
|> Enum.each(fn {format, count} ->
assert_has(session, "a", text: to_string(count))
assert_has(session, "dt", text: Record.format_long_label(format))
assert_has(session, "dt", text: format_label(format))
end)
collection
|> Enum.frequencies_by(& &1.type)
|> Enum.each(fn {type, count} ->
assert_has(session, "a", text: to_string(count))
assert_has(session, "dt", text: Record.type_long_label(type))
assert_has(session, "dt", text: type_label(type))
end)
end
@@ -2,6 +2,7 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
use MusicLibraryWeb.ConnCase
import MusicLibrary.RecordsFixtures
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
alias MusicLibrary.Records.Record
describe "Edit record from show page" do
@@ -26,8 +27,8 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
|> visit(~p"/wishlist/#{record.id}")
|> assert_has("h2", text: escape(record.title))
|> assert_has("p", text: record.release)
|> assert_has("p", text: Record.format_long_label(record.format))
|> assert_has("p", text: Record.type_long_label(record.type))
|> assert_has("p", text: format_label(record.format))
|> assert_has("p", text: type_label(record.type))
|> assert_has("dd", text: record.id)
|> assert_has("a", text: record.musicbrainz_id)
|> assert_has("dd", text: Record.format_as_date(record.inserted_at))