More tests
This commit is contained in:
parent
a9870fb5d7
commit
8cc4783fde
4 changed files with 64 additions and 27 deletions
|
|
@ -340,7 +340,7 @@ defmodule PinchflatWeb.CoreComponents do
|
|||
end)
|
||||
|
||||
~H"""
|
||||
<div x-data={"{ enabled: #{@checked}}"} class="">
|
||||
<div x-data={"{ enabled: #{@checked} }"} class="" phx-update="ignore" id={"#{@id}-wrapper"}>
|
||||
<.label :if={@label} for={@id}>
|
||||
<%= @label %>
|
||||
<span :if={@label_suffix} class="text-xs text-bodydark"><%= @label_suffix %></span>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule PinchflatWeb.Sources.IndexTableLive do
|
|||
alias Pinchflat.Sources.Source
|
||||
alias Pinchflat.Media.MediaItem
|
||||
|
||||
# TODO: test (and maybe remove existing index tests)
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<.table rows={@sources} table_class="text-white">
|
||||
|
|
@ -67,15 +66,15 @@ defmodule PinchflatWeb.Sources.IndexTableLive do
|
|||
source = Sources.get_source!(params["id"])
|
||||
should_enable = params["value"] == "true"
|
||||
|
||||
{:ok, new_source} = Sources.update_source(source, %{enabled: should_enable})
|
||||
# Trying to be efficient with the update. Let's see if it pays off
|
||||
updated_sources = Enum.map(socket.assigns.sources, fn s -> if s.id == new_source.id, do: new_source, else: s end)
|
||||
{:ok, _} = Sources.update_source(source, %{enabled: should_enable})
|
||||
|
||||
{:noreply, assign(socket, sources: updated_sources)}
|
||||
# NOTE: I'm not re-rendering the view here since, at least in this case, the UI's state
|
||||
# tracking mechanisms are good enough
|
||||
{:noreply, assign(socket, %{sources: get_sources()})}
|
||||
end
|
||||
|
||||
defp get_sources do
|
||||
source_query =
|
||||
query =
|
||||
from s in Source,
|
||||
as: :source,
|
||||
inner_join: mp in assoc(s, :media_profile),
|
||||
|
|
@ -101,6 +100,6 @@ defmodule PinchflatWeb.Sources.IndexTableLive do
|
|||
)
|
||||
}
|
||||
|
||||
Repo.all(source_query)
|
||||
Repo.all(query)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,27 +34,10 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all sources", %{conn: conn} do
|
||||
source = source_fixture()
|
||||
# Most of the tests are in `index_table_list_test.exs`
|
||||
test "returns 200", %{conn: conn} do
|
||||
conn = get(conn, ~p"/sources")
|
||||
|
||||
assert html_response(conn, 200) =~ "Sources"
|
||||
assert html_response(conn, 200) =~ source.custom_name
|
||||
end
|
||||
|
||||
test "omits sources that have marked_for_deletion_at set", %{conn: conn} do
|
||||
source = source_fixture(marked_for_deletion_at: DateTime.utc_now())
|
||||
conn = get(conn, ~p"/sources")
|
||||
|
||||
refute html_response(conn, 200) =~ source.custom_name
|
||||
end
|
||||
|
||||
test "omits sources who's media profile has marked_for_deletion_at set", %{conn: conn} do
|
||||
media_profile = media_profile_fixture(marked_for_deletion_at: DateTime.utc_now())
|
||||
source = source_fixture(media_profile_id: media_profile.id)
|
||||
conn = get(conn, ~p"/sources")
|
||||
|
||||
refute html_response(conn, 200) =~ source.custom_name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
defmodule PinchflatWeb.Sources.IndexTableLiveTest do
|
||||
use PinchflatWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Pinchflat.SourcesFixtures
|
||||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Sources.Source
|
||||
alias PinchflatWeb.Sources.IndexTableLive
|
||||
|
||||
describe "initial rendering" do
|
||||
test "lists all sources", %{conn: conn} do
|
||||
source = source_fixture()
|
||||
|
||||
{:ok, _view, html} = live_isolated(conn, IndexTableLive)
|
||||
|
||||
assert html =~ source.custom_name
|
||||
end
|
||||
|
||||
test "omits sources that have marked_for_deletion_at set", %{conn: conn} do
|
||||
source = source_fixture(marked_for_deletion_at: DateTime.utc_now())
|
||||
|
||||
{:ok, _view, html} = live_isolated(conn, IndexTableLive)
|
||||
|
||||
refute html =~ source.custom_name
|
||||
end
|
||||
|
||||
test "omits sources who's media profile has marked_for_deletion_at set", %{conn: conn} do
|
||||
media_profile = media_profile_fixture(marked_for_deletion_at: DateTime.utc_now())
|
||||
source = source_fixture(media_profile_id: media_profile.id)
|
||||
|
||||
{:ok, _view, html} = live_isolated(conn, IndexTableLive)
|
||||
|
||||
refute html =~ source.custom_name
|
||||
end
|
||||
end
|
||||
|
||||
describe "when a source is enabled or disabled" do
|
||||
test "updates the source's enabled status", %{conn: conn} do
|
||||
source = source_fixture(enabled: true)
|
||||
{:ok, view, _html} = live_isolated(conn, IndexTableLive)
|
||||
|
||||
params = %{
|
||||
"event" => "toggle_enabled",
|
||||
"id" => source.id,
|
||||
"value" => "false"
|
||||
}
|
||||
|
||||
# Send an event to the server directly
|
||||
render_change(view, "formless-input", params)
|
||||
|
||||
assert %{enabled: false} = Repo.get!(Source, source.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue