cannery/test/cannery_web/live/ammo_group_live_test.exs

126 lines
4.5 KiB
Elixir
Raw Normal View History

2021-09-02 23:31:14 -04:00
defmodule CanneryWeb.AmmoGroupLiveTest do
2022-02-16 22:51:22 -05:00
@moduledoc """
Tests ammo group live pages
"""
2021-09-02 23:31:14 -04:00
use CanneryWeb.ConnCase
import Phoenix.LiveViewTest
2022-02-08 23:58:54 -05:00
import CanneryWeb.Gettext
2022-02-16 22:51:22 -05:00
alias Cannery.Repo
2021-09-02 23:31:14 -04:00
2022-02-16 22:51:22 -05:00
@moduletag :ammo_group_live_test
2021-09-02 23:31:14 -04:00
@create_attrs %{count: 42, notes: "some notes", price_paid: 120.5}
@update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7}
2022-02-17 20:01:14 -05:00
# @invalid_attrs %{count: -1, notes: nil, price_paid: nil}
2021-09-02 23:31:14 -04:00
2022-02-16 22:51:22 -05:00
defp create_ammo_group(%{current_user: current_user}) do
ammo_type = ammo_type_fixture(current_user)
container = container_fixture(current_user)
%{ammo_group: ammo_group_fixture(ammo_type, container, current_user)}
2021-09-02 23:31:14 -04:00
end
describe "Index" do
2022-02-16 22:51:22 -05:00
setup [:register_and_log_in_user, :create_ammo_group]
2021-09-02 23:31:14 -04:00
test "lists all ammo_groups", %{conn: conn, ammo_group: ammo_group} do
{:ok, _index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
2022-02-16 22:51:22 -05:00
ammo_group = ammo_group |> Repo.preload(:ammo_type)
assert html =~ gettext("Ammo groups")
assert html =~ ammo_group.ammo_type.name
2021-09-02 23:31:14 -04:00
end
test "saves new ammo_group", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
2022-02-16 22:51:22 -05:00
assert index_live |> element("a", dgettext("actions", "New Ammo group")) |> render_click() =~
gettext("New Ammo group")
2021-09-02 23:31:14 -04:00
assert_patch(index_live, Routes.ammo_group_index_path(conn, :new))
2022-02-16 22:51:22 -05:00
# assert index_live
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank")
2021-09-02 23:31:14 -04:00
{:ok, _, html} =
index_live
|> form("#ammo_group-form", ammo_group: @create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
2022-02-16 22:51:22 -05:00
assert html =~ dgettext("prompts", "Ammo group created successfully")
2021-09-02 23:31:14 -04:00
assert html =~ "some notes"
end
test "updates ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
2022-02-16 22:51:22 -05:00
assert index_live
|> element("[data-qa=\"edit-#{ammo_group.id}\"]")
|> render_click() =~
gettext("Edit Ammo group")
2021-09-02 23:31:14 -04:00
assert_patch(index_live, Routes.ammo_group_index_path(conn, :edit, ammo_group))
2022-02-16 22:51:22 -05:00
# assert index_live
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank")
2021-09-02 23:31:14 -04:00
{:ok, _, html} =
index_live
|> form("#ammo_group-form", ammo_group: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
2022-02-16 22:51:22 -05:00
assert html =~ dgettext("prompts", "Ammo group updated successfully")
2021-09-02 23:31:14 -04:00
assert html =~ "some updated notes"
end
test "deletes ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
2022-02-16 22:51:22 -05:00
assert index_live
|> element("[data-qa=\"delete-#{ammo_group.id}\"]")
|> render_click()
2021-09-02 23:31:14 -04:00
refute has_element?(index_live, "#ammo_group-#{ammo_group.id}")
end
end
describe "Show" do
2022-02-16 22:51:22 -05:00
setup [:register_and_log_in_user, :create_ammo_group]
2021-09-02 23:31:14 -04:00
test "displays ammo_group", %{conn: conn, ammo_group: ammo_group} do
{:ok, _show_live, html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
2022-02-16 22:51:22 -05:00
ammo_group = ammo_group |> Repo.preload(:ammo_type)
assert html =~ gettext("Show Ammo group")
assert html =~ ammo_group.ammo_type.name
2021-09-02 23:31:14 -04:00
end
test "updates ammo_group within modal", %{conn: conn, ammo_group: ammo_group} do
{:ok, show_live, _html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
2022-02-16 22:51:22 -05:00
assert show_live
|> element("[data-qa=\"edit\"]")
|> render_click() =~
gettext("Edit Ammo group")
2021-09-02 23:31:14 -04:00
assert_patch(show_live, Routes.ammo_group_show_path(conn, :edit, ammo_group))
2022-02-16 22:51:22 -05:00
# assert show_live
# |> form("#ammo_group-form", ammo_group: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank")
2021-09-02 23:31:14 -04:00
{:ok, _, html} =
show_live
|> form("#ammo_group-form", ammo_group: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group))
2022-02-16 22:51:22 -05:00
assert html =~ dgettext("prompts", "Ammo group updated successfully")
2021-09-02 23:31:14 -04:00
assert html =~ "some updated notes"
end
end
end