Extract LiveView async test helper
This commit is contained in:
@@ -2,7 +2,9 @@ defmodule MusicLibraryWeb.Components.ChatTest do
|
|||||||
use MusicLibraryWeb.ConnCase, async: false
|
use MusicLibraryWeb.ConnCase, async: false
|
||||||
|
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
import Phoenix.LiveViewTest
|
|
||||||
|
import Phoenix.LiveViewTest,
|
||||||
|
only: [element: 2, form: 3, live: 2, render: 1, render_click: 1, render_submit: 1]
|
||||||
|
|
||||||
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
||||||
alias MusicBrainz.Fixtures.ReleaseGroup
|
alias MusicBrainz.Fixtures.ReleaseGroup
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
|
|
||||||
import Phoenix.LiveViewTest,
|
import Phoenix.LiveViewTest,
|
||||||
only: [element: 2, render: 1, render_async: 1, render_change: 2, render_click: 1]
|
only: [element: 2, render: 1, render_change: 2, render_click: 1]
|
||||||
|
|
||||||
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
||||||
alias MusicLibrary.Secrets
|
alias MusicLibrary.Secrets
|
||||||
@@ -83,7 +83,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("div[data-part=inner-prefix]", text: "Finished at")
|
|> assert_has("div[data-part=inner-prefix]", text: "Finished at")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element("button[phx-click=scrobble_release][phx-target]")
|
|> element("button[phx-click=scrobble_release][phx-target]")
|
||||||
@@ -116,7 +116,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(@sheet_form)
|
|> element(@sheet_form)
|
||||||
@@ -136,7 +136,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(@sheet_form)
|
|> element(@sheet_form)
|
||||||
@@ -172,7 +172,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(@sheet_form)
|
|> element(@sheet_form)
|
||||||
@@ -197,7 +197,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(@sheet_form)
|
|> element(@sheet_form)
|
||||||
@@ -221,7 +221,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> refute_has("button", text: "Scrobble selected")
|
|> refute_has("button", text: "Scrobble selected")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(@sheet_form)
|
|> element(@sheet_form)
|
||||||
@@ -250,7 +250,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(@sheet_form)
|
|> element(@sheet_form)
|
||||||
@@ -267,7 +267,7 @@ defmodule MusicLibraryWeb.Components.ReleaseTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(@sheet_form)
|
|> element(@sheet_form)
|
||||||
@@ -323,8 +323,7 @@ end
|
|||||||
defmodule MusicLibraryWeb.Components.ReleaseTest.ShowPrintTest do
|
defmodule MusicLibraryWeb.Components.ReleaseTest.ShowPrintTest do
|
||||||
use MusicLibraryWeb.ConnCase, async: false
|
use MusicLibraryWeb.ConnCase, async: false
|
||||||
|
|
||||||
import Phoenix.LiveViewTest,
|
import Phoenix.LiveViewTest, only: [render: 1]
|
||||||
only: [render: 1, render_async: 1]
|
|
||||||
|
|
||||||
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
||||||
alias Req.Test
|
alias Req.Test
|
||||||
|
|||||||
@@ -3,7 +3,15 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
|
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
|
|
||||||
import Phoenix.LiveViewTest
|
import Phoenix.LiveViewTest,
|
||||||
|
only: [
|
||||||
|
element: 2,
|
||||||
|
file_input: 4,
|
||||||
|
form: 2,
|
||||||
|
render_click: 1,
|
||||||
|
render_submit: 1,
|
||||||
|
render_upload: 2
|
||||||
|
]
|
||||||
|
|
||||||
alias LastFm.Fixtures
|
alias LastFm.Fixtures
|
||||||
alias MusicLibrary.Artists
|
alias MusicLibrary.Artists
|
||||||
@@ -48,7 +56,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("span", "No scrobbles")
|
|> assert_has("span", "No scrobbles")
|
||||||
|> assert_has("dt", "Biography")
|
|> assert_has("dt", "Biography")
|
||||||
end
|
end
|
||||||
@@ -74,7 +82,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("dt", "Biography")
|
|> assert_has("dt", "Biography")
|
||||||
|> assert_has("span", "Wikipedia")
|
|> assert_has("span", "Wikipedia")
|
||||||
|> assert_has("p", text: "English musician")
|
|> assert_has("p", text: "English musician")
|
||||||
@@ -96,7 +104,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("span", "No scrobbles")
|
|> assert_has("span", "No scrobbles")
|
||||||
|> refute_has("summary", "Biography")
|
|> refute_has("summary", "Biography")
|
||||||
|> assert_has("div", "Error loading biography")
|
|> assert_has("div", "Error loading biography")
|
||||||
@@ -118,7 +126,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("span", "United Kingdom")
|
|> assert_has("span", "United Kingdom")
|
||||||
|> assert_has("span", "🇬🇧")
|
|> assert_has("span", "🇬🇧")
|
||||||
|> assert_has("code", artist_musicbrainz_id)
|
|> assert_has("code", artist_musicbrainz_id)
|
||||||
@@ -150,7 +158,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
|> visit(~p"/artists/#{artist_musicbrainz_id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("#collection p", escape(collection_record.title))
|
|> assert_has("#collection p", escape(collection_record.title))
|
||||||
|> assert_has("#wishlist p", escape(wishlist_record.title))
|
|> assert_has("#wishlist p", escape(wishlist_record.title))
|
||||||
|> refute_has("#collection p", escape(other_collection_record.title))
|
|> refute_has("#collection p", escape(other_collection_record.title))
|
||||||
@@ -168,7 +176,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
} do
|
} do
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("#artist-info-form")
|
|> assert_has("#artist-info-form")
|
||||||
|> assert_has("label", text: "Search for artist image online")
|
|> assert_has("label", text: "Search for artist image online")
|
||||||
end
|
end
|
||||||
@@ -185,9 +193,9 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> click_button("#image-search-button", "Search")
|
|> click_button("#image-search-button", "Search")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
html = Phoenix.LiveViewTest.render(session.view)
|
html = Phoenix.LiveViewTest.render(session.view)
|
||||||
assert html =~ "https://thumbnails.example.com/raven-thumb.jpg"
|
assert html =~ "https://thumbnails.example.com/raven-thumb.jpg"
|
||||||
@@ -205,9 +213,9 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> click_button("#image-search-button", "Search")
|
|> click_button("#image-search-button", "Search")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
html = Phoenix.LiveViewTest.render(session.view)
|
html = Phoenix.LiveViewTest.render(session.view)
|
||||||
assert html =~ "Search failed"
|
assert html =~ "Search failed"
|
||||||
@@ -220,7 +228,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
} do
|
} do
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
image =
|
image =
|
||||||
file_input(view, "#artist-info-form", :image_data, [
|
file_input(view, "#artist-info-form", :image_data, [
|
||||||
@@ -260,9 +268,9 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
|> visit(~p"/artists/#{musicbrainz_id}/edit")
|
||||||
|> unwrap(fn view -> render_async(view, 500) end)
|
|> render_async(500)
|
||||||
|> click_button("#image-search-button", "Search")
|
|> click_button("#image-search-button", "Search")
|
||||||
|> unwrap(fn view -> render_async(view, 500) end)
|
|> render_async(500)
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
view
|
view
|
||||||
|> element(
|
|> element(
|
||||||
@@ -270,7 +278,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|
|||||||
)
|
)
|
||||||
|> render_click()
|
|> render_click()
|
||||||
end)
|
end)
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
updated = Artists.get_artist_info!(artist_info.id)
|
updated = Artists.get_artist_info!(artist_info.id)
|
||||||
assert updated.image_data_hash != artist_info.image_data_hash
|
assert updated.image_data_hash != artist_info.image_data_hash
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("a", "Edit")
|
|> assert_has("a", "Edit")
|
||||||
|> click_link("Edit")
|
|> click_link("Edit")
|
||||||
|> assert_path(~p"/collection/#{record}/show/edit")
|
|> assert_path(~p"/collection/#{record}/show/edit")
|
||||||
@@ -43,7 +43,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("h2", escape(record.title))
|
|> assert_has("h2", escape(record.title))
|
||||||
|> assert_has("p", record.release_date)
|
|> assert_has("p", record.release_date)
|
||||||
|> assert_has("p", format_label(record.format))
|
|> assert_has("p", format_label(record.format))
|
||||||
@@ -82,7 +82,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
|
|||||||
conn
|
conn
|
||||||
|> visit(~p"/collection/#{record.id}")
|
|> visit(~p"/collection/#{record.id}")
|
||||||
|> assert_has("button", "Show Tracks")
|
|> assert_has("button", "Show Tracks")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("a", "Connect Last.fm")
|
|> assert_has("a", "Connect Last.fm")
|
||||||
|
|
||||||
release =
|
release =
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ defmodule MusicLibraryWeb.MaintenanceLive.IndexTest do
|
|||||||
test "async status resolves to :not_connected when no session key is stored", %{conn: conn} do
|
test "async status resolves to :not_connected when no session key is stored", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/maintenance")
|
|> visit(~p"/maintenance")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("span", "Not connected")
|
|> assert_has("span", "Not connected")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ defmodule MusicLibraryWeb.MaintenanceLive.IndexTest do
|
|||||||
|
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/maintenance")
|
|> visit(~p"/maintenance")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("span", "Connected as alice")
|
|> assert_has("span", "Connected as alice")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ReleaseShowTest do
|
|||||||
test "renders the scrobble UI for the release", %{conn: conn} do
|
test "renders the scrobble UI for the release", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/scrobble/#{@rg_id}/releases/#{@release_id}")
|
|> visit(~p"/scrobble/#{@rg_id}/releases/#{@release_id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("h2", text: "Marbles")
|
|> assert_has("h2", text: "Marbles")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ defmodule MusicLibraryWeb.ScrobbleLive.ReleaseShowTest do
|
|||||||
test "sets the page title once the release loads", %{conn: conn} do
|
test "sets the page title once the release loads", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit(~p"/scrobble/#{@rg_id}/releases/#{@release_id}")
|
|> visit(~p"/scrobble/#{@rg_id}/releases/#{@release_id}")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("title", text: "Marillion - Marbles")
|
|> assert_has("title", text: "Marillion - Marbles")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
test "renders no album rows when no scrobbles exist", %{conn: conn} do
|
test "renders no album rows when no scrobbles exist", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> refute_has("#top-albums img")
|
|> refute_has("#top-albums img")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -56,7 +56,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
test "shows the album title, linked artist, and play count", %{conn: conn} do
|
test "shows the album title, linked artist, and play count", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has("#top-albums p", text: "Marbles")
|
|> assert_has("#top-albums p", text: "Marbles")
|
||||||
|> assert_has(~s|#top-albums a[href="/artists/#{@marillion_mbid}"]|, text: "Marillion")
|
|> assert_has(~s|#top-albums a[href="/artists/#{@marillion_mbid}"]|, text: "Marillion")
|
||||||
|> assert_has("#top-albums span", text: "2")
|
|> assert_has("#top-albums span", text: "2")
|
||||||
@@ -65,7 +65,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
test "uses the Last.fm cover URL when no matching record exists", %{conn: conn} do
|
test "uses the Last.fm cover URL when no matching record exists", %{conn: conn} do
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|> assert_has(~s|#top-albums img[src="https://example.com/cover.jpg"]|)
|
|> assert_has(~s|#top-albums img[src="https://example.com/cover.jpg"]|)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
html = Phoenix.LiveViewTest.render(session.view)
|
html = Phoenix.LiveViewTest.render(session.view)
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
html = Phoenix.LiveViewTest.render(session.view)
|
html = Phoenix.LiveViewTest.render(session.view)
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
html = Phoenix.LiveViewTest.render(session.view)
|
html = Phoenix.LiveViewTest.render(session.view)
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
session
|
session
|
||||||
|> assert_has("##{"top-album-#{@marbles_release_id}"}")
|
|> assert_has("##{"top-album-#{@marbles_release_id}"}")
|
||||||
@@ -176,7 +176,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
html = Phoenix.LiveViewTest.render(session.view)
|
html = Phoenix.LiveViewTest.render(session.view)
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
session =
|
session =
|
||||||
conn
|
conn
|
||||||
|> visit("/")
|
|> visit("/")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
|
|
||||||
refute_has(session, "#top-albums", text: "Older Album")
|
refute_has(session, "#top-albums", text: "Older Album")
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ defmodule MusicLibraryWeb.StatsLive.TopAlbumsTest do
|
|||||||
|> within("#top-albums", fn s ->
|
|> within("#top-albums", fn s ->
|
||||||
s
|
s
|
||||||
|> click_button("30d")
|
|> click_button("30d")
|
||||||
|> unwrap(&render_async/1)
|
|> render_async()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
assert_has(session, "#top-albums", text: "Older Album")
|
assert_has(session, "#top-albums", text: "Older Album")
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ defmodule MusicLibraryWeb.LiveHelpers.RecordActionsTest do
|
|||||||
use Oban.Testing, repo: MusicLibrary.BackgroundRepo
|
use Oban.Testing, repo: MusicLibrary.BackgroundRepo
|
||||||
|
|
||||||
import MusicLibrary.Fixtures.Records
|
import MusicLibrary.Fixtures.Records
|
||||||
import Phoenix.LiveViewTest
|
|
||||||
|
import Phoenix.LiveViewTest, only: [live: 2, render: 1, render_click: 3]
|
||||||
|
|
||||||
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
alias MusicBrainz.Fixtures.Release, as: ReleaseFixtures
|
||||||
alias MusicBrainz.Fixtures.ReleaseGroup
|
alias MusicBrainz.Fixtures.ReleaseGroup
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ defmodule MusicLibraryWeb.ConnCase do
|
|||||||
import Phoenix.LiveViewTest,
|
import Phoenix.LiveViewTest,
|
||||||
# The default endpoint for testing
|
# The default endpoint for testing
|
||||||
only: [
|
only: [
|
||||||
render_async: 1,
|
|
||||||
render_change: 1,
|
render_change: 1,
|
||||||
render_click: 3,
|
render_click: 3,
|
||||||
render_hook: 2,
|
render_hook: 2,
|
||||||
|
|||||||
@@ -1,10 +1,42 @@
|
|||||||
defmodule MusicLibraryWeb.LiveTestHelpers do
|
defmodule MusicLibraryWeb.LiveTestHelpers do
|
||||||
@moduledoc false
|
@moduledoc """
|
||||||
|
Shared helpers for LiveView tests.
|
||||||
|
|
||||||
|
These helpers sit alongside PhoenixTest and Phoenix.LiveViewTest so tests can
|
||||||
|
keep PhoenixTest sessions in the pipeline while still reaching for lower-level
|
||||||
|
LiveView interactions when PhoenixTest does not cover them directly.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Escapes text for assertions against rendered HTML.
|
||||||
|
"""
|
||||||
def escape(string) do
|
def escape(string) do
|
||||||
LazyHTML.html_escape(string)
|
LazyHTML.html_escape(string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Waits for LiveView async work to finish.
|
||||||
|
|
||||||
|
Accepts either a PhoenixTest session, returning the session for continued
|
||||||
|
piping, or a raw LiveView view/element, returning the rendered HTML from
|
||||||
|
`Phoenix.LiveViewTest.render_async/2`.
|
||||||
|
"""
|
||||||
|
def render_async(
|
||||||
|
session_or_view,
|
||||||
|
timeout \\ Application.fetch_env!(:ex_unit, :assert_receive_timeout)
|
||||||
|
)
|
||||||
|
|
||||||
|
def render_async(%{view: %Phoenix.LiveViewTest.View{}} = session, timeout) do
|
||||||
|
PhoenixTest.unwrap(session, &Phoenix.LiveViewTest.render_async(&1, timeout))
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_async(view_or_element, timeout) do
|
||||||
|
Phoenix.LiveViewTest.render_async(view_or_element, timeout)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Dispatches a hook event to an element inside a PhoenixTest session.
|
||||||
|
"""
|
||||||
def trigger_hook(session, selector, hook, params \\ %{}) do
|
def trigger_hook(session, selector, hook, params \\ %{}) do
|
||||||
session
|
session
|
||||||
|> PhoenixTest.unwrap(fn view ->
|
|> PhoenixTest.unwrap(fn view ->
|
||||||
|
|||||||
Reference in New Issue
Block a user