Test basic uploads

This commit is contained in:
Chris McCord 2021-12-14 15:19:03 -05:00
parent c8a6035a02
commit dda0cdaa3f
8 changed files with 70 additions and 5 deletions

1
.gitignore vendored
View file

@ -30,3 +30,4 @@ npm-debug.log
/assets/node_modules/
/priv/uploads
/tmp

View file

@ -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

View file

@ -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

View file

@ -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 %>

View file

@ -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 %>

View 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&#39;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&#39;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&#39;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

View file

@ -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",

Binary file not shown.