diff --git a/.gitignore b/.gitignore index 996b81b..9320028 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ npm-debug.log /assets/node_modules/ /priv/uploads +/tmp \ No newline at end of file diff --git a/config/test.exs b/config/test.exs index be278a9..043e354 100644 --- a/config/test.exs +++ b/config/test.exs @@ -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 diff --git a/lib/live_beats/mp3_stat.ex b/lib/live_beats/mp3_stat.ex index e2260c2..2016fb4 100644 --- a/lib/live_beats/mp3_stat.ex +++ b/lib/live_beats/mp3_stat.ex @@ -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(<>), do: bin diff --git a/lib/live_beats_web/live/live_helpers.ex b/lib/live_beats_web/live/live_helpers.ex index 4414f8f..00b497d 100644 --- a/lib/live_beats_web/live/live_helpers.ex +++ b/lib/live_beats_web/live/live_helpers.ex @@ -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 %> diff --git a/lib/live_beats_web/live/profile_live.ex b/lib/live_beats_web/live/profile_live.ex index 42f0950..1eec09d 100644 --- a/lib/live_beats_web/live/profile_live.ex +++ b/lib/live_beats_web/live/profile_live.ex @@ -32,7 +32,7 @@ defmodule LiveBeatsWeb.ProfileLive do <% 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}/>Upload Songs <% end %> diff --git a/test/live_beats_web/live/profile_live_test.exs b/test/live_beats_web/live/profile_live_test.exs new file mode 100644 index 0000000..98720bf --- /dev/null +++ b/test/live_beats_web/live/profile_live_test.exs @@ -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 diff --git a/test/support/fixtures/accounts_fixtures.ex b/test/support/fixtures/accounts_fixtures.ex index 1866289..3bd6b5b 100644 --- a/test/support/fixtures/accounts_fixtures.ex +++ b/test/support/fixtures/accounts_fixtures.ex @@ -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", diff --git a/test/support/fixtures/silence1s.mp3 b/test/support/fixtures/silence1s.mp3 new file mode 100644 index 0000000..fed8dc6 Binary files /dev/null and b/test/support/fixtures/silence1s.mp3 differ