pass container live test

This commit is contained in:
shibao 2022-02-17 20:19:35 -05:00
parent b4968e92dc
commit f6f30409a5

View File

@ -6,8 +6,9 @@ defmodule CanneryWeb.ContainerLiveTest do
use CanneryWeb.ConnCase use CanneryWeb.ConnCase
import Phoenix.LiveViewTest import Phoenix.LiveViewTest
import CanneryWeb.Gettext import CanneryWeb.Gettext
alias Cannery.Containers
@moduletag :containers_live @moduletag :container_live_test
@create_attrs %{ @create_attrs %{
"desc" => "some desc", "desc" => "some desc",
@ -25,18 +26,18 @@ defmodule CanneryWeb.ContainerLiveTest do
# @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil} # @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
defp create_container(%{current_user: current_user}) do defp create_container(%{current_user: current_user}) do
container = container_fixture(current_user) container = container_fixture(@create_attrs, current_user)
%{container: container} %{container: container}
end end
describe "Index" do describe "Index" do
setup [:create_container] setup [:register_and_log_in_user, :create_container]
test "lists all containers", %{conn: conn, container: container} do test "lists all containers", %{conn: conn, container: container} do
{:ok, _index_live, html} = live(conn, Routes.container_index_path(conn, :index)) {:ok, _index_live, html} = live(conn, Routes.container_index_path(conn, :index))
assert html =~ gettext("Containers") assert html =~ gettext("Containers")
assert html =~ container.desc assert html =~ container.location
end end
test "saves new container", %{conn: conn, container: container} do test "saves new container", %{conn: conn, container: container} do
@ -58,10 +59,14 @@ defmodule CanneryWeb.ContainerLiveTest do
|> follow_redirect(conn, Routes.container_index_path(conn, :index)) |> follow_redirect(conn, Routes.container_index_path(conn, :index))
assert html =~ dgettext("prompts", "%{name} created successfully", name: container.name) assert html =~ dgettext("prompts", "%{name} created successfully", name: container.name)
assert html =~ "some desc" assert html =~ "some location"
end end
test "updates container in listing", %{conn: conn, container: container} do test "updates container in listing", %{
conn: conn,
current_user: current_user,
container: container
} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index)) {:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
assert index_live |> element("[data-qa=\"edit-#{container.id}\"]") |> render_click() =~ assert index_live |> element("[data-qa=\"edit-#{container.id}\"]") |> render_click() =~
@ -79,8 +84,9 @@ defmodule CanneryWeb.ContainerLiveTest do
|> render_submit() |> render_submit()
|> follow_redirect(conn, Routes.container_index_path(conn, :index)) |> follow_redirect(conn, Routes.container_index_path(conn, :index))
container = container.id |> Containers.get_container!(current_user)
assert html =~ dgettext("prompts", "%{name} updated successfully", name: container.name) assert html =~ dgettext("prompts", "%{name} updated successfully", name: container.name)
assert html =~ "some updated desc" assert html =~ "some updated location"
end end
test "deletes container in listing", %{conn: conn, container: container} do test "deletes container in listing", %{conn: conn, container: container} do
@ -92,16 +98,20 @@ defmodule CanneryWeb.ContainerLiveTest do
end end
describe "Show" do describe "Show" do
setup [:create_container] setup [:register_and_log_in_user, :create_container]
test "displays container", %{conn: conn, container: container} do test "displays container", %{conn: conn, container: container} do
{:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container)) {:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
assert html =~ gettext("Show Container") assert html =~ gettext("Show Container")
assert html =~ container.desc assert html =~ container.location
end end
test "updates container within modal", %{conn: conn, container: container} do test "updates container within modal", %{
conn: conn,
current_user: current_user,
container: container
} do
{:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container)) {:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container))
assert show_live |> element("[data-qa=\"edit\"]") |> render_click() =~ assert show_live |> element("[data-qa=\"edit\"]") |> render_click() =~
@ -119,8 +129,9 @@ defmodule CanneryWeb.ContainerLiveTest do
|> render_submit() |> render_submit()
|> follow_redirect(conn, Routes.container_show_path(conn, :show, container)) |> follow_redirect(conn, Routes.container_show_path(conn, :show, container))
assert html =~ dgettext("prompts", "Container updated successfully") container = container.id |> Containers.get_container!(current_user)
assert html =~ "some updated desc" assert html =~ dgettext("prompts", "%{name} updated successfully", name: container.name)
assert html =~ "some updated location"
end end
end end
end end