mirror of
https://github.com/fly-apps/live_beats.git
synced 2025-02-17 00:25:14 +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/
|
/assets/node_modules/
|
||||||
|
|
||||||
/priv/uploads
|
/priv/uploads
|
||||||
|
/tmp
|
|
@ -1,5 +1,9 @@
|
||||||
import Config
|
import Config
|
||||||
|
|
||||||
|
config :live_beats, :files, [
|
||||||
|
uploads_dir: Path.expand("../tmp/test-uploads", __DIR__),
|
||||||
|
host: [scheme: "http", host: "localhost", port: 4000],
|
||||||
|
]
|
||||||
# Configure your database
|
# Configure your database
|
||||||
#
|
#
|
||||||
# The MIX_TEST_PARTITION environment variable can be used
|
# 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, [])
|
parse_frames(major_version, rest, tag_size - ext_header_size, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_tag(_), do: %{}
|
defp parse_tag(_), do: {%{}, ""}
|
||||||
|
|
||||||
defp decode_synchsafe_integer(<<bin>>), do: bin
|
defp decode_synchsafe_integer(<<bin>>), do: bin
|
||||||
|
|
||||||
|
|
|
@ -464,11 +464,13 @@ defmodule LiveBeatsWeb.LiveHelpers do
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<%= if @primary do %>
|
<%= 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) %>
|
<%= render_slot(@inner_block) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% 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) %>
|
<%= render_slot(@inner_block) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -32,7 +32,7 @@ defmodule LiveBeatsWeb.ProfileLive do
|
||||||
</.button>
|
</.button>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= if @owns_profile? do %>
|
<%= 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>
|
<.icon name={:upload}/><span class="ml-2">Upload Songs</span>
|
||||||
</.button>
|
</.button>
|
||||||
<% end %>
|
<% 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",
|
"html_url" => "https://github.com/chrismccord",
|
||||||
"id" => 1234,
|
"id" => 1234,
|
||||||
"location" => "Charlotte, NC",
|
"location" => "Charlotte, NC",
|
||||||
"login" => "chrismccord",
|
"login" => attrs[:username] || "chrismccord",
|
||||||
"name" => "Chris McCord",
|
"name" => "Chris McCord",
|
||||||
"node_id" => "slkdfjsklfjsf",
|
"node_id" => "slkdfjsklfjsf",
|
||||||
"organizations_url" => "https://api.github.com/users/chrismccord/orgs",
|
"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