forked from shibao/cannery
rename ammo type to type
This commit is contained in:
@ -13,10 +13,9 @@ defmodule Cannery.ActivityLogTest do
|
||||
setup do
|
||||
current_user = user_fixture()
|
||||
container = container_fixture(current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
type = type_fixture(current_user)
|
||||
|
||||
{1, [%{id: pack_id} = pack]} =
|
||||
pack_fixture(%{count: 25}, ammo_type, container, current_user)
|
||||
{1, [%{id: pack_id} = pack]} = pack_fixture(%{count: 25}, type, container, current_user)
|
||||
|
||||
shot_record =
|
||||
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
|
||||
@ -27,7 +26,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
[
|
||||
current_user: current_user,
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
type: type,
|
||||
pack: pack,
|
||||
shot_record: shot_record
|
||||
]
|
||||
@ -47,8 +46,8 @@ defmodule Cannery.ActivityLogTest do
|
||||
assert ActivityLog.get_shot_record_count!(other_user) == 0
|
||||
|
||||
container = container_fixture(other_user)
|
||||
ammo_type = ammo_type_fixture(other_user)
|
||||
{1, [pack]} = pack_fixture(%{count: 25}, ammo_type, container, other_user)
|
||||
type = type_fixture(other_user)
|
||||
{1, [pack]} = pack_fixture(%{count: 25}, type, container, other_user)
|
||||
shot_record_fixture(%{count: 1, date: ~N[2022-02-13 03:17:00]}, other_user, pack)
|
||||
assert ActivityLog.get_shot_record_count!(other_user) == 1
|
||||
end
|
||||
@ -191,11 +190,11 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
test "get_used_count/2 returns accurate used count", %{
|
||||
pack: pack,
|
||||
ammo_type: ammo_type,
|
||||
type: type,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [another_pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
{1, [another_pack]} = pack_fixture(type, container, current_user)
|
||||
assert 0 = another_pack |> ActivityLog.get_used_count(current_user)
|
||||
assert 5 = pack |> ActivityLog.get_used_count(current_user)
|
||||
|
||||
@ -205,18 +204,17 @@ defmodule Cannery.ActivityLogTest do
|
||||
shot_record_fixture(%{count: 10}, current_user, pack)
|
||||
assert 30 = pack |> ActivityLog.get_used_count(current_user)
|
||||
|
||||
{1, [another_pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
{1, [another_pack]} = pack_fixture(type, container, current_user)
|
||||
assert 0 = another_pack |> ActivityLog.get_used_count(current_user)
|
||||
end
|
||||
|
||||
test "get_used_counts/2 returns accurate used counts", %{
|
||||
pack: %{id: pack_id} = pack,
|
||||
ammo_type: ammo_type,
|
||||
type: type,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [%{id: another_pack_id} = another_pack]} =
|
||||
pack_fixture(ammo_type, container, current_user)
|
||||
{1, [%{id: another_pack_id} = another_pack]} = pack_fixture(type, container, current_user)
|
||||
|
||||
assert %{pack_id => 5} ==
|
||||
[pack, another_pack] |> ActivityLog.get_used_counts(current_user)
|
||||
@ -239,12 +237,12 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
test "get_last_used_date/2 returns accurate used count", %{
|
||||
pack: pack,
|
||||
ammo_type: ammo_type,
|
||||
type: type,
|
||||
container: container,
|
||||
shot_record: %{date: date},
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [another_pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
{1, [another_pack]} = pack_fixture(type, container, current_user)
|
||||
assert another_pack |> ActivityLog.get_last_used_date(current_user) |> is_nil()
|
||||
assert ^date = pack |> ActivityLog.get_last_used_date(current_user)
|
||||
|
||||
@ -257,13 +255,12 @@ defmodule Cannery.ActivityLogTest do
|
||||
|
||||
test "get_last_used_dates/2 returns accurate used counts", %{
|
||||
pack: %{id: pack_id} = pack,
|
||||
ammo_type: ammo_type,
|
||||
type: type,
|
||||
container: container,
|
||||
shot_record: %{date: date},
|
||||
current_user: current_user
|
||||
} do
|
||||
{1, [%{id: another_pack_id} = another_pack]} =
|
||||
pack_fixture(ammo_type, container, current_user)
|
||||
{1, [%{id: another_pack_id} = another_pack]} = pack_fixture(type, container, current_user)
|
||||
|
||||
# unset date
|
||||
assert %{pack_id => date} ==
|
||||
@ -297,49 +294,47 @@ defmodule Cannery.ActivityLogTest do
|
||||
assert %{^another_pack_id => ~D[2022-11-09]} = last_used_shot_records
|
||||
end
|
||||
|
||||
test "get_used_count_for_ammo_type/2 gets accurate used round count for ammo type",
|
||||
%{ammo_type: ammo_type, pack: pack, current_user: current_user} do
|
||||
another_ammo_type = ammo_type_fixture(current_user)
|
||||
assert 0 = another_ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
assert 5 = ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
test "get_used_count_for_type/2 gets accurate used round count for type",
|
||||
%{type: type, pack: pack, current_user: current_user} do
|
||||
another_type = type_fixture(current_user)
|
||||
assert 0 = another_type |> ActivityLog.get_used_count_for_type(current_user)
|
||||
assert 5 = type |> ActivityLog.get_used_count_for_type(current_user)
|
||||
|
||||
shot_record_fixture(%{count: 5}, current_user, pack)
|
||||
assert 10 = ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
assert 10 = type |> ActivityLog.get_used_count_for_type(current_user)
|
||||
|
||||
shot_record_fixture(%{count: 1}, current_user, pack)
|
||||
assert 11 = ammo_type |> ActivityLog.get_used_count_for_ammo_type(current_user)
|
||||
assert 11 = type |> ActivityLog.get_used_count_for_type(current_user)
|
||||
end
|
||||
|
||||
test "get_used_count_for_ammo_types/2 gets accurate used round count for ammo types", %{
|
||||
ammo_type: %{id: ammo_type_id} = ammo_type,
|
||||
test "get_used_count_for_types/2 gets accurate used round count for types", %{
|
||||
type: %{id: type_id} = type,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
# testing unused ammo type
|
||||
%{id: another_ammo_type_id} = another_ammo_type = ammo_type_fixture(current_user)
|
||||
{1, [pack]} = pack_fixture(another_ammo_type, container, current_user)
|
||||
# testing unused type
|
||||
%{id: another_type_id} = another_type = type_fixture(current_user)
|
||||
{1, [pack]} = pack_fixture(another_type, container, current_user)
|
||||
|
||||
assert %{ammo_type_id => 5} ==
|
||||
[ammo_type, another_ammo_type]
|
||||
|> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
assert %{type_id => 5} ==
|
||||
[type, another_type]
|
||||
|> ActivityLog.get_used_count_for_types(current_user)
|
||||
|
||||
# use generated pack
|
||||
shot_record_fixture(%{count: 5}, current_user, pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
used_counts = [type, another_type] |> ActivityLog.get_used_count_for_types(current_user)
|
||||
|
||||
assert %{^ammo_type_id => 5} = used_counts
|
||||
assert %{^another_ammo_type_id => 5} = used_counts
|
||||
assert %{^type_id => 5} = used_counts
|
||||
assert %{^another_type_id => 5} = used_counts
|
||||
|
||||
# use generated pack again
|
||||
shot_record_fixture(%{count: 1}, current_user, pack)
|
||||
|
||||
used_counts =
|
||||
[ammo_type, another_ammo_type] |> ActivityLog.get_used_count_for_ammo_types(current_user)
|
||||
used_counts = [type, another_type] |> ActivityLog.get_used_count_for_types(current_user)
|
||||
|
||||
assert %{^ammo_type_id => 5} = used_counts
|
||||
assert %{^another_ammo_type_id => 6} = used_counts
|
||||
assert %{^type_id => 5} = used_counts
|
||||
assert %{^another_type_id => 6} = used_counts
|
||||
end
|
||||
end
|
||||
|
||||
@ -347,13 +342,13 @@ defmodule Cannery.ActivityLogTest do
|
||||
setup do
|
||||
current_user = user_fixture()
|
||||
container = container_fixture(current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
{1, [pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
type = type_fixture(current_user)
|
||||
{1, [pack]} = pack_fixture(type, container, current_user)
|
||||
|
||||
[
|
||||
current_user: current_user,
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
type: type,
|
||||
pack: pack
|
||||
]
|
||||
end
|
||||
@ -364,21 +359,21 @@ defmodule Cannery.ActivityLogTest do
|
||||
other_container = container_fixture(other_user)
|
||||
|
||||
for class <- ["rifle", "shotgun", "pistol"] do
|
||||
other_ammo_type = ammo_type_fixture(%{class: class}, other_user)
|
||||
{1, [other_pack]} = pack_fixture(other_ammo_type, other_container, other_user)
|
||||
other_type = type_fixture(%{class: class}, other_user)
|
||||
{1, [other_pack]} = pack_fixture(other_type, other_container, other_user)
|
||||
shot_record_fixture(other_user, other_pack)
|
||||
end
|
||||
|
||||
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(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(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(current_user, pistol_pack)
|
||||
|
||||
assert [^rifle_shot_record] = ActivityLog.list_shot_records(:rifle, current_user)
|
||||
@ -399,29 +394,28 @@ defmodule Cannery.ActivityLogTest do
|
||||
end
|
||||
|
||||
test "list_shot_records/3 returns relevant shot_records for a search", %{
|
||||
ammo_type: ammo_type,
|
||||
type: type,
|
||||
pack: pack,
|
||||
container: container,
|
||||
current_user: current_user
|
||||
} do
|
||||
shot_record_a = shot_record_fixture(%{notes: "amazing"}, current_user, pack)
|
||||
|
||||
{1, [another_pack]} =
|
||||
pack_fixture(%{notes: "stupendous"}, ammo_type, container, current_user)
|
||||
{1, [another_pack]} = pack_fixture(%{notes: "stupendous"}, type, container, current_user)
|
||||
|
||||
shot_record_b = shot_record_fixture(current_user, another_pack)
|
||||
|
||||
another_ammo_type = ammo_type_fixture(%{name: "fabulous ammo"}, current_user)
|
||||
another_type = type_fixture(%{name: "fabulous ammo"}, current_user)
|
||||
|
||||
{1, [yet_another_pack]} = pack_fixture(another_ammo_type, container, current_user)
|
||||
{1, [yet_another_pack]} = pack_fixture(another_type, container, current_user)
|
||||
|
||||
shot_record_c = shot_record_fixture(current_user, yet_another_pack)
|
||||
|
||||
another_user = user_fixture()
|
||||
another_container = container_fixture(another_user)
|
||||
another_ammo_type = ammo_type_fixture(another_user)
|
||||
another_type = type_fixture(another_user)
|
||||
|
||||
{1, [another_pack]} = pack_fixture(another_ammo_type, another_container, another_user)
|
||||
{1, [another_pack]} = pack_fixture(another_type, another_container, another_user)
|
||||
|
||||
_shouldnt_return = shot_record_fixture(another_user, another_pack)
|
||||
|
||||
@ -431,7 +425,7 @@ defmodule Cannery.ActivityLogTest do
|
||||
# pack attributes
|
||||
assert ActivityLog.list_shot_records("stupendous", :all, current_user) == [shot_record_b]
|
||||
|
||||
# ammo type attributes
|
||||
# type attributes
|
||||
assert ActivityLog.list_shot_records("fabulous", :all, current_user) == [shot_record_c]
|
||||
end
|
||||
end
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -10,8 +10,8 @@ defmodule Cannery.Fixtures do
|
||||
Accounts.User,
|
||||
ActivityLog.ShotRecord,
|
||||
Ammo,
|
||||
Ammo.AmmoType,
|
||||
Ammo.Pack,
|
||||
Ammo.Type,
|
||||
Containers,
|
||||
Containers.Container,
|
||||
Containers.Tag,
|
||||
@ -102,11 +102,11 @@ defmodule Cannery.Fixtures do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a AmmoType
|
||||
Generate a Type
|
||||
"""
|
||||
@spec ammo_type_fixture(User.t()) :: AmmoType.t()
|
||||
@spec ammo_type_fixture(attrs :: map(), User.t()) :: AmmoType.t()
|
||||
def ammo_type_fixture(attrs \\ %{}, %User{} = user) do
|
||||
@spec type_fixture(User.t()) :: Type.t()
|
||||
@spec type_fixture(attrs :: map(), User.t()) :: Type.t()
|
||||
def type_fixture(attrs \\ %{}, %User{} = user) do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
name: random_string(),
|
||||
@ -142,34 +142,34 @@ defmodule Cannery.Fixtures do
|
||||
manufacturer: random_string(),
|
||||
upc: random_string()
|
||||
})
|
||||
|> Ammo.create_ammo_type(user)
|
||||
|> Ammo.create_type(user)
|
||||
|> unwrap_ok_tuple()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Generate a Pack
|
||||
"""
|
||||
@spec pack_fixture(AmmoType.t(), Container.t(), User.t()) ::
|
||||
@spec pack_fixture(Type.t(), Container.t(), User.t()) ::
|
||||
{count :: non_neg_integer(), [Pack.t()]}
|
||||
@spec pack_fixture(attrs :: map(), AmmoType.t(), Container.t(), User.t()) ::
|
||||
@spec pack_fixture(attrs :: map(), Type.t(), Container.t(), User.t()) ::
|
||||
{count :: non_neg_integer(), [Pack.t()]}
|
||||
@spec pack_fixture(
|
||||
attrs :: map(),
|
||||
multiplier :: non_neg_integer(),
|
||||
AmmoType.t(),
|
||||
Type.t(),
|
||||
Container.t(),
|
||||
User.t()
|
||||
) :: {count :: non_neg_integer(), [Pack.t()]}
|
||||
def pack_fixture(
|
||||
attrs \\ %{},
|
||||
multiplier \\ 1,
|
||||
%AmmoType{id: ammo_type_id},
|
||||
%Type{id: type_id},
|
||||
%Container{id: container_id},
|
||||
%User{} = user
|
||||
) do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
ammo_type_id: ammo_type_id,
|
||||
type_id: type_id,
|
||||
container_id: container_id,
|
||||
count: 20,
|
||||
purchased_on: Date.utc_today()
|
||||
|
Reference in New Issue
Block a user