rename ammo type to type

This commit is contained in:
2023-03-30 21:53:52 -04:00
parent 98775359af
commit c33f15603b
59 changed files with 1616 additions and 1677 deletions

View File

@ -11,16 +11,16 @@ defmodule CanneryWeb.ExportControllerTest do
setup [:register_and_log_in_user]
defp add_data(%{current_user: current_user}) do
ammo_type = ammo_type_fixture(current_user)
type = type_fixture(current_user)
container = container_fixture(current_user)
tag = tag_fixture(current_user)
Containers.add_tag!(container, tag, current_user)
{1, [pack]} = pack_fixture(ammo_type, container, current_user)
{1, [pack]} = pack_fixture(type, container, current_user)
shot_record = shot_record_fixture(current_user, pack)
pack = pack |> Repo.reload!()
%{
ammo_type: ammo_type,
type: type,
pack: pack,
container: container,
shot_record: shot_record,
@ -35,7 +35,7 @@ defmodule CanneryWeb.ExportControllerTest do
conn: conn,
current_user: current_user,
container: container,
ammo_type: ammo_type,
type: type,
pack: pack,
shot_record: shot_record,
tag: tag
@ -43,7 +43,7 @@ defmodule CanneryWeb.ExportControllerTest do
conn = get(conn, Routes.export_path(conn, :export, :json))
ideal_pack = %{
"ammo_type_id" => pack.ammo_type_id,
"type_id" => pack.type_id,
"container_id" => pack.container_id,
"count" => pack.count,
"id" => pack.id,
@ -56,34 +56,34 @@ defmodule CanneryWeb.ExportControllerTest do
"percentage_remaining" => pack |> Ammo.get_percentage_remaining(current_user)
}
ideal_ammo_type = %{
"blank" => ammo_type.blank,
"bullet_core" => ammo_type.bullet_core,
"bullet_type" => ammo_type.bullet_type,
"caliber" => ammo_type.caliber,
"cartridge" => ammo_type.cartridge,
"case_material" => ammo_type.case_material,
"corrosive" => ammo_type.corrosive,
"desc" => ammo_type.desc,
"firing_type" => ammo_type.firing_type,
"grains" => ammo_type.grains,
"id" => ammo_type.id,
"incendiary" => ammo_type.incendiary,
"jacket_type" => ammo_type.jacket_type,
"manufacturer" => ammo_type.manufacturer,
"muzzle_velocity" => ammo_type.muzzle_velocity,
"name" => ammo_type.name,
"powder_grains_per_charge" => ammo_type.powder_grains_per_charge,
"powder_type" => ammo_type.powder_type,
"pressure" => ammo_type.pressure,
"primer_type" => ammo_type.primer_type,
"tracer" => ammo_type.tracer,
"upc" => ammo_type.upc,
"average_cost" => ammo_type |> Ammo.get_average_cost_for_ammo_type(current_user),
"round_count" => ammo_type |> Ammo.get_round_count_for_ammo_type(current_user),
"used_count" => ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user),
"pack_count" => ammo_type |> Ammo.get_packs_count_for_type(current_user),
"total_pack_count" => ammo_type |> Ammo.get_packs_count_for_type(current_user, true)
ideal_type = %{
"blank" => type.blank,
"bullet_core" => type.bullet_core,
"bullet_type" => type.bullet_type,
"caliber" => type.caliber,
"cartridge" => type.cartridge,
"case_material" => type.case_material,
"corrosive" => type.corrosive,
"desc" => type.desc,
"firing_type" => type.firing_type,
"grains" => type.grains,
"id" => type.id,
"incendiary" => type.incendiary,
"jacket_type" => type.jacket_type,
"manufacturer" => type.manufacturer,
"muzzle_velocity" => type.muzzle_velocity,
"name" => type.name,
"powder_grains_per_charge" => type.powder_grains_per_charge,
"powder_type" => type.powder_type,
"pressure" => type.pressure,
"primer_type" => type.primer_type,
"tracer" => type.tracer,
"upc" => type.upc,
"average_cost" => type |> Ammo.get_average_cost_for_type(current_user),
"round_count" => type |> Ammo.get_round_count_for_type(current_user),
"used_count" => type |> ActivityLog.get_used_count_for_type(current_user),
"pack_count" => type |> Ammo.get_packs_count_for_type(current_user),
"total_pack_count" => type |> Ammo.get_packs_count_for_type(current_user, true)
}
ideal_container = %{
@ -125,7 +125,7 @@ defmodule CanneryWeb.ExportControllerTest do
json_resp = conn |> json_response(200)
assert %{"packs" => [^ideal_pack]} = json_resp
assert %{"ammo_types" => [^ideal_ammo_type]} = json_resp
assert %{"types" => [^ideal_type]} = json_resp
assert %{"containers" => [^ideal_container]} = json_resp
assert %{"shot_records" => [^ideal_shot_record]} = json_resp
assert %{"user" => ^ideal_user} = json_resp

View File

@ -1,13 +1,13 @@
defmodule CanneryWeb.AmmoTypeLiveTest do
defmodule CanneryWeb.TypeLiveTest do
@moduledoc """
Tests the ammo type liveview
Tests the type liveview
"""
use CanneryWeb.ConnCase
import Phoenix.LiveViewTest
alias Cannery.{Ammo, Repo}
@moduletag :ammo_type_live_test
@moduletag :type_live_test
@create_attrs %{
bullet_type: "some bullet_type",
@ -42,39 +42,39 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
count: 20
}
defp create_ammo_type(%{current_user: current_user}) do
[ammo_type: ammo_type_fixture(@create_attrs, current_user)]
defp create_type(%{current_user: current_user}) do
[type: type_fixture(@create_attrs, current_user)]
end
defp create_pack(%{ammo_type: ammo_type, current_user: current_user}) do
defp create_pack(%{type: type, current_user: current_user}) do
container = container_fixture(current_user)
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
{1, [pack]} = pack_fixture(@pack_attrs, type, container, current_user)
[pack: pack, container: container]
end
defp create_empty_pack(%{ammo_type: ammo_type, current_user: current_user}) do
defp create_empty_pack(%{type: type, current_user: current_user}) do
container = container_fixture(current_user)
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
{1, [pack]} = pack_fixture(@pack_attrs, type, container, current_user)
shot_record = shot_record_fixture(@shot_record_attrs, current_user, pack)
pack = pack |> Repo.reload!()
[pack: pack, container: container, shot_record: shot_record]
end
describe "Index" do
setup [:register_and_log_in_user, :create_ammo_type]
setup [:register_and_log_in_user, :create_type]
test "lists all ammo_types", %{conn: conn, ammo_type: ammo_type} do
{:ok, _index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
test "lists all types", %{conn: conn, type: type} do
{:ok, _index_live, html} = live(conn, Routes.type_index_path(conn, :index))
assert html =~ "Catalog"
assert html =~ ammo_type.bullet_type
assert html =~ type.bullet_type
end
test "can sort by class", %{conn: conn, current_user: current_user} do
rifle_type = ammo_type_fixture(%{class: :rifle}, current_user)
shotgun_type = ammo_type_fixture(%{class: :shotgun}, current_user)
pistol_type = ammo_type_fixture(%{class: :pistol}, current_user)
rifle_type = type_fixture(%{class: :rifle}, current_user)
shotgun_type = type_fixture(%{class: :shotgun}, current_user)
pistol_type = type_fixture(%{class: :pistol}, current_user)
{:ok, index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
{:ok, index_live, html} = live(conn, Routes.type_index_path(conn, :index))
assert html =~ "All"
@ -85,7 +85,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :rifle})
|> render_change(type: %{class: :rifle})
assert html =~ rifle_type.name
refute html =~ shotgun_type.name
@ -94,7 +94,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :shotgun})
|> render_change(type: %{class: :shotgun})
refute html =~ rifle_type.name
assert html =~ shotgun_type.name
@ -103,7 +103,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :pistol})
|> render_change(type: %{class: :pistol})
refute html =~ rifle_type.name
refute html =~ shotgun_type.name
@ -112,148 +112,148 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :all})
|> render_change(type: %{class: :all})
assert html =~ rifle_type.name
assert html =~ shotgun_type.name
assert html =~ pistol_type.name
end
test "can search for ammo_type", %{conn: conn, ammo_type: ammo_type} do
{:ok, index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
test "can search for type", %{conn: conn, type: type} do
{:ok, index_live, html} = live(conn, Routes.type_index_path(conn, :index))
assert html =~ ammo_type.bullet_type
assert html =~ type.bullet_type
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ammo_type.bullet_type}) =~
ammo_type.bullet_type
|> render_change(search: %{search_term: type.bullet_type}) =~
type.bullet_type
assert_patch(index_live, Routes.ammo_type_index_path(conn, :search, ammo_type.bullet_type))
assert_patch(index_live, Routes.type_index_path(conn, :search, type.bullet_type))
refute index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~ ammo_type.bullet_type
|> render_change(search: %{search_term: "something_else"}) =~ type.bullet_type
assert_patch(index_live, Routes.ammo_type_index_path(conn, :search, "something_else"))
assert_patch(index_live, Routes.type_index_path(conn, :search, "something_else"))
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ""}) =~ ammo_type.bullet_type
|> render_change(search: %{search_term: ""}) =~ type.bullet_type
assert_patch(index_live, Routes.ammo_type_index_path(conn, :index))
assert_patch(index_live, Routes.type_index_path(conn, :index))
end
test "saves new ammo_type", %{conn: conn, current_user: current_user, ammo_type: ammo_type} do
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
test "saves new type", %{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
assert index_live |> element("a", "New Ammo type") |> render_click() =~ "New Ammo type"
assert_patch(index_live, Routes.ammo_type_index_path(conn, :new))
assert index_live |> element("a", "New Type") |> render_click() =~ "New Type"
assert_patch(index_live, Routes.type_index_path(conn, :new))
assert index_live
|> form("#ammo_type-form")
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|> form("#type-form")
|> render_change(type: @invalid_attrs) =~ "can't be blank"
{:ok, _view, html} =
index_live
|> form("#ammo_type-form")
|> render_submit(ammo_type: @create_attrs)
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|> form("#type-form")
|> render_submit(type: @create_attrs)
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
assert html =~ "#{ammo_type.name} created successfully"
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} created successfully"
assert html =~ "some bullet_type"
end
test "updates ammo_type in listing",
%{conn: conn, current_user: current_user, ammo_type: ammo_type} do
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
test "updates type in listing",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
assert index_live |> element(~s/a[aria-label="Edit #{ammo_type.name}"]/) |> render_click() =~
"Edit #{ammo_type.name}"
assert index_live |> element(~s/a[aria-label="Edit #{type.name}"]/) |> render_click() =~
"Edit #{type.name}"
assert_patch(index_live, Routes.ammo_type_index_path(conn, :edit, ammo_type))
assert_patch(index_live, Routes.type_index_path(conn, :edit, type))
assert index_live
|> form("#ammo_type-form")
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|> form("#type-form")
|> render_change(type: @invalid_attrs) =~ "can't be blank"
{:ok, _view, html} =
index_live
|> form("#ammo_type-form")
|> render_submit(ammo_type: @update_attrs)
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|> form("#type-form")
|> render_submit(type: @update_attrs)
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
assert html =~ "#{ammo_type.name} updated successfully"
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} updated successfully"
assert html =~ "some updated bullet_type"
end
test "clones ammo_type in listing",
%{conn: conn, current_user: current_user, ammo_type: ammo_type} do
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
test "clones type in listing",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
html = index_live |> element(~s/a[aria-label="Clone #{ammo_type.name}"]/) |> render_click()
assert html =~ "New Ammo type"
html = index_live |> element(~s/a[aria-label="Clone #{type.name}"]/) |> render_click()
assert html =~ "New Type"
assert html =~ "some bullet_type"
assert_patch(index_live, Routes.ammo_type_index_path(conn, :clone, ammo_type))
assert_patch(index_live, Routes.type_index_path(conn, :clone, type))
assert index_live
|> form("#ammo_type-form")
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|> form("#type-form")
|> render_change(type: @invalid_attrs) =~ "can't be blank"
{:ok, _view, html} =
index_live
|> form("#ammo_type-form")
|> render_submit(ammo_type: @create_attrs)
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|> form("#type-form")
|> render_submit(type: @create_attrs)
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
assert html =~ "#{ammo_type.name} created successfully"
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} created successfully"
assert html =~ "some bullet_type"
end
test "clones ammo_type in listing with updates",
%{conn: conn, current_user: current_user, ammo_type: ammo_type} do
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
test "clones type in listing with updates",
%{conn: conn, current_user: current_user, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
html = index_live |> element(~s/a[aria-label="Clone #{ammo_type.name}"]/) |> render_click()
assert html =~ "New Ammo type"
html = index_live |> element(~s/a[aria-label="Clone #{type.name}"]/) |> render_click()
assert html =~ "New Type"
assert html =~ "some bullet_type"
assert_patch(index_live, Routes.ammo_type_index_path(conn, :clone, ammo_type))
assert_patch(index_live, Routes.type_index_path(conn, :clone, type))
assert index_live
|> form("#ammo_type-form")
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|> form("#type-form")
|> render_change(type: @invalid_attrs) =~ "can't be blank"
{:ok, _view, html} =
index_live
|> form("#ammo_type-form")
|> form("#type-form")
|> render_submit(
ammo_type: Map.merge(@create_attrs, %{bullet_type: "some updated bullet_type"})
type: Map.merge(@create_attrs, %{bullet_type: "some updated bullet_type"})
)
|> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
|> follow_redirect(conn, Routes.type_index_path(conn, :index))
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
assert html =~ "#{ammo_type.name} created successfully"
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} created successfully"
assert html =~ "some updated bullet_type"
end
test "deletes ammo_type in listing", %{conn: conn, ammo_type: ammo_type} do
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
assert index_live |> element(~s/a[aria-label="Delete #{ammo_type.name}"]/) |> render_click()
refute has_element?(index_live, "#ammo_type-#{ammo_type.id}")
test "deletes type in listing", %{conn: conn, type: type} do
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
assert index_live |> element(~s/a[aria-label="Delete #{type.name}"]/) |> render_click()
refute has_element?(index_live, "#type-#{type.id}")
end
end
describe "Index with pack" do
setup [:register_and_log_in_user, :create_ammo_type, :create_pack]
setup [:register_and_log_in_user, :create_type, :create_pack]
test "shows used packs on toggle",
%{conn: conn, pack: pack, current_user: current_user} do
{:ok, index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
{:ok, index_live, html} = live(conn, Routes.type_index_path(conn, :index))
assert html =~ "Show used"
refute html =~ "Used rounds"
@ -277,7 +277,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
shot_record_fixture(%{count: 5}, current_user, pack)
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, Routes.type_index_path(conn, :index))
html =
index_live
@ -289,62 +289,62 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
end
end
describe "Show ammo type" do
setup [:register_and_log_in_user, :create_ammo_type]
describe "Show type" do
setup [:register_and_log_in_user, :create_type]
test "displays ammo_type", %{
test "displays type", %{
conn: conn,
ammo_type: %{name: name, bullet_type: bullet_type} = ammo_type
type: %{name: name, bullet_type: bullet_type} = type
} do
{:ok, _show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
{:ok, _show_live, html} = live(conn, Routes.type_show_path(conn, :show, type))
assert html =~ name
assert html =~ bullet_type
end
test "updates ammo_type within modal",
%{conn: conn, current_user: current_user, ammo_type: %{name: name} = ammo_type} do
{:ok, show_live, _html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
test "updates type within modal",
%{conn: conn, current_user: current_user, type: %{name: name} = type} do
{:ok, show_live, _html} = live(conn, Routes.type_show_path(conn, :show, type))
assert show_live |> element(~s/a[aria-label="Edit #{ammo_type.name}"]/) |> render_click() =~
assert show_live |> element(~s/a[aria-label="Edit #{type.name}"]/) |> render_click() =~
"Edit #{name}"
assert_patch(show_live, Routes.ammo_type_show_path(conn, :edit, ammo_type))
assert_patch(show_live, Routes.type_show_path(conn, :edit, type))
assert show_live
|> form("#ammo_type-form")
|> render_change(ammo_type: @invalid_attrs) =~ "can't be blank"
|> form("#type-form")
|> render_change(type: @invalid_attrs) =~ "can't be blank"
{:ok, _view, html} =
show_live
|> form("#ammo_type-form")
|> render_submit(ammo_type: @update_attrs)
|> follow_redirect(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
|> form("#type-form")
|> render_submit(type: @update_attrs)
|> follow_redirect(conn, Routes.type_show_path(conn, :show, type))
ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
assert html =~ "#{ammo_type.name} updated successfully"
type = type.id |> Ammo.get_type!(current_user)
assert html =~ "#{type.name} updated successfully"
assert html =~ "some updated bullet_type"
end
end
describe "Show ammo type with pack" do
setup [:register_and_log_in_user, :create_ammo_type, :create_pack]
describe "Show type with pack" do
setup [:register_and_log_in_user, :create_type, :create_pack]
test "displays pack", %{
conn: conn,
ammo_type: %{name: ammo_type_name} = ammo_type,
type: %{name: type_name} = type,
container: %{name: container_name}
} do
{:ok, _show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
{:ok, _show_live, html} = live(conn, Routes.type_show_path(conn, :show, type))
assert html =~ ammo_type_name
assert html =~ type_name
assert html =~ "\n20\n"
assert html =~ container_name
end
test "displays pack in table",
%{conn: conn, ammo_type: ammo_type, container: %{name: container_name}} do
{:ok, show_live, _html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
%{conn: conn, type: type, container: %{name: container_name}} do
{:ok, show_live, _html} = live(conn, Routes.type_show_path(conn, :show, type))
html =
show_live
@ -356,12 +356,12 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
end
end
describe "Show ammo type with empty pack" do
setup [:register_and_log_in_user, :create_ammo_type, :create_empty_pack]
describe "Show type with empty pack" do
setup [:register_and_log_in_user, :create_type, :create_empty_pack]
test "displays empty packs on toggle",
%{conn: conn, ammo_type: ammo_type, container: %{name: container_name}} do
{:ok, show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
%{conn: conn, type: type, container: %{name: container_name}} do
{:ok, show_live, html} = live(conn, Routes.type_show_path(conn, :show, type))
assert html =~ "Show used"
refute html =~ "\n20\n"
@ -376,8 +376,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
end
test "displays empty packs in table on toggle",
%{conn: conn, ammo_type: ammo_type, container: %{name: container_name}} do
{:ok, show_live, _html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
%{conn: conn, type: type, container: %{name: container_name}} do
{:ok, show_live, _html} = live(conn, Routes.type_show_path(conn, :show, type))
html =
show_live

View File

@ -22,7 +22,7 @@ defmodule CanneryWeb.ContainerLiveTest do
type: "some updated type"
}
@invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
@ammo_type_attrs %{
@type_attrs %{
bullet_type: "some bullet_type",
case_material: "some case_material",
desc: "some desc",
@ -41,10 +41,10 @@ defmodule CanneryWeb.ContainerLiveTest do
end
defp create_pack(%{container: container, current_user: current_user}) do
ammo_type = ammo_type_fixture(@ammo_type_attrs, current_user)
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
type = type_fixture(@type_attrs, current_user)
{1, [pack]} = pack_fixture(@pack_attrs, type, container, current_user)
[ammo_type: ammo_type, pack: pack]
[type: type, pack: pack]
end
describe "Index" do
@ -245,56 +245,56 @@ defmodule CanneryWeb.ContainerLiveTest do
test "can sort by type",
%{conn: conn, container: container, current_user: current_user} do
rifle_type = ammo_type_fixture(%{class: :rifle}, current_user)
rifle_type = type_fixture(%{class: :rifle}, current_user)
{1, [rifle_pack]} = pack_fixture(rifle_type, container, current_user)
shotgun_type = ammo_type_fixture(%{class: :shotgun}, current_user)
shotgun_type = type_fixture(%{class: :shotgun}, current_user)
{1, [shotgun_pack]} = pack_fixture(shotgun_type, container, current_user)
pistol_type = ammo_type_fixture(%{class: :pistol}, current_user)
pistol_type = type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
{:ok, index_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
assert html =~ "All"
assert html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
assert html =~ rifle_pack.type.name
assert html =~ shotgun_pack.type.name
assert html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :rifle})
|> render_change(type: %{class: :rifle})
assert html =~ rifle_pack.ammo_type.name
refute html =~ shotgun_pack.ammo_type.name
refute html =~ pistol_pack.ammo_type.name
assert html =~ rifle_pack.type.name
refute html =~ shotgun_pack.type.name
refute html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :shotgun})
|> render_change(type: %{class: :shotgun})
refute html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
refute html =~ pistol_pack.ammo_type.name
refute html =~ rifle_pack.type.name
assert html =~ shotgun_pack.type.name
refute html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :pistol})
|> render_change(type: %{class: :pistol})
refute html =~ rifle_pack.ammo_type.name
refute html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
refute html =~ rifle_pack.type.name
refute html =~ shotgun_pack.type.name
assert html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :all})
|> render_change(type: %{class: :all})
assert html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
assert html =~ rifle_pack.type.name
assert html =~ shotgun_pack.type.name
assert html =~ pistol_pack.type.name
end
end
@ -302,15 +302,15 @@ defmodule CanneryWeb.ContainerLiveTest do
setup [:register_and_log_in_user, :create_container, :create_pack]
test "displays pack",
%{conn: conn, ammo_type: %{name: ammo_type_name}, container: container} do
%{conn: conn, type: %{name: type_name}, container: container} do
{:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
assert html =~ ammo_type_name
assert html =~ type_name
assert html =~ "\n20\n"
end
test "displays pack in table",
%{conn: conn, ammo_type: %{name: ammo_type_name}, container: container} do
%{conn: conn, type: %{name: type_name}, container: container} do
{:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container))
html =
@ -318,7 +318,7 @@ defmodule CanneryWeb.ContainerLiveTest do
|> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/)
|> render_click()
assert html =~ ammo_type_name
assert html =~ type_name
assert html =~ "\n20\n"
end
end

View File

@ -29,10 +29,10 @@ defmodule CanneryWeb.PackLiveTest do
}
defp create_pack(%{current_user: current_user}) do
ammo_type = ammo_type_fixture(current_user)
type = type_fixture(current_user)
container = container_fixture(current_user)
{1, [pack]} = pack_fixture(@create_attrs, ammo_type, container, current_user)
[ammo_type: ammo_type, pack: pack, container: container]
{1, [pack]} = pack_fixture(@create_attrs, type, container, current_user)
[type: type, pack: pack, container: container]
end
defp create_shot_record(%{current_user: current_user, pack: pack}) do
@ -43,10 +43,10 @@ defmodule CanneryWeb.PackLiveTest do
defp create_empty_pack(%{
current_user: current_user,
ammo_type: ammo_type,
type: type,
container: container
}) do
{1, [pack]} = pack_fixture(@empty_attrs, ammo_type, container, current_user)
{1, [pack]} = pack_fixture(@empty_attrs, type, container, current_user)
shot_record = shot_record_fixture(@shot_record_attrs, current_user, pack)
pack = pack |> Repo.reload!()
[empty_pack: pack, shot_record: shot_record]
@ -57,92 +57,92 @@ defmodule CanneryWeb.PackLiveTest do
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)
pack = pack |> Repo.preload(:type)
assert html =~ "Ammo"
assert html =~ pack.ammo_type.name
assert html =~ pack.type.name
end
test "can sort by type",
%{conn: conn, container: container, current_user: current_user} do
rifle_type = ammo_type_fixture(%{class: :rifle}, current_user)
rifle_type = type_fixture(%{class: :rifle}, current_user)
{1, [rifle_pack]} = pack_fixture(rifle_type, container, current_user)
shotgun_type = ammo_type_fixture(%{class: :shotgun}, current_user)
shotgun_type = type_fixture(%{class: :shotgun}, current_user)
{1, [shotgun_pack]} = pack_fixture(shotgun_type, container, current_user)
pistol_type = ammo_type_fixture(%{class: :pistol}, current_user)
pistol_type = type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
assert html =~ "All"
assert html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
assert html =~ rifle_pack.type.name
assert html =~ shotgun_pack.type.name
assert html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :rifle})
|> render_change(type: %{class: :rifle})
assert html =~ rifle_pack.ammo_type.name
refute html =~ shotgun_pack.ammo_type.name
refute html =~ pistol_pack.ammo_type.name
assert html =~ rifle_pack.type.name
refute html =~ shotgun_pack.type.name
refute html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :shotgun})
|> render_change(type: %{class: :shotgun})
refute html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
refute html =~ pistol_pack.ammo_type.name
refute html =~ rifle_pack.type.name
assert html =~ shotgun_pack.type.name
refute html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :pistol})
|> render_change(type: %{class: :pistol})
refute html =~ rifle_pack.ammo_type.name
refute html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
refute html =~ rifle_pack.type.name
refute html =~ shotgun_pack.type.name
assert html =~ pistol_pack.type.name
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :all})
|> render_change(type: %{class: :all})
assert html =~ rifle_pack.ammo_type.name
assert html =~ shotgun_pack.ammo_type.name
assert html =~ pistol_pack.ammo_type.name
assert html =~ rifle_pack.type.name
assert html =~ shotgun_pack.type.name
assert html =~ pistol_pack.type.name
end
test "can search for packs", %{conn: conn, pack: pack} do
{:ok, index_live, html} = live(conn, Routes.pack_index_path(conn, :index))
pack = pack |> Repo.preload(:ammo_type)
pack = pack |> Repo.preload(:type)
assert html =~ pack.ammo_type.name
assert html =~ pack.type.name
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: pack.ammo_type.name}) =~
pack.ammo_type.name
|> render_change(search: %{search_term: pack.type.name}) =~
pack.type.name
assert_patch(
index_live,
Routes.pack_index_path(conn, :search, pack.ammo_type.name)
Routes.pack_index_path(conn, :search, pack.type.name)
)
refute index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: "something_else"}) =~
pack.ammo_type.name
pack.type.name
assert_patch(index_live, Routes.pack_index_path(conn, :search, "something_else"))
assert index_live
|> form(~s/form[phx-change="search"]/)
|> render_change(search: %{search_term: ""}) =~ pack.ammo_type.name
|> render_change(search: %{search_term: ""}) =~ pack.type.name
assert_patch(index_live, Routes.pack_index_path(conn, :index))
end
@ -366,9 +366,9 @@ defmodule CanneryWeb.PackLiveTest do
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)
pack = pack |> Repo.preload(:type)
assert html =~ "Show Ammo"
assert html =~ pack.ammo_type.name
assert html =~ pack.type.name
end
test "updates pack within modal", %{conn: conn, pack: pack} do

