shot groups to shot records
This commit is contained in:
@ -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