forked from shibao/cannery
		
	add selectable ammo types
This commit is contained in:
		@@ -66,6 +66,60 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
 | 
			
		||||
      assert html =~ ammo_group.ammo_type.name
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "can sort by type",
 | 
			
		||||
         %{conn: conn, container: container, current_user: current_user} do
 | 
			
		||||
      rifle_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
 | 
			
		||||
      {1, [rifle_ammo_group]} = ammo_group_fixture(rifle_type, container, current_user)
 | 
			
		||||
      shotgun_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
 | 
			
		||||
      {1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_type, container, current_user)
 | 
			
		||||
      pistol_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
 | 
			
		||||
      {1, [pistol_ammo_group]} = ammo_group_fixture(pistol_type, container, current_user)
 | 
			
		||||
 | 
			
		||||
      {:ok, index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
      assert html =~ "All"
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :rifle})
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :shotgun})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :pistol})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :all})
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "can search for ammo_groups", %{conn: conn, ammo_group: ammo_group} do
 | 
			
		||||
      {:ok, index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
@@ -142,7 +196,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
 | 
			
		||||
        |> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
      assert html =~ dgettext("prompts", "Ammo added successfully")
 | 
			
		||||
      assert Ammo.list_ammo_groups(nil, false, current_user) |> Enum.count() == multiplier + 1
 | 
			
		||||
      assert Ammo.list_ammo_groups(nil, :all, current_user) |> Enum.count() == multiplier + 1
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "does not save invalid number of new ammo_groups", %{conn: conn} do
 | 
			
		||||
 
 | 
			
		||||
@@ -74,28 +74,77 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
 | 
			
		||||
      assert html =~ ammo_type.bullet_type
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "can sort by type", %{conn: conn, current_user: current_user} do
 | 
			
		||||
      rifle_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
 | 
			
		||||
      shotgun_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
 | 
			
		||||
      pistol_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
 | 
			
		||||
 | 
			
		||||
      {:ok, index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
      assert html =~ "All"
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_type.name
 | 
			
		||||
      assert html =~ shotgun_type.name
 | 
			
		||||
      assert html =~ pistol_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :rifle})
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_type.name
 | 
			
		||||
      refute html =~ shotgun_type.name
 | 
			
		||||
      refute html =~ pistol_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :shotgun})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_type.name
 | 
			
		||||
      assert html =~ shotgun_type.name
 | 
			
		||||
      refute html =~ pistol_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :pistol})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_type.name
 | 
			
		||||
      refute html =~ shotgun_type.name
 | 
			
		||||
      assert html =~ pistol_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :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))
 | 
			
		||||
 | 
			
		||||
      assert html =~ ammo_type.bullet_type
 | 
			
		||||
 | 
			
		||||
      assert index_live
 | 
			
		||||
             |> form(~s/form[phx-change="search"]/,
 | 
			
		||||
               search: %{search_term: ammo_type.bullet_type}
 | 
			
		||||
             )
 | 
			
		||||
             |> render_change() =~ ammo_type.bullet_type
 | 
			
		||||
             |> form(~s/form[phx-change="search"]/)
 | 
			
		||||
             |> render_change(search: %{search_term: ammo_type.bullet_type}) =~
 | 
			
		||||
               ammo_type.bullet_type
 | 
			
		||||
 | 
			
		||||
      assert_patch(index_live, Routes.ammo_type_index_path(conn, :search, ammo_type.bullet_type))
 | 
			
		||||
 | 
			
		||||
      refute index_live
 | 
			
		||||
             |> form(~s/form[phx-change="search"]/, search: %{search_term: "something_else"})
 | 
			
		||||
             |> render_change() =~ ammo_type.bullet_type
 | 
			
		||||
             |> form(~s/form[phx-change="search"]/)
 | 
			
		||||
             |> render_change(search: %{search_term: "something_else"}) =~ ammo_type.bullet_type
 | 
			
		||||
 | 
			
		||||
      assert_patch(index_live, Routes.ammo_type_index_path(conn, :search, "something_else"))
 | 
			
		||||
 | 
			
		||||
      assert index_live
 | 
			
		||||
             |> form(~s/form[phx-change="search"]/, search: %{search_term: ""})
 | 
			
		||||
             |> render_change() =~ ammo_type.bullet_type
 | 
			
		||||
             |> form(~s/form[phx-change="search"]/)
 | 
			
		||||
             |> render_change(search: %{search_term: ""}) =~ ammo_type.bullet_type
 | 
			
		||||
 | 
			
		||||
      assert_patch(index_live, Routes.ammo_type_index_path(conn, :index))
 | 
			
		||||
    end
 | 
			
		||||
@@ -114,8 +163,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
 | 
			
		||||
 | 
			
		||||
      {:ok, _view, html} =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form("#ammo_type-form", ammo_type: @create_attrs)
 | 
			
		||||
        |> render_submit()
 | 
			
		||||
        |> form("#ammo_type-form")
 | 
			
		||||
        |> render_submit(ammo_type: @create_attrs)
 | 
			
		||||
        |> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
      ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
 | 
			
		||||