View File

@ -14,9 +14,9 @@ defmodule CanneryWeb.RangeLiveTest do
defp create_shot_record(%{current_user: current_user}) do
container = container_fixture(%{staged: true}, current_user)
ammo_type = ammo_type_fixture(current_user)
type = type_fixture(current_user)
{1, [pack]} = pack_fixture(%{staged: true}, ammo_type, container, current_user)
{1, [pack]} = pack_fixture(%{staged: true}, type, container, current_user)
shot_record =
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
@ -24,7 +24,7 @@ defmodule CanneryWeb.RangeLiveTest do
[
container: container,
ammo_type: ammo_type,
type: type,
pack: pack,
shot_record: shot_record
]
@ -42,18 +42,18 @@ defmodule CanneryWeb.RangeLiveTest do
test "can sort by type",
%{conn: conn, container: container, current_user: current_user} do
rifle_ammo_type = ammo_type_fixture(%{class: :rifle}, current_user)
{1, [rifle_pack]} = pack_fixture(rifle_ammo_type, container, current_user)
rifle_type = type_fixture(%{class: :rifle}, current_user)
{1, [rifle_pack]} = pack_fixture(rifle_type, container, current_user)
rifle_shot_record = shot_record_fixture(%{notes: "group_one"}, current_user, rifle_pack)
shotgun_ammo_type = ammo_type_fixture(%{class: :shotgun}, current_user)
{1, [shotgun_pack]} = pack_fixture(shotgun_ammo_type, container, current_user)
shotgun_type = type_fixture(%{class: :shotgun}, current_user)
{1, [shotgun_pack]} = pack_fixture(shotgun_type, container, current_user)
shotgun_shot_record = shot_record_fixture(%{notes: "group_two"}, current_user, shotgun_pack)
pistol_ammo_type = ammo_type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_ammo_type, container, current_user)
pistol_type = type_fixture(%{class: :pistol}, current_user)
{1, [pistol_pack]} = pack_fixture(pistol_type, container, current_user)
pistol_shot_record = shot_record_fixture(%{notes: "group_three"}, current_user, pistol_pack)
@ -68,7 +68,7 @@ defmodule CanneryWeb.RangeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :rifle})
|> render_change(type: %{class: :rifle})
assert html =~ rifle_shot_record.notes
refute html =~ shotgun_shot_record.notes
@ -77,7 +77,7 @@ defmodule CanneryWeb.RangeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :shotgun})
|> render_change(type: %{class: :shotgun})
refute html =~ rifle_shot_record.notes
assert html =~ shotgun_shot_record.notes
@ -86,7 +86,7 @@ defmodule CanneryWeb.RangeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :pistol})
|> render_change(type: %{class: :pistol})
refute html =~ rifle_shot_record.notes
refute html =~ shotgun_shot_record.notes
@ -95,7 +95,7 @@ defmodule CanneryWeb.RangeLiveTest do
html =
index_live
|> form(~s/form[phx-change="change_class"]/)
|> render_change(ammo_type: %{class: :all})
|> render_change(type: %{class: :all})
assert html =~ rifle_shot_record.notes
assert html =~ shotgun_shot_record.notes