2021-12-14 20:19:03 +00:00
|
|
|
defmodule LiveBeatsWeb.ProfileLiveTest do
|
|
|
|
use LiveBeatsWeb.ConnCase
|
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
import LiveBeats.AccountsFixtures
|
|
|
|
|
2021-12-14 20:29:07 +00:00
|
|
|
alias LiveBeats.MediaLibrary
|
2021-12-14 20:19:03 +00:00
|
|
|
alias LiveBeatsWeb.LiveHelpers
|
|
|
|
|
|
|
|
setup %{conn: conn} do
|
|
|
|
current_user = user_fixture(%{username: "chrismccord"})
|
|
|
|
user2 = user_fixture(%{username: "mrkurt"})
|
|
|
|
conn = log_in_user(conn, current_user)
|
|
|
|
{:ok, conn: conn, current_user: current_user, user2: user2}
|
|
|
|
end
|
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
describe "own profile" do
|
|
|
|
test "profile page uploads", %{conn: conn, current_user: current_user} do
|
|
|
|
profile = MediaLibrary.get_profile!(current_user)
|
|
|
|
{:ok, lv, dead_html} = live(conn, LiveHelpers.profile_path(current_user))
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
assert dead_html =~ "chrismccord's beats"
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
# uploads
|
|
|
|
assert lv
|
2021-12-16 17:19:02 +00:00
|
|
|
|> element("#upload-btn")
|
|
|
|
|> render_click()
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
assert render(lv) =~ "Add Songs"
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
mp3 =
|
|
|
|
file_input(lv, "#song-form", :mp3, [
|
|
|
|
%{
|
|
|
|
last_modified: 1_594_171_879_000,
|
|
|
|
name: "my.mp3",
|
|
|
|
content: File.read!("test/support/fixtures/silence1s.mp3"),
|
|
|
|
type: "audio/mpeg"
|
|
|
|
}
|
|
|
|
])
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
assert render_upload(mp3, "my.mp3") =~ "can't be blank"
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
[%{"ref" => ref}] = mp3.entries
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
refute lv
|
2021-12-16 17:19:02 +00:00
|
|
|
|> form("#song-form")
|
|
|
|
|> render_change(%{
|
|
|
|
"_target" => ["songs", ref, "artist"],
|
|
|
|
"songs" => %{
|
|
|
|
ref => %{"artist" => "Anon", "attribution" => "", "title" => "silence1s"}
|
|
|
|
}
|
|
|
|
}) =~ "can't be blank"
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
assert {:ok, new_lv, html} =
|
2021-12-16 17:19:02 +00:00
|
|
|
lv |> form("#song-form") |> render_submit() |> follow_redirect(conn)
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
assert_redirected(lv, "/#{current_user.username}")
|
|
|
|
assert html =~ "1 song(s) uploaded"
|
2021-12-14 20:19:03 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
assert html =~ "silence1s"
|
2021-12-14 20:29:07 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
# deleting songs
|
2021-12-14 20:29:07 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
song = MediaLibrary.get_first_song(profile)
|
|
|
|
assert new_lv |> element("#delete-modal-#{song.id}-confirm") |> render_click()
|
2021-12-14 20:29:07 +00:00
|
|
|
|
2021-12-14 20:31:02 +00:00
|
|
|
{:ok, refreshed_lv, _} = live(conn, LiveHelpers.profile_path(current_user))
|
|
|
|
refute render(refreshed_lv) =~ "silence1s"
|
|
|
|
end
|
2021-12-14 20:40:46 +00:00
|
|
|
|
|
|
|
test "invalid uploads" do
|
|
|
|
# TODO
|
|
|
|
end
|
2021-12-14 20:31:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "viewing other profiles" do
|
|
|
|
# TODO
|
2021-12-14 20:19:03 +00:00
|
|
|
end
|
|
|
|
end
|