add range mode
This commit is contained in:
		
							
								
								
									
										68
									
								
								test/cannery/activity_log_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								test/cannery/activity_log_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| defmodule Cannery.ActivityLogTest do | ||||
|   use Cannery.DataCase | ||||
|  | ||||
|   alias Cannery.ActivityLog | ||||
|  | ||||
|   describe "shot_groups" do | ||||
|     alias Cannery.ActivityLog.ShotGroup | ||||
|  | ||||
|     import Cannery.ActivityLogFixtures | ||||
|  | ||||
|     @invalid_attrs %{count: nil, date: nil, notes: nil} | ||||
|  | ||||
|     test "list_shot_groups/0 returns all shot_groups" do | ||||
|       shot_group = shot_group_fixture() | ||||
|       assert ActivityLog.list_shot_groups() == [shot_group] | ||||
|     end | ||||
|  | ||||
|     test "get_shot_group!/1 returns the shot_group with given id" do | ||||
|       shot_group = shot_group_fixture() | ||||
|       assert ActivityLog.get_shot_group!(shot_group.id) == shot_group | ||||
|     end | ||||
|  | ||||
|     test "create_shot_group/1 with valid data creates a shot_group" do | ||||
|       valid_attrs = %{count: 42, date: ~N[2022-02-13 03:17:00], notes: "some notes"} | ||||
|  | ||||
|       assert {:ok, %ShotGroup{} = shot_group} = ActivityLog.create_shot_group(valid_attrs) | ||||
|       assert shot_group.count == 42 | ||||
|       assert shot_group.date == ~N[2022-02-13 03:17:00] | ||||
|       assert shot_group.notes == "some notes" | ||||
|     end | ||||
|  | ||||
|     test "create_shot_group/1 with invalid data returns error changeset" do | ||||
|       assert {:error, %Ecto.Changeset{}} = ActivityLog.create_shot_group(@invalid_attrs) | ||||
|     end | ||||
|  | ||||
|     test "update_shot_group/2 with valid data updates the shot_group" do | ||||
|       shot_group = shot_group_fixture() | ||||
|       update_attrs = %{count: 43, date: ~N[2022-02-14 03:17:00], notes: "some updated notes"} | ||||
|  | ||||
|       assert {:ok, %ShotGroup{} = shot_group} = | ||||
|                ActivityLog.update_shot_group(shot_group, update_attrs) | ||||
|  | ||||
|       assert shot_group.count == 43 | ||||
|       assert shot_group.date == ~N[2022-02-14 03:17:00] | ||||
|       assert shot_group.notes == "some updated notes" | ||||
|     end | ||||
|  | ||||
|     test "update_shot_group/2 with invalid data returns error changeset" do | ||||
|       shot_group = shot_group_fixture() | ||||
|  | ||||
|       assert {:error, %Ecto.Changeset{}} = | ||||
|                ActivityLog.update_shot_group(shot_group, @invalid_attrs) | ||||
|  | ||||
|       assert shot_group == ActivityLog.get_shot_group!(shot_group.id) | ||||
|     end | ||||
|  | ||||
|     test "delete_shot_group/1 deletes the shot_group" do | ||||
|       shot_group = shot_group_fixture() | ||||
|       assert {:ok, %ShotGroup{}} = ActivityLog.delete_shot_group(shot_group) | ||||
|       assert_raise Ecto.NoResultsError, fn -> ActivityLog.get_shot_group!(shot_group.id) end | ||||
|     end | ||||
|  | ||||
|     test "change_shot_group/1 returns a shot_group changeset" do | ||||
|       shot_group = shot_group_fixture() | ||||
|       assert %Ecto.Changeset{} = ActivityLog.change_shot_group(shot_group) | ||||
|     end | ||||
|   end | ||||
| end | ||||
| @@ -24,7 +24,7 @@ defmodule CanneryWeb.AmmoGroupLiveTest do | ||||
|     test "lists all ammo_groups", %{conn: conn, ammo_group: ammo_group} do | ||||
|       {:ok, _index_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Listing Ammo groups" | ||||
|       assert html =~ "Ammo groups" | ||||
|       assert html =~ ammo_group.notes | ||||
|     end | ||||
|  | ||||
|   | ||||
| @@ -45,7 +45,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do | ||||
|     test "lists all ammo_types", %{conn: conn, ammo_type: ammo_type} do | ||||
|       {:ok, _index_live, html} = live(conn, Routes.ammo_type_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Listing Ammo types" | ||||
|       assert html =~ "Ammo types" | ||||
|       assert html =~ ammo_type.bullet_type | ||||
|     end | ||||
|  | ||||
|   | ||||
| @@ -38,7 +38,7 @@ defmodule CanneryWeb.ContainerLiveTest do | ||||
|     test "lists all containers", %{conn: conn, container: container} do | ||||
|       {:ok, _index_live, html} = live(conn, Routes.container_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ gettext("Listing Containers") | ||||
|       assert html =~ gettext("Containers") | ||||
|       assert html =~ container.desc | ||||
|     end | ||||
|  | ||||
|   | ||||
| @@ -24,7 +24,7 @@ defmodule CanneryWeb.InviteLiveTest do | ||||
|     test "lists all invites", %{conn: conn, invite: invite} do | ||||
|       {:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Listing Invites" | ||||
|       assert html =~ "Invites" | ||||
|       assert html =~ invite.name | ||||
|     end | ||||
|  | ||||
|   | ||||
							
								
								
									
										122
									
								
								test/cannery_web/live/shot_group_live_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								test/cannery_web/live/shot_group_live_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,122 @@ | ||||
| defmodule CanneryWeb.ShotGroupLiveTest do | ||||
|   use CanneryWeb.ConnCase | ||||
|  | ||||
|   import Phoenix.LiveViewTest | ||||
|   import Cannery.ActivityLogFixtures | ||||
|  | ||||
|   @create_attrs %{ | ||||
|     count: 42, | ||||
|     date: %{day: 13, hour: 3, minute: 17, month: 2, year: 2022}, | ||||
|     notes: "some notes" | ||||
|   } | ||||
|   @update_attrs %{ | ||||
|     count: 43, | ||||
|     date: %{day: 14, hour: 3, minute: 17, month: 2, year: 2022}, | ||||
|     notes: "some updated notes" | ||||
|   } | ||||
|   @invalid_attrs %{ | ||||
|     count: nil, | ||||
|     date: %{day: 30, hour: 3, minute: 17, month: 2, year: 2022}, | ||||
|     notes: nil | ||||
|   } | ||||
|  | ||||
|   defp create_shot_group(_) do | ||||
|     shot_group = shot_group_fixture() | ||||
|     %{shot_group: shot_group} | ||||
|   end | ||||
|  | ||||
|   describe "Index" do | ||||
|     setup [:create_shot_group] | ||||
|  | ||||
|     test "lists all shot_groups", %{conn: conn, shot_group: shot_group} do | ||||
|       {:ok, _index_live, html} = live(conn, Routes.shot_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Shot records" | ||||
|       assert html =~ shot_group.notes | ||||
|     end | ||||
|  | ||||
|     test "saves new shot_group", %{conn: conn} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.shot_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("a", "New Shot group") |> render_click() =~ | ||||
|                "New Shot group" | ||||
|  | ||||
|       assert_patch(index_live, Routes.shot_group_index_path(conn, :new)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#shot_group-form", shot_group: @invalid_attrs) | ||||
|              |> render_change() =~ "is invalid" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#shot_group-form", shot_group: @create_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.shot_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Shot group created 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.shot_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#shot_group-#{shot_group.id} a", "Edit") |> render_click() =~ | ||||
|                "Edit Shot group" | ||||
|  | ||||
|       assert_patch(index_live, Routes.shot_group_index_path(conn, :edit, shot_group)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#shot_group-form", shot_group: @invalid_attrs) | ||||
|              |> render_change() =~ "is invalid" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#shot_group-form", shot_group: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.shot_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Shot group 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.shot_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#shot_group-#{shot_group.id} a", "Delete") |> render_click() | ||||
|       refute has_element?(index_live, "#shot_group-#{shot_group.id}") | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   describe "Show" do | ||||
|     setup [:create_shot_group] | ||||
|  | ||||
|     test "displays shot_group", %{conn: conn, shot_group: shot_group} do | ||||
|       {:ok, _show_live, html} = live(conn, Routes.shot_group_show_path(conn, :show, shot_group)) | ||||
|  | ||||
|       assert html =~ "Show Shot group" | ||||
|       assert html =~ shot_group.notes | ||||
|     end | ||||
|  | ||||
|     test "updates shot_group within modal", %{conn: conn, shot_group: shot_group} do | ||||
|       {:ok, show_live, _html} = live(conn, Routes.shot_group_show_path(conn, :show, shot_group)) | ||||
|  | ||||
|       assert show_live |> element("a", "Edit") |> render_click() =~ | ||||
|                "Edit Shot group" | ||||
|  | ||||
|       assert_patch(show_live, Routes.shot_group_show_path(conn, :edit, shot_group)) | ||||
|  | ||||
|       assert show_live | ||||
|              |> form("#shot_group-form", shot_group: @invalid_attrs) | ||||
|              |> render_change() =~ "is invalid" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         show_live | ||||
|         |> form("#shot_group-form", shot_group: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.shot_group_show_path(conn, :show, shot_group)) | ||||
|  | ||||
|       assert html =~ "Shot group updated successfully" | ||||
|       assert html =~ "some updated notes" | ||||
|     end | ||||
|   end | ||||
| end | ||||
| @@ -36,7 +36,7 @@ defmodule CanneryWeb.TagLiveTest do | ||||
|     test "lists all tags", %{conn: conn, tag: tag} do | ||||
|       {:ok, _index_live, html} = live(conn, Routes.tag_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Listing Tags" | ||||
|       assert html =~ "Tags" | ||||
|       assert html =~ tag.bg_color | ||||
|     end | ||||
|  | ||||
|   | ||||
							
								
								
									
										22
									
								
								test/support/fixtures/activity_log_fixtures.ex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								test/support/fixtures/activity_log_fixtures.ex
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| defmodule Cannery.ActivityLogFixtures do | ||||
|   @moduledoc """ | ||||
|   This module defines test helpers for creating | ||||
|   entities via the `Cannery.ActivityLog` context. | ||||
|   """ | ||||
|  | ||||
|   @doc """ | ||||
|   Generate a shot_group. | ||||
|   """ | ||||
|   def shot_group_fixture(attrs \\ %{}) do | ||||
|     {:ok, shot_group} = | ||||
|       attrs | ||||
|       |> Enum.into(%{ | ||||
|         count: 42, | ||||
|         date: ~N[2022-02-13 03:17:00], | ||||
|         notes: "some notes" | ||||
|       }) | ||||
|       |> Cannery.ActivityLog.create_shot_group() | ||||
|  | ||||
|     shot_group | ||||
|   end | ||||
| end | ||||
		Reference in New Issue
	
	Block a user