forked from shibao/cannery
		
	add search to range index
This commit is contained in:
		@@ -38,17 +38,56 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
      ]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "list_shot_groups/0 returns all shot_groups",
 | 
			
		||||
    test "list_shot_groups/1 returns all shot_groups",
 | 
			
		||||
         %{shot_group: shot_group, current_user: current_user} do
 | 
			
		||||
      assert ActivityLog.list_shot_groups(current_user) == [shot_group]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "get_shot_group!/1 returns the shot_group with given id",
 | 
			
		||||
    test "list_shot_groups/2 returns relevant shot_groups for a user", %{
 | 
			
		||||
      ammo_type: ammo_type,
 | 
			
		||||
      ammo_group: ammo_group,
 | 
			
		||||
      container: container,
 | 
			
		||||
      current_user: current_user
 | 
			
		||||
    } do
 | 
			
		||||
      shot_group_a = shot_group_fixture(%{"notes" => "amazing"}, current_user, ammo_group)
 | 
			
		||||
 | 
			
		||||
      {1, [another_ammo_group]} =
 | 
			
		||||
        ammo_group_fixture(%{"notes" => "stupendous"}, ammo_type, container, current_user)
 | 
			
		||||
 | 
			
		||||
      shot_group_b = shot_group_fixture(current_user, another_ammo_group)
 | 
			
		||||
 | 
			
		||||
      another_ammo_type = ammo_type_fixture(%{"name" => "fabulous ammo"}, current_user)
 | 
			
		||||
 | 
			
		||||
      {1, [yet_another_ammo_group]} =
 | 
			
		||||
        ammo_group_fixture(another_ammo_type, container, current_user)
 | 
			
		||||
 | 
			
		||||
      shot_group_c = shot_group_fixture(current_user, yet_another_ammo_group)
 | 
			
		||||
 | 
			
		||||
      random_user = user_fixture()
 | 
			
		||||
      random_container = container_fixture(random_user)
 | 
			
		||||
      random_ammo_type = ammo_type_fixture(random_user)
 | 
			
		||||
 | 
			
		||||
      {1, [random_ammo_group]} =
 | 
			
		||||
        ammo_group_fixture(random_ammo_type, random_container, random_user)
 | 
			
		||||
 | 
			
		||||
      _shouldnt_return = shot_group_fixture(random_user, random_ammo_group)
 | 
			
		||||
 | 
			
		||||
      # notes
 | 
			
		||||
      assert ActivityLog.list_shot_groups("amazing", current_user) == [shot_group_a]
 | 
			
		||||
 | 
			
		||||
      # ammo group attributes
 | 
			
		||||
      assert ActivityLog.list_shot_groups("stupendous", current_user) == [shot_group_b]
 | 
			
		||||
 | 
			
		||||
      # ammo type attributes
 | 
			
		||||
      assert ActivityLog.list_shot_groups("fabulous", current_user) == [shot_group_c]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "get_shot_group!/2 returns the shot_group with given id",
 | 
			
		||||
         %{shot_group: shot_group, current_user: current_user} do
 | 
			
		||||
      assert ActivityLog.get_shot_group!(shot_group.id, current_user) == shot_group
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "get_shot_group!/1 does not return a shot_group of another user",
 | 
			
		||||
    test "get_shot_group!/2 does not return a shot_group of another user",
 | 
			
		||||
         %{shot_group: shot_group} do
 | 
			
		||||
      another_user = user_fixture()
 | 
			
		||||
 | 
			
		||||
@@ -57,7 +96,7 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "create_shot_group/1 with valid data creates a shot_group",
 | 
			
		||||
    test "create_shot_group/3 with valid data creates a shot_group",
 | 
			
		||||
         %{current_user: current_user, ammo_group: ammo_group} do
 | 
			
		||||
      valid_attrs = %{"count" => 10, "date" => ~D[2022-02-13], "notes" => "some notes"}
 | 
			
		||||
 | 
			
		||||
