mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-27 02:10:59 +00:00
Test basic uploads
This commit is contained in:
parent
c8a6035a02
commit
dda0cdaa3f
8 changed files with 70 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -30,3 +30,4 @@ npm-debug.log
|
|||
/assets/node_modules/
|
||||
|
||||
/priv/uploads
|
||||
/tmp
|
|
@ -1,5 +1,9 @@
|
|||
import Config
|
||||
|
||||
config :live_beats, :files, [
|
||||
uploads_dir: Path.expand("../tmp/test-uploads", __DIR__),
|
||||
host: [scheme: "http", host: "localhost", port: 4000],
|
||||
]
|
||||
# Configure your database
|
||||
#
|
||||
# The MIX_TEST_PARTITION environment variable can be used
|
||||
|
|
|
@ -65,7 +65,7 @@ defmodule LiveBeats.MP3Stat do
|
|||
parse_frames(major_version, rest, tag_size - ext_header_size, [])
|
||||
end
|
||||
|
||||
defp parse_tag(_), do: %{}
|
||||
defp parse_tag(_), do: {%{}, ""}
|
||||
|
||||
defp decode_synchsafe_integer(<<bin>>), do: bin
|
||||
|
||||
|
|
|
@ -464,11 +464,13 @@ defmodule LiveBeatsWeb.LiveHelpers do
|
|||
|
||||
~H"""
|
||||
<%= if @primary do %>
|
||||
<%= live_patch to: @patch, class: "order-0 inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-purple-600 hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-1 sm:ml-3" do %>
|
||||
<%= live_patch [to: @patch, class: "order-0 inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-purple-600 hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-1 sm:ml-3"] ++
|
||||
assigns_to_attributes(assigns, [:primary, :patch]) do %>
|
||||
<%= render_slot(@inner_block) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= live_patch to: @patch, class: "order-1 inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-0 sm:ml-0 lg:ml-3" do %>
|
||||
<%= live_patch [to: @patch, class: "order-1 inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-0 sm:ml-0 lg:ml-3"] ++
|
||||
assigns_to_attributes(assigns, [:primary, :patch]) do %>
|
||||
<%= render_slot(@inner_block) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -32,7 +32,7 @@ defmodule LiveBeatsWeb.ProfileLive do
|
|||
</.button>
|
||||
<% end %>
|
||||
<%= if @owns_profile? do %>
|
||||
<.button primary patch={profile_path(@current_user, :new)}>
|
||||
<.button id="upload-btn" primary patch={profile_path(@current_user, :new)}>
|
||||
<.icon name={:upload}/><span class="ml-2">Upload Songs</span>
|
||||
</.button>
|
||||
<% end %>
|
||||
|
|
58
test/live_beats_web/live/profile_live_test.exs
Normal file
58
test/live_beats_web/live/profile_live_test.exs
Normal file
|
@ -0,0 +1,58 @@
|
|||
defmodule LiveBeatsWeb.ProfileLiveTest do
|
||||
use LiveBeatsWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import LiveBeats.AccountsFixtures
|
||||
|
||||
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
|
||||
|
||||
test "profile page", %{conn: conn, current_user: current_user} do
|
||||
{:ok, lv, dead_html} = live(conn, LiveHelpers.profile_path(current_user))
|
||||
|
||||
assert dead_html =~ "chrismccord's beats"
|
||||
|
||||
assert lv
|
||||
|> element("#upload-btn")
|
||||
|> render_click()
|
||||
|
||||
assert render(lv) =~ "Add Songs"
|
||||
|
||||
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"
|
||||
}
|
||||
])
|
||||
|
||||
assert render_upload(mp3, "my.mp3") =~ "can't be blank"
|
||||
|
||||
[%{"ref" => ref}] = mp3.entries
|
||||
|
||||
refute lv
|
||||
|> form("#song-form")
|
||||
|> render_change(%{
|
||||
"_target" => ["songs", ref, "artist"],
|
||||
"songs" => %{
|
||||
ref => %{"artist" => "Anon", "attribution" => "", "title" => "silence1s"}
|
||||
}
|
||||
}) =~ "can't be blank"
|
||||
|
||||
assert {:ok, _new_lv, html} =
|
||||
lv |> form("#song-form") |> render_submit() |> follow_redirect(conn)
|
||||
|
||||
assert_redirected(lv, "/#{current_user.username}")
|
||||
assert html =~ "1 song(s) uploaded"
|
||||
|
||||
assert html =~ "silence1s"
|
||||
end
|
||||
end
|
|
@ -27,7 +27,7 @@ defmodule LiveBeats.AccountsFixtures do
|
|||
"html_url" => "https://github.com/chrismccord",
|
||||
"id" => 1234,
|
||||
"location" => "Charlotte, NC",
|
||||
"login" => "chrismccord",
|
||||
"login" => attrs[:username] || "chrismccord",
|
||||
"name" => "Chris McCord",
|
||||
"node_id" => "slkdfjsklfjsf",
|
||||
"organizations_url" => "https://api.github.com/users/chrismccord/orgs",
|
||||
|
|
BIN
test/support/fixtures/silence1s.mp3
Normal file
BIN
test/support/fixtures/silence1s.mp3
Normal file
Binary file not shown.
Loading…
Reference in a new issue