cannery/test/cannery_web/live/container_live_test.exs

127 lines
4.3 KiB
Elixir
Raw Normal View History

2021-09-02 23:31:14 -04:00
defmodule CanneryWeb.ContainerLiveTest do
2022-02-17 20:01:47 -05:00
@moduledoc """
Tests the containers liveviews
"""
2021-09-02 23:31:14 -04:00
use CanneryWeb.ConnCase
import Phoenix.LiveViewTest
2022-02-08 22:10:48 -05:00
import CanneryWeb.Gettext
@moduletag :containers_live
2021-09-02 23:31:14 -04:00
2022-01-22 17:21:13 -05:00
@create_attrs %{
"desc" => "some desc",
"location" => "some location",
"name" => "some name",
"type" => "some type"
}
@update_attrs %{
"desc" => "some updated desc",
"location" => "some updated location",
"name" => "some updated name",
"type" => "some updated type"
}
2021-09-02 23:31:14 -04:00
2022-02-17 20:01:47 -05:00
# @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
2021-09-02 23:31:14 -04:00
2022-02-17 20:01:47 -05:00
defp create_container(%{current_user: current_user}) do
container = container_fixture(current_user)
2021-09-02 23:31:14 -04:00
%{container: container}
end
describe "Index" do
setup [:create_container]
test "lists all containers", %{conn: conn, container: container} do
{:ok, _index_live, html} = live(conn, Routes.container_index_path(conn, :index))
2022-02-15 17:33:45 -05:00
assert html =~ gettext("Containers")
2021-09-02 23:31:14 -04:00
assert html =~ container.desc
end
2022-02-17 20:01:47 -05:00
test "saves new container", %{conn: conn, container: container} do
2021-09-02 23:31:14 -04:00
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
2022-02-17 20:01:47 -05:00
assert index_live |> element("a", dgettext("actions", "New Container")) |> render_click() =~
2022-02-08 22:10:48 -05:00
gettext("New Container")
2021-09-02 23:31:14 -04:00
assert_patch(index_live, Routes.container_index_path(conn, :new))
2022-02-17 20:01:47 -05:00
# assert index_live
# |> form("#container-form", container: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank")
2021-09-02 23:31:14 -04:00
{:ok, _, html} =
index_live
|> form("#container-form", container: @create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
2022-02-17 20:01:47 -05:00
assert html =~ dgettext("prompts", "%{name} created successfully", name: container.name)
2021-09-02 23:31:14 -04:00
assert html =~ "some desc"
end
test "updates container in listing", %{conn: conn, container: container} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
2022-02-17 20:01:47 -05:00
assert index_live |> element("[data-qa=\"edit-#{container.id}\"]") |> render_click() =~
2022-02-08 22:10:48 -05:00
gettext("Edit Container")
2021-09-02 23:31:14 -04:00
assert_patch(index_live, Routes.container_index_path(conn, :edit, container))
2022-02-17 20:01:47 -05:00
# assert index_live
# |> form("#container-form", container: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank")
2021-09-02 23:31:14 -04:00
{:ok, _, html} =
index_live
|> form("#container-form", container: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.container_index_path(conn, :index))
2022-02-17 20:01:47 -05:00
assert html =~ dgettext("prompts", "%{name} updated successfully", name: container.name)
2021-09-02 23:31:14 -04:00
assert html =~ "some updated desc"
end
test "deletes container in listing", %{conn: conn, container: container} do
{:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index))
2022-02-17 20:01:47 -05:00
assert index_live |> element("[data-qa=\"delete-#{container.id}\"]") |> render_click()
2021-09-02 23:31:14 -04:00
refute has_element?(index_live, "#container-#{container.id}")
end
end
describe "Show" do
setup [:create_container]
test "displays container", %{conn: conn, container: container} do
{:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
2022-02-08 22:10:48 -05:00
assert html =~ gettext("Show Container")
2021-09-02 23:31:14 -04:00
assert html =~ container.desc
end
test "updates container within modal", %{conn: conn, container: container} do
{:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container))
2022-02-17 20:01:47 -05:00
assert show_live |> element("[data-qa=\"edit\"]") |> render_click() =~
2022-02-08 22:10:48 -05:00
gettext("Edit Container")
2021-09-02 23:31:14 -04:00
assert_patch(show_live, Routes.container_show_path(conn, :edit, container))
2022-02-17 20:01:47 -05:00
# assert show_live
# |> form("#container-form", container: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank")
2021-09-02 23:31:14 -04:00
{:ok, _, html} =
show_live
|> form("#container-form", container: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.container_show_path(conn, :show, container))
2022-02-17 20:01:47 -05:00
assert html =~ dgettext("prompts", "Container updated successfully")
2021-09-02 23:31:14 -04:00
assert html =~ "some updated desc"
end
end
end