cannery/test/cannery_web/live/pack_live_test.exs

460 lines
16 KiB
Elixir
Raw Normal View History

2023-03-29 22:54:55 -04:00
defmodule CanneryWeb.PackLiveTest 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-24 00:16:23 -05:00
alias Cannery.{Ammo, Repo}
2021-09-02 23:31:14 -04:00
2023-03-29 22:54:55 -04:00
@moduletag :pack_live_test
2023-03-28 21:57:29 -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}
@invalid_attrs %{count: nil, notes: nil, price_paid: nil}
2023-03-29 22:54:55 -04:00
@pack_create_limit 10_000
2023-03-28 21:57:29 -04:00
@shot_group_create_attrs %{ammo_left: 5, notes: "some notes"}
@shot_group_update_attrs %{
2023-03-28 21:57:29 -04:00
count: 5,
date: ~N[2022-02-13 03:17:00],
notes: "some updated notes"
}
2023-03-28 21:57:29 -04:00
@shot_group_invalid_attrs %{ammo_left: nil, count: nil, notes: nil}
2022-11-10 18:21:29 -05:00
@empty_attrs %{
2023-03-28 21:57:29 -04:00
price_paid: 50,
count: 20
}
@shot_group_attrs %{
2023-03-28 21:57:29 -04:00
price_paid: 50,
count: 20
}
2023-03-29 22:54:55 -04:00
defp create_pack(%{current_user: current_user}) do
2022-02-16 22:51:22 -05:00
ammo_type = ammo_type_fixture(current_user)
container = container_fixture(current_user)
2023-03-29 22:54:55 -04:00
{1, [pack]} = pack_fixture(@create_attrs, ammo_type, container, current_user)
[ammo_type: ammo_type, pack: pack, container: container]
end
2023-03-29 22:54:55 -04:00
defp create_shot_group(%{current_user: current_user, pack: pack}) do
shot_group = shot_group_fixture(@shot_group_update_attrs, current_user, pack)
pack = pack |> Repo.reload!()
[pack: pack, shot_group: shot_group]
2021-09-02 23:31:14 -04:00
end
2023-03-29 22:54:55 -04:00
defp create_empty_pack(%{
current_user: current_user,
ammo_type: ammo_type,
container: container
}) do
2023-03-29 22:54:55 -04:00
{1, [pack]} = pack_fixture(@empty_attrs, ammo_type, container, current_user)
shot_group = shot_group_fixture(@shot_group_attrs, current_user, pack)
pack = pack |> Repo.reload!()
[empty_pack: pack, shot_group: shot_group]
end
describe "Index of ammo group" do
2023-03-29 22:54:55 -04:00
setup [:register_and_log_in_user, :create_pack]
2021-09-02 23:31:14 -04:00
2023-03-29 22:54:55 -04:00
test "lists all packs", %{conn: conn, pack: pack} do
{:ok, _index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
pack = pack |> Repo.preload(:ammo_type)
2023-03-28 21:57:29 -04:00
assert html =~ "Ammo"
2023-03-29 22:54:55 -04:00
assert html =~ pack.ammo_type.name
2021-09-02 23:31:14 -04:00
end
2023-03-23 22:07:25 -04:00
test "can sort by type",
%{conn: conn, container: container, current_user: current_user} do
2023-03-28 23:08:40 -04:00
rifle_type = ammo_type_fixture(%{class: :rifle}, current_user)
2023-03-29 22:54:55 -04:00
{1, [rifle_pack]} = pack_fixture(rifle_type, container, current_user)
2023-03-28 23:08:40 -04:00
shotgun_type = ammo_type_fixture(%{class: :shotgun}, current_user)
2023-03-29 22:54:55 -04:00
{1, [shotgun_pack]} = pack_fixture(shotgun_type, container, current_user)
2023-03-28 23:08:40 -04:00
pistol_type = ammo_type_fixture(%{class: :pistol}, current_user)
2023-03-29 22:54:55 -04:00
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
2023-03-23 22:07:25 -04:00
2023-03-29 22:54:55 -04:00
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
2023-03-23 22:07:25 -04:00
assert html =~ "All"
2023-03-29 22:54:55 -04:00
assert html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
2023-03-23 22:07:25 -04:00
html =
index_live
2023-03-28 23:08:40 -04:00
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :rifle})
2023-03-23 22:07:25 -04:00
2023-03-29 22:54:55 -04:00
assert html =~ rifle_pack.ammo_type.name
refute html =~ shotgun_pack.ammo_type.name
refute html =~ pistol_pack.ammo_type.name
2023-03-23 22:07:25 -04:00
html =
index_live
2023-03-28 23:08:40 -04:00
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :shotgun})
2023-03-23 22:07:25 -04:00
2023-03-29 22:54:55 -04:00
refute html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
refute html =~ pistol_pack.ammo_type.name
2023-03-23 22:07:25 -04:00
html =
index_live
2023-03-28 23:08:40 -04:00
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :pistol})
2023-03-23 22:07:25 -04:00
2023-03-29 22:54:55 -04:00
refute html =~ rifle_pack.ammo_type.name
refute html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
2023-03-23 22:07:25 -04:00
html =
index_live
2023-03-28 23:08:40 -04:00
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :all})
2023-03-23 22:07:25 -04:00
2023-03-29 22:54:55 -04:00
assert html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
2023-03-23 22:07:25 -04:00
end
2023-03-29 22:54:55 -04:00
test "can search for packs", %{conn: conn, pack: pack} do
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
2022-12-03 18:46:44 -05:00
2023-03-29 22:54:55 -04:00
pack = pack |> Repo.preload(:ammo_type)
2022-12-03 18:46:44 -05:00
2023-03-29 22:54:55 -04:00
assert html =~ pack.ammo_type.name
2022-12-03 18:46:44 -05:00
assert index_live
2023-03-28 21:57:29 -04:00
|> form(~s/form[phx-change="search"]/)
2023-03-29 22:54:55 -04:00
|> render_change(search: %{search_term: pack.ammo_type.name}) =~
pack.ammo_type.name
2022-12-03 18:46:44 -05:00
assert_patch(
index_live,
2023-03-29 22:54:55 -04:00
Routes.pack_index_path(conn, :search, pack.ammo_type.name)
2022-12-03 18:46:44 -05:00
)
refute index_live
2023-03-28 21:57:29 -04:00
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~
2023-03-29 22:54:55 -04:00
pack.ammo_type.name
2022-12-03 18:46:44 -05:00
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :search, "something_else"))
2022-12-03 18:46:44 -05:00
assert index_live
2023-03-28 21:57:29 -04:00
|> form(~s/form[phx-change="search"]/)
2023-03-29 22:54:55 -04:00
|> render_change(search: %{search_term: ""}) =~ pack.ammo_type.name
2022-12-03 18:46:44 -05:00
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :index))
2022-12-03 18:46:44 -05:00
end
2023-03-29 22:54:55 -04:00
test "saves a single new pack", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2021-09-02 23:31:14 -04:00
2023-03-28 21:57:29 -04:00
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :new))
2021-09-02 23:31:14 -04:00
2023-03-28 21:57:29 -04:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
2021-09-02 23:31:14 -04:00
2022-03-28 23:05:12 -04:00
{:ok, _view, html} =
2021-09-02 23:31:14 -04:00
index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_submit(pack: @create_attrs)
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
2021-09-02 23:31:14 -04:00
2023-03-28 21:57:29 -04:00
assert html =~ "Ammo added successfully"
assert html =~ "\n42\n"
2021-09-02 23:31:14 -04:00
end
2023-03-29 22:54:55 -04:00
test "saves multiple new packs", %{conn: conn, current_user: current_user} do
2022-02-24 00:16:23 -05:00
multiplier = 25
2023-03-29 22:54:55 -04:00
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2022-02-24 00:16:23 -05:00
2023-03-28 21:57:29 -04:00
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :new))
2022-02-24 00:16:23 -05:00
2023-03-28 21:57:29 -04:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
2022-02-24 00:16:23 -05:00
2022-03-28 23:05:12 -04:00
{:ok, _view, html} =
2022-02-24 00:16:23 -05:00
index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_submit(pack: @create_attrs |> Map.put(:multiplier, multiplier))
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
2022-02-24 00:16:23 -05:00
2023-03-28 21:57:29 -04:00
assert html =~ "Ammo added successfully"
2023-03-29 22:54:55 -04:00
assert Ammo.list_packs(nil, :all, current_user) |> Enum.count() == multiplier + 1
2022-02-24 00:16:23 -05:00
end
2023-03-29 22:54:55 -04:00
test "does not save invalid number of new packs", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2022-02-24 00:16:23 -05:00
2023-03-28 21:57:29 -04:00
assert index_live |> element("a", "Add Ammo") |> render_click() =~ "Add Ammo"
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :new))
2022-02-24 00:16:23 -05:00
2023-03-28 21:57:29 -04:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
2022-02-24 00:16:23 -05:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_submit(pack: @create_attrs |> Map.put(:multiplier, "0")) =~
"Invalid number of copies, must be between 1 and #{@pack_create_limit}. Was 0"
2022-02-24 00:16:23 -05:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_submit(pack: @create_attrs |> Map.put(:multiplier, @pack_create_limit + 1)) =~
"Invalid number of copies, must be between 1 and #{@pack_create_limit}. Was #{@pack_create_limit + 1}"
2022-02-24 00:16:23 -05:00
end
2023-03-29 22:54:55 -04:00
test "updates pack in listing", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2021-09-02 23:31:14 -04:00
2022-02-16 22:51:22 -05:00
assert index_live
2023-03-29 22:54:55 -04:00
|> element(~s/a[aria-label="Edit ammo group of #{pack.count} bullets"]/)
2023-03-28 21:57:29 -04:00
|> render_click() =~ "Edit ammo"
2021-09-02 23:31:14 -04:00
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :edit, pack))
2021-09-02 23:31:14 -04:00
2023-03-28 21:57:29 -04:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
2021-09-02 23:31:14 -04:00
2022-03-28 23:05:12 -04:00
{:ok, _view, html} =
2021-09-02 23:31:14 -04:00
index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_submit(pack: @update_attrs)
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
2021-09-02 23:31:14 -04:00
2023-03-28 21:57:29 -04:00
assert html =~ "Ammo updated successfully"
assert html =~ "\n43\n"
2021-09-02 23:31:14 -04:00
end
2022-11-10 18:21:29 -05:00
2023-03-29 22:54:55 -04:00
test "clones pack in listing", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2022-11-10 18:21:29 -05:00
html =
index_live
2023-03-29 22:54:55 -04:00
|> element(~s/a[aria-label="Clone ammo group of #{pack.count} bullets"]/)
2022-11-10 18:21:29 -05:00
|> render_click()
2023-03-28 21:57:29 -04:00
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
2022-11-10 18:21:29 -05:00
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
2022-11-10 18:21:29 -05:00
2023-03-28 21:57:29 -04:00
{:ok, _index_live, html} =
2022-11-10 18:21:29 -05:00
index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
2022-11-10 18:21:29 -05:00
|> render_submit()
2023-03-29 22:54:55 -04:00
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
2022-11-10 18:21:29 -05:00
2023-03-28 21:57:29 -04:00
assert html =~ "Ammo added successfully"
assert html =~ "\n42\n"
2023-03-28 21:57:29 -04:00
assert html =~ "$#{display_currency(120.5)}"
2022-11-10 18:21:29 -05:00
end
2023-03-29 22:54:55 -04:00
test "checks validity when cloning", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2022-11-10 18:21:29 -05:00
html =
index_live
2023-03-29 22:54:55 -04:00
|> element(~s/a[aria-label="Clone ammo group of #{pack.count} bullets"]/)
2022-11-10 18:21:29 -05:00
|> render_click()
2023-03-28 21:57:29 -04:00
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
2023-03-28 21:57:29 -04:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
2023-03-28 21:57:29 -04:00
end
2022-11-10 18:21:29 -05:00
2023-03-29 22:54:55 -04:00
test "clones pack in listing with updates", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2023-03-28 21:57:29 -04:00
html =
index_live
2023-03-29 22:54:55 -04:00
|> element(~s/a[aria-label="Clone ammo group of #{pack.count} bullets"]/)
2023-03-28 21:57:29 -04:00
|> render_click()
assert html =~ "Add Ammo"
assert html =~ "$#{display_currency(120.5)}"
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :clone, pack))
2022-11-10 18:21:29 -05:00
2023-03-28 21:57:29 -04:00
assert index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
2022-11-10 18:21:29 -05:00
{:ok, _view, html} =
index_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_submit(pack: @create_attrs |> Map.put(:count, 43))
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
2022-11-10 18:21:29 -05:00
2023-03-28 21:57:29 -04:00
assert html =~ "Ammo added successfully"
assert html =~ "\n43\n"
2023-03-28 21:57:29 -04:00
assert html =~ "$#{display_currency(120.5)}"
2022-11-10 18:21:29 -05:00
end
2021-09-02 23:31:14 -04:00
2023-03-29 22:54:55 -04:00
test "deletes pack in listing", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2021-09-02 23:31:14 -04:00
2022-02-16 22:51:22 -05:00
assert index_live
2023-03-29 22:54:55 -04:00
|> element(~s/a[aria-label="Delete ammo group of #{pack.count} bullets"]/)
2022-02-16 22:51:22 -05:00
|> render_click()
2023-03-29 22:54:55 -04:00
refute has_element?(index_live, "#pack-#{pack.id}")
2021-09-02 23:31:14 -04:00
end
2023-03-29 22:54:55 -04:00
test "saves new shot_group", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
2023-03-28 21:57:29 -04:00
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_index_path(conn, :add_shot_group, pack))
2023-03-28 21:57:29 -04:00
assert index_live
|> form("#shot-group-form")
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
{:ok, _view, html} =
index_live
2023-03-28 21:57:29 -04:00
|> form("#shot-group-form")
|> render_submit(shot_group: @shot_group_create_attrs)
2023-03-29 22:54:55 -04:00
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
2023-03-28 21:57:29 -04:00
assert html =~ "Shots recorded successfully"
end
@spec display_currency(float()) :: String.t()
defp display_currency(float), do: :erlang.float_to_binary(float, decimals: 2)
end
describe "Index of empty ammo group" do
2023-03-29 22:54:55 -04:00
setup [:register_and_log_in_user, :create_pack, :create_empty_pack]
test "hides empty ammo groups by default", %{
conn: conn,
2023-03-29 22:54:55 -04:00
empty_pack: pack,
current_user: current_user
} do
2023-03-29 22:54:55 -04:00
{:ok, show_live, html} = live(conn, Routes.pack_index_path(conn, :index))
2023-03-28 21:57:29 -04:00
assert html =~ "Show used"
refute html =~ "$#{display_currency(50.00)}"
2023-03-29 22:54:55 -04:00
percentage = pack |> Ammo.get_percentage_remaining(current_user)
2023-03-28 21:57:29 -04:00
refute html =~ "\n#{"#{percentage}%"}\n"
2023-03-15 00:45:08 -04:00
html =
show_live
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
|> render_click()
2023-03-28 21:57:29 -04:00
assert html =~ "$#{display_currency(50.00)}"
2023-03-29 22:54:55 -04:00
percentage = pack |> Ammo.get_percentage_remaining(current_user)
2023-03-28 21:57:29 -04:00
assert html =~ "\n#{"#{percentage}%"}\n"
end
2021-09-02 23:31:14 -04:00
end
describe "Show ammo group" do
2023-03-29 22:54:55 -04:00
setup [:register_and_log_in_user, :create_pack]
2021-09-02 23:31:14 -04:00
2023-03-29 22:54:55 -04:00
test "displays pack", %{conn: conn, pack: pack} do
{:ok, _show_live, html} = live(conn, Routes.pack_show_path(conn, :show, pack))
pack = pack |> Repo.preload(:ammo_type)
2023-03-28 21:57:29 -04:00
assert html =~ "Show Ammo"
2023-03-29 22:54:55 -04:00
assert html =~ pack.ammo_type.name
2021-09-02 23:31:14 -04:00
end
2023-03-29 22:54:55 -04:00
test "updates pack within modal", %{conn: conn, pack: pack} do
{:ok, show_live, _html} = live(conn, Routes.pack_show_path(conn, :show, pack))
2021-09-02 23:31:14 -04:00
2022-02-16 22:51:22 -05:00
assert show_live
2023-03-29 22:54:55 -04:00
|> element(~s/a[aria-label="Edit ammo group of #{pack.count} bullets"]/)
2023-03-28 21:57:29 -04:00
|> render_click() =~ "Edit Ammo"
2021-09-02 23:31:14 -04:00
2023-03-29 22:54:55 -04:00
assert_patch(show_live, Routes.pack_show_path(conn, :edit, pack))
2021-09-02 23:31:14 -04:00
2023-03-28 21:57:29 -04:00
assert show_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_change(pack: @invalid_attrs) =~ "can't be blank"
2021-09-02 23:31:14 -04:00
2022-03-28 23:05:12 -04:00
{:ok, _view, html} =
2021-09-02 23:31:14 -04:00
show_live
2023-03-29 22:54:55 -04:00
|> form("#pack-form")
|> render_submit(pack: @update_attrs)
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
2021-09-02 23:31:14 -04:00
2023-03-28 21:57:29 -04:00
assert html =~ "Ammo updated successfully"
2021-09-02 23:31:14 -04:00
assert html =~ "some updated notes"
end
2022-02-17 21:19:04 -05:00
2023-03-29 22:54:55 -04:00
test "saves new shot_group", %{conn: conn, pack: pack} do
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :show, pack))
2022-02-17 21:19:04 -05:00
2023-03-28 21:57:29 -04:00
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
2023-03-29 22:54:55 -04:00
assert_patch(index_live, Routes.pack_show_path(conn, :add_shot_group, pack))
2022-02-17 21:19:04 -05:00
2023-03-28 21:57:29 -04:00
assert index_live
|> form("#shot-group-form")
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
2022-02-17 21:19:04 -05:00
2022-03-28 23:05:12 -04:00
{:ok, _view, html} =
2022-02-17 21:19:04 -05:00
index_live
2023-03-28 21:57:29 -04:00
|> form("#shot-group-form")
|> render_submit(shot_group: @shot_group_create_attrs)
2023-03-29 22:54:55 -04:00
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
2022-02-17 21:19:04 -05:00
2023-03-28 21:57:29 -04:00
assert html =~ "Shots recorded successfully"
2022-02-17 21:19:04 -05:00
end
end
describe "Show ammo group with shot group" do
2023-03-29 22:54:55 -04:00
setup [:register_and_log_in_user, :create_pack, :create_shot_group]
test "updates shot_group in listing",
2023-03-29 22:54:55 -04:00
%{conn: conn, pack: pack, shot_group: shot_group} do
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :edit, pack))
2023-03-15 00:45:08 -04:00
assert index_live
|> element(~s/a[aria-label="Edit shot group of #{shot_group.count} shots"]/)
2023-03-28 21:57:29 -04:00
|> render_click() =~ "Edit Shot Records"
assert_patch(
index_live,
2023-03-29 22:54:55 -04:00
Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group)
)
2023-03-28 21:57:29 -04:00
assert index_live
|> form("#shot-group-form")
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
2022-03-28 23:05:12 -04:00
{:ok, _view, html} =
index_live
2023-03-28 21:57:29 -04:00
|> form("#shot-group-form")
|> render_submit(shot_group: @shot_group_update_attrs)
2023-03-29 22:54:55 -04:00
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
2023-03-28 21:57:29 -04:00
assert html =~ "Shot records updated successfully"
assert html =~ "some updated notes"
end
test "deletes shot_group in listing",
2023-03-29 22:54:55 -04:00
%{conn: conn, pack: pack, shot_group: shot_group} do
{:ok, index_live, _html} =
2023-03-29 22:54:55 -04:00
live(conn, Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group))
2023-03-15 00:45:08 -04:00
assert index_live
|> element(~s/a[aria-label="Delete shot record of #{shot_group.count} shots"]/)
|> render_click()
refute has_element?(index_live, "#shot_group-#{shot_group.id}")
end
2021-09-02 23:31:14 -04:00
end
end