Add tests for On This Day functionality
This commit is contained in:
@@ -241,5 +241,90 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
|||||||
assert [wishlisted_record] = Wishlist.search_records("mbid:#{release_group_id}")
|
assert [wishlisted_record] = Wishlist.search_records("mbid:#{release_group_id}")
|
||||||
assert_path(session, ~p"/wishlist/#{wishlisted_record.id}")
|
assert_path(session, ~p"/wishlist/#{wishlisted_record.id}")
|
||||||
end
|
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", text: "On This day")
|
||||||
|
|
||||||
|
assert_has(session, "#records_on_this_day-#{record_today.id}",
|
||||||
|
text: escape(record_today.title)
|
||||||
|
)
|
||||||
|
|
||||||
|
refute_has(session, "#records_on_this_day-#{record_yesterday.id}",
|
||||||
|
text: 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, "#records_on_this_day-#{record_today.id}",
|
||||||
|
text: escape(record_today.title)
|
||||||
|
)
|
||||||
|
|
||||||
|
refute_has(session, "#records_on_this_day-#{record_yesterday.id}",
|
||||||
|
text: 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, "#records_on_this_day-#{record_today.id}",
|
||||||
|
text: escape(record_today.title)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_has(session, "#records_on_this_day-#{record_yesterday.id}",
|
||||||
|
text: escape(record_yesterday.title)
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,7 +27,15 @@ defmodule MusicLibraryWeb.ConnCase do
|
|||||||
|
|
||||||
import Phoenix.LiveViewTest,
|
import Phoenix.LiveViewTest,
|
||||||
# The default endpoint for testing
|
# The default endpoint for testing
|
||||||
only: [render: 1, render_async: 1, render_hook: 2, render_hook: 3, element: 2, element: 3]
|
only: [
|
||||||
|
render_async: 1,
|
||||||
|
render_change: 1,
|
||||||
|
render_hook: 2,
|
||||||
|
render_hook: 3,
|
||||||
|
element: 2,
|
||||||
|
element: 3,
|
||||||
|
form: 3
|
||||||
|
]
|
||||||
|
|
||||||
import PhoenixTest
|
import PhoenixTest
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
|
|||||||
Reference in New Issue
Block a user