diff --git a/test/music_library_web/live/collection_live/index_test.exs b/test/music_library_web/live/collection_live/index_test.exs index 1d3ba452..7222cfa6 100644 --- a/test/music_library_web/live/collection_live/index_test.exs +++ b/test/music_library_web/live/collection_live/index_test.exs @@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do alias MusicLibrary.Records.Record # make it a multiple of 4 for easier calculations - @default_records_page_size 8 + @default_records_page_size 4 @total_records @default_records_page_size + div(@default_records_page_size, 2) defp fill_collection(_) do @@ -20,18 +20,11 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do %{collection: records} end - defp fill_wishlist(_) do - records = Enum.map(1..@total_records, fn _ -> record(%{purchased_at: nil}) end) - %{wishlist: records} - end - describe "Collection" do - setup [:fill_collection, :fill_wishlist] + setup [:fill_collection] - test "does not show wishlist records", %{ - conn: conn, - wishlist: wishlist_records - } do + test "does not show wishlist records", %{conn: conn} do + wishlist_records = Enum.map(1..3, fn _ -> record(%{purchased_at: nil}) end) session = visit(conn, ~p"/collection") for record <- wishlist_records do diff --git a/test/music_library_web/live/stats_live/index_test.exs b/test/music_library_web/live/stats_live/index_test.exs index 5187c04e..0b117a5c 100644 --- a/test/music_library_web/live/stats_live/index_test.exs +++ b/test/music_library_web/live/stats_live/index_test.exs @@ -71,6 +71,81 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do |> assert_has("dd", wishlist |> length() |> Integer.to_string()) end + test "it displays records for the current date in the 'On This Day' section", %{ + conn: conn, + collection: collection + } do + today = Date.utc_today() + yesterday = Date.add(today, -1) + + record_today = + List.first(collection) + |> Records.change_record(%{ + release_date: Date.to_iso8601(today), + purchased_at: DateTime.utc_now() + }) + |> Repo.update!() + + record_yesterday = + List.last(collection) + |> Records.change_record(%{ + release_date: Date.to_iso8601(yesterday), + purchased_at: DateTime.utc_now() + }) + |> Repo.update!() + + session = conn |> visit("/") + + assert_has(session, "h1", "On This day") + + assert_has(session, "##{record_today.id} h2", escape(record_today.title)) + + refute_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title)) + end + + test "it updates the 'On This Day' records when the date is changed", %{ + conn: conn, + collection: collection + } do + today = Date.utc_today() + yesterday = Date.add(today, -1) + + record_today = + List.first(collection) + |> Records.change_record(%{ + release_date: Date.to_iso8601(today), + purchased_at: DateTime.utc_now() + }) + |> Repo.update!() + + record_yesterday = + List.last(collection) + |> Records.change_record(%{ + release_date: Date.to_iso8601(yesterday), + purchased_at: DateTime.utc_now() + }) + |> Repo.update!() + + session = conn |> visit("/") + + assert_has(session, "##{record_today.id} h2", escape(record_today.title)) + + refute_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title)) + + session + |> unwrap(fn view -> + view + |> form("[phx-change='set_current_date']", %{"current_date" => Date.to_iso8601(yesterday)}) + |> render_change() + end) + + refute_has(session, "##{record_today.id} h2", escape(record_today.title)) + + assert_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title)) + end + end + + describe "Scrobble activity" do test "it shows the scrobble activity", %{conn: conn} do # In test we don't run the LastFm.Refresh worker, # so we need to interact directly with the LastFm.Feed to have some data @@ -241,78 +316,5 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do assert [wishlisted_record] = Wishlist.search_records("mbid:#{release_group_id}") assert_path(session, ~p"/wishlist/#{wishlisted_record.id}") end - - test "it displays records for the current date in the 'On This Day' section", %{ - conn: conn, - collection: collection - } do - today = Date.utc_today() - yesterday = Date.add(today, -1) - - record_today = - List.first(collection) - |> Records.change_record(%{ - release_date: Date.to_iso8601(today), - purchased_at: DateTime.utc_now() - }) - |> Repo.update!() - - record_yesterday = - List.last(collection) - |> Records.change_record(%{ - release_date: Date.to_iso8601(yesterday), - purchased_at: DateTime.utc_now() - }) - |> Repo.update!() - - session = conn |> visit("/") - - assert_has(session, "h1", "On This day") - - assert_has(session, "##{record_today.id} h2", escape(record_today.title)) - - refute_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title)) - end - - test "it updates the 'On This Day' records when the date is changed", %{ - conn: conn, - collection: collection - } do - today = Date.utc_today() - yesterday = Date.add(today, -1) - - record_today = - List.first(collection) - |> Records.change_record(%{ - release_date: Date.to_iso8601(today), - purchased_at: DateTime.utc_now() - }) - |> Repo.update!() - - record_yesterday = - List.last(collection) - |> Records.change_record(%{ - release_date: Date.to_iso8601(yesterday), - purchased_at: DateTime.utc_now() - }) - |> Repo.update!() - - session = conn |> visit("/") - - assert_has(session, "##{record_today.id} h2", escape(record_today.title)) - - refute_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title)) - - session - |> unwrap(fn view -> - view - |> form("[phx-change='set_current_date']", %{"current_date" => Date.to_iso8601(yesterday)}) - |> render_change() - end) - - refute_has(session, "##{record_today.id} h2", escape(record_today.title)) - - assert_has(session, "##{record_yesterday.id} h2", escape(record_yesterday.title)) - end end end