@@ -69,7 +108,7 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
      assert shot_group.notes == "some notes"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "create_shot_group/1 removes corresponding count from ammo group",
 | 
			
		||||
    test "create_shot_group/3 removes corresponding count from ammo group",
 | 
			
		||||
         %{
 | 
			
		||||
           current_user: current_user,
 | 
			
		||||
           ammo_group: %{id: ammo_group_id, count: org_count} = ammo_group
 | 
			
		||||
@@ -85,7 +124,7 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
      assert new_count == 10
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "create_shot_group/1 does not remove more than ammo group amount",
 | 
			
		||||
    test "create_shot_group/3 does not remove more than ammo group amount",
 | 
			
		||||
         %{current_user: current_user, ammo_group: %{id: ammo_group_id} = ammo_group} do
 | 
			
		||||
      valid_attrs = %{"count" => 20, "date" => ~D[2022-02-13], "notes" => "some notes"}
 | 
			
		||||
 | 
			
		||||
@@ -100,7 +139,7 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
               ActivityLog.create_shot_group(%{"count" => 1}, current_user, ammo_group)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "create_shot_group/1 with invalid data returns error changeset",
 | 
			
		||||
    test "create_shot_group/3 with invalid data returns error changeset",
 | 
			
		||||
         %{current_user: current_user, ammo_group: ammo_group} do
 | 
			
		||||
      invalid_params = %{"count" => nil, "date" => nil, "notes" => nil}
 | 
			
		||||
 | 
			
		||||
@@ -108,7 +147,7 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
               ActivityLog.create_shot_group(invalid_params, current_user, ammo_group)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "update_shot_group/2 with valid data updates the shot_group and ammo_group",
 | 
			
		||||
    test "update_shot_group/3 with valid data updates the shot_group and ammo_group",
 | 
			
		||||
         %{
 | 
			
		||||
           shot_group: shot_group,
 | 
			
		||||
           ammo_group: %{id: ammo_group_id},
 | 
			
		||||
@@ -149,7 +188,7 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
      assert ammo_group.count == 0
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "update_shot_group/2 with invalid data returns error changeset",
 | 
			
		||||
    test "update_shot_group/3 with invalid data returns error changeset",
 | 
			
		||||
         %{shot_group: shot_group, current_user: current_user} do
 | 
			
		||||
      assert {:error, %Ecto.Changeset{}} =
 | 
			
		||||
               ActivityLog.update_shot_group(
 | 
			
		||||
@@ -168,7 +207,7 @@ defmodule Cannery.ActivityLogTest do
 | 
			
		||||
      assert shot_group == ActivityLog.get_shot_group!(shot_group.id, current_user)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "delete_shot_group/1 deletes the shot_group and adds value back",
 | 
			
		||||
    test "delete_shot_group/2 deletes the shot_group and adds value back",
 | 
			
		||||
         %{shot_group: shot_group, current_user: current_user, ammo_group: %{id: ammo_group_id}} do
 | 
			
		||||
      assert {:ok, %ShotGroup{}} = ActivityLog.delete_shot_group(shot_group, current_user)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -37,6 +37,32 @@ defmodule CanneryWeb.RangeLiveTest do
 | 
			
		||||
      assert html =~ 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))
 | 
			
		||||
 | 
			
		||||
      assert html =~ shot_group.notes
 | 
			
		||||
 | 
			
		||||
      assert index_live
 | 
			
		||||
             |> form("[data-qa=\"shot_group_search\"]",
 | 
			
		||||
               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
 | 
			
		||||
             |> form("[data-qa=\"shot_group_search\"]", search: %{search_term: "something_else"})
 | 
			
		||||
             |> render_change() =~ shot_group.notes
 | 
			
		||||
 | 
			
		||||
      assert_patch(index_live, Routes.range_index_path(conn, :search, "something_else"))
 | 
			
		||||
 | 
			
		||||
      assert index_live
 | 
			
		||||
             |> form("[data-qa=\"shot_group_search\"]", search: %{search_term: ""})
 | 
			
		||||
             |> render_change() =~ shot_group.notes
 | 
			
		||||
 | 
			
		||||
      assert_patch(index_live, Routes.range_index_path(conn, :index))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
 | 
			
		||||
      {:ok, index_live, _html} = live(conn, Routes.range_index_path(conn, :index))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user