@@ -138,8 +187,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
 | 
			
		||||
 | 
			
		||||
      {:ok, _view, html} =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form("#ammo_type-form", ammo_type: @update_attrs)
 | 
			
		||||
        |> render_submit()
 | 
			
		||||
        |> form("#ammo_type-form")
 | 
			
		||||
        |> render_submit(ammo_type: @update_attrs)
 | 
			
		||||
        |> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
      ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
 | 
			
		||||
@@ -163,8 +212,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
 | 
			
		||||
 | 
			
		||||
      {:ok, _view, html} =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form("#ammo_type-form", ammo_type: @create_attrs)
 | 
			
		||||
        |> render_submit()
 | 
			
		||||
        |> form("#ammo_type-form")
 | 
			
		||||
        |> render_submit(ammo_type: @create_attrs)
 | 
			
		||||
        |> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
      ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
 | 
			
		||||
@@ -188,10 +237,10 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
 | 
			
		||||
 | 
			
		||||
      {:ok, _view, html} =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form("#ammo_type-form",
 | 
			
		||||
        |> form("#ammo_type-form")
 | 
			
		||||
        |> render_submit(
 | 
			
		||||
          ammo_type: Map.merge(@create_attrs, %{"bullet_type" => "some updated bullet_type"})
 | 
			
		||||
        )
 | 
			
		||||
        |> render_submit()
 | 
			
		||||
        |> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
      ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
 | 
			
		||||
@@ -276,8 +325,8 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
 | 
			
		||||
 | 
			
		||||
      {:ok, _view, html} =
 | 
			
		||||
        show_live
 | 
			
		||||
        |> form("#ammo_type-form", ammo_type: @update_attrs)
 | 
			
		||||
        |> render_submit()
 | 
			
		||||
        |> form("#ammo_type-form")
 | 
			
		||||
        |> render_submit(ammo_type: @update_attrs)
 | 
			
		||||
        |> follow_redirect(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
 | 
			
		||||
 | 
			
		||||
      ammo_type = ammo_type.id |> Ammo.get_ammo_type!(current_user)
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ defmodule CanneryWeb.ContainerLiveTest do
 | 
			
		||||
  use CanneryWeb.ConnCase
 | 
			
		||||
  import Phoenix.LiveViewTest
 | 
			
		||||
  import CanneryWeb.Gettext
 | 
			
		||||
  alias Cannery.{Containers, Repo}
 | 
			
		||||
  alias Cannery.Containers
 | 
			
		||||
 | 
			
		||||
  @moduletag :container_live_test
 | 
			
		||||
 | 
			
		||||
@@ -34,10 +34,6 @@ defmodule CanneryWeb.ContainerLiveTest do
 | 
			
		||||
    "notes" => "some ammo group",
 | 
			
		||||
    "count" => 20
 | 
			
		||||
  }
 | 
			
		||||
  @shot_group_attrs %{
 | 
			
		||||
    "notes" => "some shot group",
 | 
			
		||||
    "count" => 20
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  # @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
 | 
			
		||||
 | 
			
		||||
@@ -53,15 +49,6 @@ defmodule CanneryWeb.ContainerLiveTest do
 | 
			
		||||
    %{ammo_type: ammo_type, ammo_group: ammo_group}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  defp create_empty_ammo_group(%{container: container, current_user: current_user}) do
 | 
			
		||||
    ammo_type = ammo_type_fixture(@ammo_type_attrs, current_user)
 | 
			
		||||
    {1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
 | 
			
		||||
    shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
 | 
			
		||||
    ammo_group = ammo_group |> Repo.reload!()
 | 
			
		||||
 | 
			
		||||
    %{ammo_type: ammo_type, ammo_group: ammo_group, shot_group: shot_group}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "Index" do
 | 
			
		||||
    setup [:register_and_log_in_user, :create_container]
 | 
			
		||||
 | 
			
		||||
@@ -263,6 +250,60 @@ defmodule CanneryWeb.ContainerLiveTest do
 | 
			
		||||
      assert html =~ dgettext("prompts", "%{name} updated successfully", name: container.name)
 | 
			
		||||
      assert html =~ "some updated location"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "can sort by type",
 | 
			
		||||
         %{conn: conn, container: container, current_user: current_user} do
 | 
			
		||||
      rifle_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
 | 
			
		||||
      {1, [rifle_ammo_group]} = ammo_group_fixture(rifle_type, container, current_user)
 | 
			
		||||
      shotgun_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
 | 
			
		||||
      {1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_type, container, current_user)
 | 
			
		||||
      pistol_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
 | 
			
		||||
      {1, [pistol_ammo_group]} = ammo_group_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_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :rifle})
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :shotgun})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :pistol})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      refute html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :all})
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ shotgun_ammo_group.ammo_type.name
 | 
			
		||||
      assert html =~ pistol_ammo_group.ammo_type.name
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "Show with ammo group" do
 | 
			
		||||
