forked from shibao/cannery
shot groups to shot records
This commit is contained in:
@ -16,14 +16,14 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
tag = tag_fixture(current_user)
|
||||
Containers.add_tag!(container, tag, current_user)
|
||||
{1, [pack]} = pack_fixture(ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(current_user, pack)
|
||||
shot_record = shot_record_fixture(current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
|
||||
%{
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
container: container,
|
||||
shot_group: shot_group,
|
||||
shot_record: shot_record,
|
||||
tag: tag
|
||||
}
|
||||
end
|
||||
@ -37,7 +37,7 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
shot_group: shot_group,
|
||||
shot_record: shot_record,
|
||||
tag: tag
|
||||
} do
|
||||
conn = get(conn, Routes.export_path(conn, :export, :json))
|
||||
@ -104,12 +104,12 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
"round_count" => container |> Ammo.get_round_count_for_container!(current_user)
|
||||
}
|
||||
|
||||
ideal_shot_group = %{
|
||||
"pack_id" => shot_group.pack_id,
|
||||
"count" => shot_group.count,
|
||||
"date" => to_string(shot_group.date),
|
||||
"id" => shot_group.id,
|
||||
"notes" => shot_group.notes
|
||||
ideal_shot_record = %{
|
||||
"pack_id" => shot_record.pack_id,
|
||||
"count" => shot_record.count,
|
||||
"date" => to_string(shot_record.date),
|
||||
"id" => shot_record.id,
|
||||
"notes" => shot_record.notes
|
||||
}
|
||||
|
||||
ideal_user = %{
|
||||
@ -127,7 +127,7 @@ defmodule CanneryWeb.ExportControllerTest do
|
||||
assert %{"packs" => [^ideal_pack]} = json_resp
|
||||
assert %{"ammo_types" => [^ideal_ammo_type]} = json_resp
|
||||
assert %{"containers" => [^ideal_container]} = json_resp
|
||||
assert %{"shot_groups" => [^ideal_shot_group]} = json_resp
|
||||
assert %{"shot_records" => [^ideal_shot_record]} = json_resp
|
||||
assert %{"user" => ^ideal_user} = json_resp
|
||||
end
|
||||
end
|
||||
|
@ -37,8 +37,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
notes: "some pack",
|
||||
count: 20
|
||||
}
|
||||
@shot_group_attrs %{
|
||||
notes: "some shot group",
|
||||
@shot_record_attrs %{
|
||||
notes: "some shot recorddd",
|
||||
count: 20
|
||||
}
|
||||
|
||||
@ -55,9 +55,9 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
defp create_empty_pack(%{ammo_type: ammo_type, current_user: current_user}) do
|
||||
container = container_fixture(current_user)
|
||||
{1, [pack]} = pack_fixture(@pack_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, pack)
|
||||
shot_record = shot_record_fixture(@shot_record_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[pack: pack, container: container, shot_group: shot_group]
|
||||
[pack: pack, container: container, shot_record: shot_record]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
@ -275,7 +275,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
|
||||
assert html =~ "\n0\n"
|
||||
assert html =~ "\n1\n"
|
||||
|
||||
shot_group_fixture(%{count: 5}, current_user, pack)
|
||||
shot_record_fixture(%{count: 5}, current_user, pack)
|
||||
|
||||
{:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index))
|
||||
|
||||
|
@ -12,18 +12,18 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
@update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7}
|
||||
@invalid_attrs %{count: nil, notes: nil, price_paid: nil}
|
||||
@pack_create_limit 10_000
|
||||
@shot_group_create_attrs %{ammo_left: 5, notes: "some notes"}
|
||||
@shot_group_update_attrs %{
|
||||
@shot_record_create_attrs %{ammo_left: 5, notes: "some notes"}
|
||||
@shot_record_update_attrs %{
|
||||
count: 5,
|
||||
date: ~N[2022-02-13 03:17:00],
|
||||
notes: "some updated notes"
|
||||
}
|
||||
@shot_group_invalid_attrs %{ammo_left: nil, count: nil, notes: nil}
|
||||
@shot_record_invalid_attrs %{ammo_left: nil, count: nil, notes: nil}
|
||||
@empty_attrs %{
|
||||
price_paid: 50,
|
||||
count: 20
|
||||
}
|
||||
@shot_group_attrs %{
|
||||
@shot_record_attrs %{
|
||||
price_paid: 50,
|
||||
count: 20
|
||||
}
|
||||
@ -35,10 +35,10 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
[ammo_type: ammo_type, pack: pack, container: container]
|
||||
end
|
||||
|
||||
defp create_shot_group(%{current_user: current_user, pack: pack}) do
|
||||
shot_group = shot_group_fixture(@shot_group_update_attrs, current_user, pack)
|
||||
defp create_shot_record(%{current_user: current_user, pack: pack}) do
|
||||
shot_record = shot_record_fixture(@shot_record_update_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[pack: pack, shot_group: shot_group]
|
||||
[pack: pack, shot_record: shot_record]
|
||||
end
|
||||
|
||||
defp create_empty_pack(%{
|
||||
@ -47,9 +47,9 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
container: container
|
||||
}) do
|
||||
{1, [pack]} = pack_fixture(@empty_attrs, ammo_type, container, current_user)
|
||||
shot_group = shot_group_fixture(@shot_group_attrs, current_user, pack)
|
||||
shot_record = shot_record_fixture(@shot_record_attrs, current_user, pack)
|
||||
pack = pack |> Repo.reload!()
|
||||
[empty_pack: pack, shot_group: shot_group]
|
||||
[empty_pack: pack, shot_record: shot_record]
|
||||
end
|
||||
|
||||
describe "Index of pack" do
|
||||
@ -311,20 +311,20 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
refute has_element?(index_live, "#pack-#{pack.id}")
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
test "saves new shot_record", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :add_shot_group, pack))
|
||||
assert_patch(index_live, Routes.pack_index_path(conn, :add_shot_record, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @shot_record_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> render_submit(shot_record: @shot_record_create_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
@ -394,66 +394,66 @@ defmodule CanneryWeb.PackLiveTest do
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
test "saves new shot_record", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.pack_show_path(conn, :add_shot_group, pack))
|
||||
assert_patch(index_live, Routes.pack_show_path(conn, :add_shot_record, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @shot_record_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_create_attrs)
|
||||
|> render_submit(shot_record: @shot_record_create_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show pack with shot group" do
|
||||
setup [:register_and_log_in_user, :create_pack, :create_shot_group]
|
||||
describe "Show pack with shot recorddd" do
|
||||
setup [:register_and_log_in_user, :create_pack, :create_shot_record]
|
||||
|
||||
test "updates shot_group in listing",
|
||||
%{conn: conn, pack: pack, shot_group: shot_group} do
|
||||
test "updates shot_record in listing",
|
||||
%{conn: conn, pack: pack, shot_record: shot_record} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.pack_show_path(conn, :edit, pack))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit shot group of #{shot_group.count} shots"]/)
|
||||
|> element(~s/a[aria-label="Edit shot recordd of #{shot_record.count} shots"]/)
|
||||
|> render_click() =~ "Edit Shot Records"
|
||||
|
||||
assert_patch(
|
||||
index_live,
|
||||
Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group)
|
||||
Routes.pack_show_path(conn, :edit_shot_record, pack, shot_record)
|
||||
)
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @shot_group_invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @shot_record_invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @shot_group_update_attrs)
|
||||
|> render_submit(shot_record: @shot_record_update_attrs)
|
||||
|> follow_redirect(conn, Routes.pack_show_path(conn, :show, pack))
|
||||
|
||||
assert html =~ "Shot records updated successfully"
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "deletes shot_group in listing",
|
||||
%{conn: conn, pack: pack, shot_group: shot_group} do
|
||||
test "deletes shot_record in listing",
|
||||
%{conn: conn, pack: pack, shot_record: shot_record} do
|
||||
{:ok, index_live, _html} =
|
||||
live(conn, Routes.pack_show_path(conn, :edit_shot_group, pack, shot_group))
|
||||
live(conn, Routes.pack_show_path(conn, :edit_shot_record, pack, shot_record))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_group.count} shots"]/)
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_record.count} shots"]/)
|
||||
|> render_click()
|
||||
|
||||
refute has_element?(index_live, "#shot_group-#{shot_group.id}")
|
||||
refute has_element?(index_live, "#shot_record-#{shot_record.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -12,32 +12,32 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
@update_attrs %{count: 16, notes: "some updated notes"}
|
||||
@invalid_attrs %{count: nil, notes: nil}
|
||||
|
||||
defp create_shot_group(%{current_user: current_user}) do
|
||||
defp create_shot_record(%{current_user: current_user}) do
|
||||
container = container_fixture(%{staged: true}, current_user)
|
||||
ammo_type = ammo_type_fixture(current_user)
|
||||
|
||||
{1, [pack]} = pack_fixture(%{staged: true}, ammo_type, container, current_user)
|
||||
|
||||
shot_group =
|
||||
shot_record =
|
||||
%{count: 5, date: ~N[2022-02-13 03:17:00], notes: "some notes"}
|
||||
|> shot_group_fixture(current_user, pack)
|
||||
|> shot_record_fixture(current_user, pack)
|
||||
|
||||
[
|
||||
container: container,
|
||||
ammo_type: ammo_type,
|
||||
pack: pack,
|
||||
shot_group: shot_group
|
||||
shot_record: shot_record
|
||||
]
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:register_and_log_in_user, :create_shot_group]
|
||||
setup [:register_and_log_in_user, :create_shot_record]
|
||||
|
||||
test "lists all shot_groups", %{conn: conn, shot_group: shot_group} do
|
||||
test "lists all shot_records", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Range day"
|
||||
assert html =~ shot_group.notes
|
||||
assert html =~ shot_record.notes
|
||||
end
|
||||
|
||||
test "can sort by type",
|
||||
@ -45,123 +45,123 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
rifle_ammo_type = ammo_type_fixture(%{class: :rifle}, current_user)
|
||||
{1, [rifle_pack]} = pack_fixture(rifle_ammo_type, container, current_user)
|
||||
|
||||
rifle_shot_group = shot_group_fixture(%{notes: "group_one"}, current_user, rifle_pack)
|
||||
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_shot_group = shot_group_fixture(%{notes: "group_two"}, current_user, shotgun_pack)
|
||||
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_shot_group = shot_group_fixture(%{notes: "group_three"}, current_user, pistol_pack)
|
||||
pistol_shot_record = shot_record_fixture(%{notes: "group_three"}, current_user, pistol_pack)
|
||||
|
||||
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ "All"
|
||||
|
||||
assert html =~ rifle_shot_group.notes
|
||||
assert html =~ shotgun_shot_group.notes
|
||||
assert html =~ pistol_shot_group.notes
|
||||
assert html =~ rifle_shot_record.notes
|
||||
assert html =~ shotgun_shot_record.notes
|
||||
assert html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :rifle})
|
||||
|
||||
assert html =~ rifle_shot_group.notes
|
||||
refute html =~ shotgun_shot_group.notes
|
||||
refute html =~ pistol_shot_group.notes
|
||||
assert html =~ rifle_shot_record.notes
|
||||
refute html =~ shotgun_shot_record.notes
|
||||
refute html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :shotgun})
|
||||
|
||||
refute html =~ rifle_shot_group.notes
|
||||
assert html =~ shotgun_shot_group.notes
|
||||
refute html =~ pistol_shot_group.notes
|
||||
refute html =~ rifle_shot_record.notes
|
||||
assert html =~ shotgun_shot_record.notes
|
||||
refute html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :pistol})
|
||||
|
||||
refute html =~ rifle_shot_group.notes
|
||||
refute html =~ shotgun_shot_group.notes
|
||||
assert html =~ pistol_shot_group.notes
|
||||
refute html =~ rifle_shot_record.notes
|
||||
refute html =~ shotgun_shot_record.notes
|
||||
assert html =~ pistol_shot_record.notes
|
||||
|
||||
html =
|
||||
index_live
|
||||
|> form(~s/form[phx-change="change_class"]/)
|
||||
|> render_change(ammo_type: %{class: :all})
|
||||
|
||||
assert html =~ rifle_shot_group.notes
|
||||
assert html =~ shotgun_shot_group.notes
|
||||
assert html =~ pistol_shot_group.notes
|
||||
assert html =~ rifle_shot_record.notes
|
||||
assert html =~ shotgun_shot_record.notes
|
||||
assert html =~ pistol_shot_record.notes
|
||||
end
|
||||
|
||||
test "can search for shot_group", %{conn: conn, shot_group: shot_group} do
|
||||
test "can search for shot_record", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ shot_group.notes
|
||||
assert html =~ shot_record.notes
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: shot_group.notes}) =~ shot_group.notes
|
||||
|> render_change(search: %{search_term: shot_record.notes}) =~ shot_record.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, shot_group.notes))
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, shot_record.notes))
|
||||
|
||||
refute index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: "something_else"}) =~ shot_group.notes
|
||||
|> render_change(search: %{search_term: "something_else"}) =~ shot_record.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :search, "something_else"))
|
||||
|
||||
assert index_live
|
||||
|> form(~s/form[phx-change="search"]/)
|
||||
|> render_change(search: %{search_term: ""}) =~ shot_group.notes
|
||||
|> render_change(search: %{search_term: ""}) =~ shot_record.notes
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :index))
|
||||
end
|
||||
|
||||
test "saves new shot_group", %{conn: conn, pack: pack} do
|
||||
test "saves new shot_record", %{conn: conn, pack: pack} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "Record shots") |> render_click() =~ "Record shots"
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_group, pack))
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_record, pack))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_submit(shot_group: @create_attrs)
|
||||
|> render_submit(shot_record: @create_attrs)
|
||||
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Shots recorded successfully"
|
||||
assert html =~ "some notes"
|
||||
end
|
||||
|
||||
test "updates shot_group in listing", %{conn: conn, shot_group: shot_group} do
|
||||
test "updates shot_record in listing", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Edit shot record of #{shot_group.count} shots"]/)
|
||||
|> element(~s/a[aria-label="Edit shot record of #{shot_record.count} shots"]/)
|
||||
|> render_click() =~ "Edit Shot Records"
|
||||
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :edit, shot_group))
|
||||
assert_patch(index_live, Routes.range_index_path(conn, :edit, shot_record))
|
||||
|
||||
assert index_live
|
||||
|> form("#shot-group-form")
|
||||
|> render_change(shot_group: @invalid_attrs) =~ "can't be blank"
|
||||
|> render_change(shot_record: @invalid_attrs) =~ "can't be blank"
|
||||
|
||||
{:ok, _view, html} =
|
||||
index_live
|
||||
|> form("#shot-group-form", shot_group: @update_attrs)
|
||||
|> form("#shot-group-form", shot_record: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
@ -169,14 +169,14 @@ defmodule CanneryWeb.RangeLiveTest do
|
||||
assert html =~ "some updated notes"
|
||||
end
|
||||
|
||||
test "deletes shot_group in listing", %{conn: conn, shot_group: shot_group} do
|
||||
test "deletes shot_record in listing", %{conn: conn, shot_record: shot_record} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
||||
|
||||
assert index_live
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_group.count} shots"]/)
|
||||
|> element(~s/a[aria-label="Delete shot record of #{shot_record.count} shots"]/)
|
||||
|> render_click()
|
||||
|
||||
refute has_element?(index_live, "#shot_group-#{shot_group.id}")
|
||||
refute has_element?(index_live, "#shot_record-#{shot_record.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user