2022-02-16 23:30:12 -05:00
|
|
|
defmodule CanneryWeb.RangeLiveTest do
|
|
|
|
@moduledoc """
|
|
|
|
This module tests the Range LiveViews
|
|
|
|
"""
|
|
|
|
|
|
|
|
use CanneryWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
import Cannery.Fixtures
|
|
|
|
import CanneryWeb.Gettext
|
|
|
|
|
|
|
|
@moduletag :range_live_test
|
|
|
|
@create_attrs %{"ammo_left" => 5, "notes" => "some notes"}
|
|
|
|
@update_attrs %{"count" => 16, "notes" => "some updated notes"}
|
2022-02-17 20:01:14 -05:00
|
|
|
# @invalid_attrs %{"count" => nil, "notes" => nil}
|
2022-02-16 23:30:12 -05:00
|
|
|
|
|
|
|
defp create_shot_group(%{current_user: current_user}) do
|
|
|
|
container = container_fixture(%{"staged" => true}, current_user)
|
|
|
|
ammo_type = ammo_type_fixture(current_user)
|
2022-02-24 00:16:23 -05:00
|
|
|
|
|
|
|
{1, [ammo_group]} =
|
|
|
|
ammo_group_fixture(%{"staged" => true}, ammo_type, container, current_user)
|
2022-02-16 23:30:12 -05:00
|
|
|
|
|
|
|
shot_group =
|
|
|
|
%{"count" => 5, "date" => ~N[2022-02-13 03:17:00], "notes" => "some notes"}
|
|
|
|
|> shot_group_fixture(current_user, ammo_group)
|
|
|
|
|
|
|
|
%{shot_group: shot_group, ammo_group: ammo_group}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Index" do
|
|
|
|
setup [:register_and_log_in_user, :create_shot_group]
|
|
|
|
|
|
|
|
test "lists all shot_groups", %{conn: conn, shot_group: shot_group} do
|
|
|
|
{:ok, _index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
|
|
|
|
|
|
|
assert html =~ gettext("Range day")
|
|
|
|
assert html =~ shot_group.notes
|
|
|
|
end
|
|
|
|
|
2022-12-03 21:27:39 -05:00
|
|
|
test "can search for shot_group", %{conn: conn, shot_group: shot_group} do
|
|
|
|
{:ok, index_live, html} = live(conn, Routes.range_index_path(conn, :index))
|
|
|
|
|
|
|
|
assert html =~ shot_group.notes
|
|
|
|
|
|
|
|
assert index_live
|
2023-03-15 00:45:08 -04:00
|
|
|
|> form(~s/form[phx-change="search"]/,
|
2022-12-03 21:27:39 -05:00
|
|
|
search: %{search_term: shot_group.notes}
|
|
|
|
)
|
|
|
|
|> render_change() =~ shot_group.notes
|
|
|
|
|
|
|
|
assert_patch(index_live, Routes.range_index_path(conn, :search, shot_group.notes))
|
|
|
|
|
|
|
|
refute index_live
|
2023-03-15 00:45:08 -04:00
|
|
|
|> form(~s/form[phx-change="search"]/, search: %{search_term: "something_else"})
|
2022-12-03 21:27:39 -05:00
|
|
|
|> render_change() =~ shot_group.notes
|
|
|
|
|
|
|
|
assert_patch(index_live, Routes.range_index_path(conn, :search, "something_else"))
|
|
|
|
|
|
|
|
assert index_live
|
2023-03-15 00:45:08 -04:00
|
|
|
|> form(~s/form[phx-change="search"]/, search: %{search_term: ""})
|
2022-12-03 21:27:39 -05:00
|
|
|
|> render_change() =~ shot_group.notes
|
|
|
|
|
|
|
|
assert_patch(index_live, Routes.range_index_path(conn, :index))
|
|
|
|
end
|
|
|
|
|
2022-02-16 23:30:12 -05:00
|
|
|
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
|
|
|
|
|
|
|
assert index_live |> element("a", dgettext("actions", "Record shots")) |> render_click() =~
|
2022-02-17 20:01:14 -05:00
|
|
|
gettext("Record shots")
|
2022-02-16 23:30:12 -05:00
|
|
|
|
|
|
|
assert_patch(index_live, Routes.range_index_path(conn, :add_shot_group, ammo_group))
|
|
|
|
|
|
|
|
# assert index_live
|
|
|
|
# |> form("#shot_group-form", shot_group: @invalid_attrs)
|
|
|
|
# |> render_change() =~ dgettext("errors", "is invalid")
|
|
|
|
|
2022-03-28 23:05:12 -04:00
|
|
|
{:ok, _view, html} =
|
2022-02-16 23:30:12 -05:00
|
|
|
index_live
|
|
|
|
|> form("#shot-group-form", shot_group: @create_attrs)
|
|
|
|
|> render_submit()
|
|
|
|
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
|
|
|
|
|
|
|
assert html =~ dgettext("prompts", "Shots recorded successfully")
|
|
|
|
assert html =~ "some notes"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updates shot_group in listing", %{conn: conn, shot_group: shot_group} do
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
|
|
|
|
2023-03-15 00:45:08 -04:00
|
|
|
assert index_live
|
|
|
|
|> element(~s/a[aria-label="Edit shot record of #{shot_group.count} shots"]/)
|
|
|
|
|> render_click() =~
|
2022-02-16 23:30:12 -05:00
|
|
|
gettext("Edit Shot Records")
|
|
|
|
|
|
|
|
assert_patch(index_live, Routes.range_index_path(conn, :edit, shot_group))
|
|
|
|
|
|
|
|
# assert index_live
|
|
|
|
# |> form("#shot_group-form", shot_group: @invalid_attrs)
|
|
|
|
# |> render_change() =~ dgettext("errors", "is invalid")
|
|
|
|
|
2022-03-28 23:05:12 -04:00
|
|
|
{:ok, _view, html} =
|
2022-02-16 23:30:12 -05:00
|
|
|
index_live
|
|
|
|
|> form("#shot-group-form", shot_group: @update_attrs)
|
|
|
|
|> render_submit()
|
|
|
|
|> follow_redirect(conn, Routes.range_index_path(conn, :index))
|
|
|
|
|
|
|
|
assert html =~ dgettext("actions", "Shot records updated successfully")
|
|
|
|
assert html =~ "some updated notes"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes shot_group in listing", %{conn: conn, shot_group: shot_group} do
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
|
|
|
|
|
2023-03-15 00:45:08 -04:00
|
|
|
assert index_live
|
|
|
|
|> element(~s/a[aria-label="Delete shot record of #{shot_group.count} shots"]/)
|
|
|
|
|> render_click()
|
|
|
|
|
2022-02-16 23:30:12 -05:00
|
|
|
refute has_element?(index_live, "#shot_group-#{shot_group.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|