@@ -289,47 +330,4 @@ defmodule CanneryWeb.ContainerLiveTest do
 | 
			
		||||
      assert html =~ "\n20\n"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "Show with empty ammo group" do
 | 
			
		||||
    setup [:register_and_log_in_user, :create_container, :create_empty_ammo_group]
 | 
			
		||||
 | 
			
		||||
    test "hides empty ammo groups by default",
 | 
			
		||||
         %{conn: conn, ammo_type: %{name: ammo_type_name}, container: container} do
 | 
			
		||||
      {:ok, show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
 | 
			
		||||
 | 
			
		||||
      assert html =~ dgettext("actions", "Show used")
 | 
			
		||||
      refute html =~ "\n20\n"
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        show_live
 | 
			
		||||
        |> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
 | 
			
		||||
        |> render_click()
 | 
			
		||||
 | 
			
		||||
      assert html =~ ammo_type_name
 | 
			
		||||
      assert html =~ "\n20\n"
 | 
			
		||||
      assert html =~ "Empty"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "displays empty ammo groups in table on toggle",
 | 
			
		||||
         %{conn: conn, ammo_type: %{name: ammo_type_name}, container: container} do
 | 
			
		||||
      {:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container))
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        show_live
 | 
			
		||||
        |> element(~s/input[type="checkbox"][aria-labelledby="toggle_table-label"}]/)
 | 
			
		||||
        |> render_click()
 | 
			
		||||
 | 
			
		||||
      assert html =~ dgettext("actions", "Show used")
 | 
			
		||||
      refute html =~ "\n20\n"
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        show_live
 | 
			
		||||
        |> element(~s/input[type="checkbox"][aria-labelledby="toggle_show_used-label"}]/)
 | 
			
		||||
        |> render_click()
 | 
			
		||||
 | 
			
		||||
      assert html =~ ammo_type_name
 | 
			
		||||
      assert html =~ "\n20\n"
 | 
			
		||||
      assert html =~ "Empty"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,12 @@ defmodule CanneryWeb.RangeLiveTest do
 | 
			
		||||
      %{"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}
 | 
			
		||||
    [
 | 
			
		||||
      container: container,
 | 
			
		||||
      ammo_type: ammo_type,
 | 
			
		||||
      ammo_group: ammo_group,
 | 
			
		||||
      shot_group: shot_group
 | 
			
		||||
    ]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "Index" do
 | 
			
		||||
@@ -37,6 +42,71 @@ defmodule CanneryWeb.RangeLiveTest do
 | 
			
		||||
      assert html =~ shot_group.notes
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "can sort by type",
 | 
			
		||||
         %{conn: conn, container: container, current_user: current_user} do
 | 
			
		||||
      rifle_ammo_type = ammo_type_fixture(%{"type" => "rifle"}, current_user)
 | 
			
		||||
      {1, [rifle_ammo_group]} = ammo_group_fixture(rifle_ammo_type, container, current_user)
 | 
			
		||||
 | 
			
		||||
      rifle_shot_group =
 | 
			
		||||
        shot_group_fixture(%{"notes" => "group_one"}, current_user, rifle_ammo_group)
 | 
			
		||||
 | 
			
		||||
      shotgun_ammo_type = ammo_type_fixture(%{"type" => "shotgun"}, current_user)
 | 
			
		||||
      {1, [shotgun_ammo_group]} = ammo_group_fixture(shotgun_ammo_type, container, current_user)
 | 
			
		||||
 | 
			
		||||
      shotgun_shot_group =
 | 
			
		||||
        shot_group_fixture(%{"notes" => "group_two"}, current_user, shotgun_ammo_group)
 | 
			
		||||
 | 
			
		||||
      pistol_ammo_type = ammo_type_fixture(%{"type" => "pistol"}, current_user)
 | 
			
		||||
      {1, [pistol_ammo_group]} = ammo_group_fixture(pistol_ammo_type, container, current_user)
 | 
			
		||||
 | 
			
		||||
      pistol_shot_group =
 | 
			
		||||
        shot_group_fixture(%{"notes" => "group_three"}, current_user, pistol_ammo_group)
 | 
			
		||||
 | 
			
		||||
      {: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
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :rifle})
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_shot_group.notes
 | 
			
		||||
      refute html =~ shotgun_shot_group.notes
 | 
			
		||||
      refute html =~ pistol_shot_group.notes
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :shotgun})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_shot_group.notes
 | 
			
		||||
      assert html =~ shotgun_shot_group.notes
 | 
			
		||||
      refute html =~ pistol_shot_group.notes
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :pistol})
 | 
			
		||||
 | 
			
		||||
      refute html =~ rifle_shot_group.notes
 | 
			
		||||
      refute html =~ shotgun_shot_group.notes
 | 
			
		||||
      assert html =~ pistol_shot_group.notes
 | 
			
		||||
 | 
			
		||||
      html =
 | 
			
		||||
        index_live
 | 
			
		||||
        |> form(~s/form[phx-change="change_type"]/)
 | 
			
		||||
        |> render_change(ammo_type: %{type: :all})
 | 
			
		||||
 | 
			
		||||
      assert html =~ rifle_shot_group.notes
 | 
			
		||||
      assert html =~ shotgun_shot_group.notes
 | 
			
		||||
      assert html =~ pistol_shot_group.notes
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    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))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user