add models, context and liveviews
This commit is contained in:
		
							
								
								
									
										137
									
								
								test/cannery/ammo_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								test/cannery/ammo_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,137 @@ | ||||
| defmodule Cannery.AmmoTest do | ||||
|   use Cannery.DataCase | ||||
|  | ||||
|   alias Cannery.Ammo | ||||
|  | ||||
|   describe "ammo_types" do | ||||
|     alias Cannery.Ammo.AmmoType | ||||
|  | ||||
|     @valid_attrs %{bullet_type: "some bullet_type", case_material: "some case_material", desc: "some desc", manufacturer: "some manufacturer", name: "some name", weight: 120.5} | ||||
|     @update_attrs %{bullet_type: "some updated bullet_type", case_material: "some updated case_material", desc: "some updated desc", manufacturer: "some updated manufacturer", name: "some updated name", weight: 456.7} | ||||
|     @invalid_attrs %{bullet_type: nil, case_material: nil, desc: nil, manufacturer: nil, name: nil, weight: nil} | ||||
|  | ||||
|     def ammo_type_fixture(attrs \\ %{}) do | ||||
|       {:ok, ammo_type} = | ||||
|         attrs | ||||
|         |> Enum.into(@valid_attrs) | ||||
|         |> Ammo.create_ammo_type() | ||||
|  | ||||
|       ammo_type | ||||
|     end | ||||
|  | ||||
|     test "list_ammo_types/0 returns all ammo_types" do | ||||
|       ammo_type = ammo_type_fixture() | ||||
|       assert Ammo.list_ammo_types() == [ammo_type] | ||||
|     end | ||||
|  | ||||
|     test "get_ammo_type!/1 returns the ammo_type with given id" do | ||||
|       ammo_type = ammo_type_fixture() | ||||
|       assert Ammo.get_ammo_type!(ammo_type.id) == ammo_type | ||||
|     end | ||||
|  | ||||
|     test "create_ammo_type/1 with valid data creates a ammo_type" do | ||||
|       assert {:ok, %AmmoType{} = ammo_type} = Ammo.create_ammo_type(@valid_attrs) | ||||
|       assert ammo_type.bullet_type == "some bullet_type" | ||||
|       assert ammo_type.case_material == "some case_material" | ||||
|       assert ammo_type.desc == "some desc" | ||||
|       assert ammo_type.manufacturer == "some manufacturer" | ||||
|       assert ammo_type.name == "some name" | ||||
|       assert ammo_type.weight == 120.5 | ||||
|     end | ||||
|  | ||||
|     test "create_ammo_type/1 with invalid data returns error changeset" do | ||||
|       assert {:error, %Ecto.Changeset{}} = Ammo.create_ammo_type(@invalid_attrs) | ||||
|     end | ||||
|  | ||||
|     test "update_ammo_type/2 with valid data updates the ammo_type" do | ||||
|       ammo_type = ammo_type_fixture() | ||||
|       assert {:ok, %AmmoType{} = ammo_type} = Ammo.update_ammo_type(ammo_type, @update_attrs) | ||||
|       assert ammo_type.bullet_type == "some updated bullet_type" | ||||
|       assert ammo_type.case_material == "some updated case_material" | ||||
|       assert ammo_type.desc == "some updated desc" | ||||
|       assert ammo_type.manufacturer == "some updated manufacturer" | ||||
|       assert ammo_type.name == "some updated name" | ||||
|       assert ammo_type.weight == 456.7 | ||||
|     end | ||||
|  | ||||
|     test "update_ammo_type/2 with invalid data returns error changeset" do | ||||
|       ammo_type = ammo_type_fixture() | ||||
|       assert {:error, %Ecto.Changeset{}} = Ammo.update_ammo_type(ammo_type, @invalid_attrs) | ||||
|       assert ammo_type == Ammo.get_ammo_type!(ammo_type.id) | ||||
|     end | ||||
|  | ||||
|     test "delete_ammo_type/1 deletes the ammo_type" do | ||||
|       ammo_type = ammo_type_fixture() | ||||
|       assert {:ok, %AmmoType{}} = Ammo.delete_ammo_type(ammo_type) | ||||
|       assert_raise Ecto.NoResultsError, fn -> Ammo.get_ammo_type!(ammo_type.id) end | ||||
|     end | ||||
|  | ||||
|     test "change_ammo_type/1 returns a ammo_type changeset" do | ||||
|       ammo_type = ammo_type_fixture() | ||||
|       assert %Ecto.Changeset{} = Ammo.change_ammo_type(ammo_type) | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   describe "ammo_groups" do | ||||
|     alias Cannery.Ammo.AmmoGroup | ||||
|  | ||||
|     @valid_attrs %{count: 42, notes: "some notes", price_paid: 120.5} | ||||
|     @update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7} | ||||
|     @invalid_attrs %{count: nil, notes: nil, price_paid: nil} | ||||
|  | ||||
|     def ammo_group_fixture(attrs \\ %{}) do | ||||
|       {:ok, ammo_group} = | ||||
|         attrs | ||||
|         |> Enum.into(@valid_attrs) | ||||
|         |> Ammo.create_ammo_group() | ||||
|  | ||||
|       ammo_group | ||||
|     end | ||||
|  | ||||
|     test "list_ammo_groups/0 returns all ammo_groups" do | ||||
|       ammo_group = ammo_group_fixture() | ||||
|       assert Ammo.list_ammo_groups() == [ammo_group] | ||||
|     end | ||||
|  | ||||
|     test "get_ammo_group!/1 returns the ammo_group with given id" do | ||||
|       ammo_group = ammo_group_fixture() | ||||
|       assert Ammo.get_ammo_group!(ammo_group.id) == ammo_group | ||||
|     end | ||||
|  | ||||
|     test "create_ammo_group/1 with valid data creates a ammo_group" do | ||||
|       assert {:ok, %AmmoGroup{} = ammo_group} = Ammo.create_ammo_group(@valid_attrs) | ||||
|       assert ammo_group.count == 42 | ||||
|       assert ammo_group.notes == "some notes" | ||||
|       assert ammo_group.price_paid == 120.5 | ||||
|     end | ||||
|  | ||||
|     test "create_ammo_group/1 with invalid data returns error changeset" do | ||||
|       assert {:error, %Ecto.Changeset{}} = Ammo.create_ammo_group(@invalid_attrs) | ||||
|     end | ||||
|  | ||||
|     test "update_ammo_group/2 with valid data updates the ammo_group" do | ||||
|       ammo_group = ammo_group_fixture() | ||||
|       assert {:ok, %AmmoGroup{} = ammo_group} = Ammo.update_ammo_group(ammo_group, @update_attrs) | ||||
|       assert ammo_group.count == 43 | ||||
|       assert ammo_group.notes == "some updated notes" | ||||
|       assert ammo_group.price_paid == 456.7 | ||||
|     end | ||||
|  | ||||
|     test "update_ammo_group/2 with invalid data returns error changeset" do | ||||
|       ammo_group = ammo_group_fixture() | ||||
|       assert {:error, %Ecto.Changeset{}} = Ammo.update_ammo_group(ammo_group, @invalid_attrs) | ||||
|       assert ammo_group == Ammo.get_ammo_group!(ammo_group.id) | ||||
|     end | ||||
|  | ||||
|     test "delete_ammo_group/1 deletes the ammo_group" do | ||||
|       ammo_group = ammo_group_fixture() | ||||
|       assert {:ok, %AmmoGroup{}} = Ammo.delete_ammo_group(ammo_group) | ||||
|       assert_raise Ecto.NoResultsError, fn -> Ammo.get_ammo_group!(ammo_group.id) end | ||||
|     end | ||||
|  | ||||
|     test "change_ammo_group/1 returns a ammo_group changeset" do | ||||
|       ammo_group = ammo_group_fixture() | ||||
|       assert %Ecto.Changeset{} = Ammo.change_ammo_group(ammo_group) | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										70
									
								
								test/cannery/containers_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								test/cannery/containers_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,70 @@ | ||||
| defmodule Cannery.ContainersTest do | ||||
|   use Cannery.DataCase | ||||
|  | ||||
|   alias Cannery.Containers | ||||
|  | ||||
|   describe "containers" do | ||||
|     alias Cannery.Containers.Container | ||||
|  | ||||
|     @valid_attrs %{desc: "some desc", location: "some location", name: "some name", type: "some type"} | ||||
|     @update_attrs %{desc: "some updated desc", location: "some updated location", name: "some updated name", type: "some updated type"} | ||||
|     @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil} | ||||
|  | ||||
|     def container_fixture(attrs \\ %{}) do | ||||
|       {:ok, container} = | ||||
|         attrs | ||||
|         |> Enum.into(@valid_attrs) | ||||
|         |> Containers.create_container() | ||||
|  | ||||
|       container | ||||
|     end | ||||
|  | ||||
|     test "list_containers/0 returns all containers" do | ||||
|       container = container_fixture() | ||||
|       assert Containers.list_containers() == [container] | ||||
|     end | ||||
|  | ||||
|     test "get_container!/1 returns the container with given id" do | ||||
|       container = container_fixture() | ||||
|       assert Containers.get_container!(container.id) == container | ||||
|     end | ||||
|  | ||||
|     test "create_container/1 with valid data creates a container" do | ||||
|       assert {:ok, %Container{} = container} = Containers.create_container(@valid_attrs) | ||||
|       assert container.desc == "some desc" | ||||
|       assert container.location == "some location" | ||||
|       assert container.name == "some name" | ||||
|       assert container.type == "some type" | ||||
|     end | ||||
|  | ||||
|     test "create_container/1 with invalid data returns error changeset" do | ||||
|       assert {:error, %Ecto.Changeset{}} = Containers.create_container(@invalid_attrs) | ||||
|     end | ||||
|  | ||||
|     test "update_container/2 with valid data updates the container" do | ||||
|       container = container_fixture() | ||||
|       assert {:ok, %Container{} = container} = Containers.update_container(container, @update_attrs) | ||||
|       assert container.desc == "some updated desc" | ||||
|       assert container.location == "some updated location" | ||||
|       assert container.name == "some updated name" | ||||
|       assert container.type == "some updated type" | ||||
|     end | ||||
|  | ||||
|     test "update_container/2 with invalid data returns error changeset" do | ||||
|       container = container_fixture() | ||||
|       assert {:error, %Ecto.Changeset{}} = Containers.update_container(container, @invalid_attrs) | ||||
|       assert container == Containers.get_container!(container.id) | ||||
|     end | ||||
|  | ||||
|     test "delete_container/1 deletes the container" do | ||||
|       container = container_fixture() | ||||
|       assert {:ok, %Container{}} = Containers.delete_container(container) | ||||
|       assert_raise Ecto.NoResultsError, fn -> Containers.get_container!(container.id) end | ||||
|     end | ||||
|  | ||||
|     test "change_container/1 returns a container changeset" do | ||||
|       container = container_fixture() | ||||
|       assert %Ecto.Changeset{} = Containers.change_container(container) | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										68
									
								
								test/cannery/tags_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								test/cannery/tags_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| defmodule Cannery.TagsTest do | ||||
|   use Cannery.DataCase | ||||
|  | ||||
|   alias Cannery.Tags | ||||
|  | ||||
|   describe "tags" do | ||||
|     alias Cannery.Tags.Tag | ||||
|  | ||||
|     @valid_attrs %{"bg-color": "some bg-color", name: "some name", "text-color": "some text-color"} | ||||
|     @update_attrs %{"bg-color": "some updated bg-color", name: "some updated name", "text-color": "some updated text-color"} | ||||
|     @invalid_attrs %{"bg-color": nil, name: nil, "text-color": nil} | ||||
|  | ||||
|     def tag_fixture(attrs \\ %{}) do | ||||
|       {:ok, tag} = | ||||
|         attrs | ||||
|         |> Enum.into(@valid_attrs) | ||||
|         |> Tags.create_tag() | ||||
|  | ||||
|       tag | ||||
|     end | ||||
|  | ||||
|     test "list_tags/0 returns all tags" do | ||||
|       tag = tag_fixture() | ||||
|       assert Tags.list_tags() == [tag] | ||||
|     end | ||||
|  | ||||
|     test "get_tag!/1 returns the tag with given id" do | ||||
|       tag = tag_fixture() | ||||
|       assert Tags.get_tag!(tag.id) == tag | ||||
|     end | ||||
|  | ||||
|     test "create_tag/1 with valid data creates a tag" do | ||||
|       assert {:ok, %Tag{} = tag} = Tags.create_tag(@valid_attrs) | ||||
|       assert tag.bg-color == "some bg-color" | ||||
|       assert tag.name == "some name" | ||||
|       assert tag.text-color == "some text-color" | ||||
|     end | ||||
|  | ||||
|     test "create_tag/1 with invalid data returns error changeset" do | ||||
|       assert {:error, %Ecto.Changeset{}} = Tags.create_tag(@invalid_attrs) | ||||
|     end | ||||
|  | ||||
|     test "update_tag/2 with valid data updates the tag" do | ||||
|       tag = tag_fixture() | ||||
|       assert {:ok, %Tag{} = tag} = Tags.update_tag(tag, @update_attrs) | ||||
|       assert tag.bg-color == "some updated bg-color" | ||||
|       assert tag.name == "some updated name" | ||||
|       assert tag.text-color == "some updated text-color" | ||||
|     end | ||||
|  | ||||
|     test "update_tag/2 with invalid data returns error changeset" do | ||||
|       tag = tag_fixture() | ||||
|       assert {:error, %Ecto.Changeset{}} = Tags.update_tag(tag, @invalid_attrs) | ||||
|       assert tag == Tags.get_tag!(tag.id) | ||||
|     end | ||||
|  | ||||
|     test "delete_tag/1 deletes the tag" do | ||||
|       tag = tag_fixture() | ||||
|       assert {:ok, %Tag{}} = Tags.delete_tag(tag) | ||||
|       assert_raise Ecto.NoResultsError, fn -> Tags.get_tag!(tag.id) end | ||||
|     end | ||||
|  | ||||
|     test "change_tag/1 returns a tag changeset" do | ||||
|       tag = tag_fixture() | ||||
|       assert %Ecto.Changeset{} = Tags.change_tag(tag) | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										116
									
								
								test/cannery_web/live/ammo_group_live_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								test/cannery_web/live/ammo_group_live_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | ||||
| defmodule CanneryWeb.AmmoGroupLiveTest do | ||||
|   use CanneryWeb.ConnCase | ||||
|  | ||||
|   import Phoenix.LiveViewTest | ||||
|  | ||||
|   alias Cannery.Ammo | ||||
|  | ||||
|   @create_attrs %{count: 42, notes: "some notes", price_paid: 120.5} | ||||
|   @update_attrs %{count: 43, notes: "some updated notes", price_paid: 456.7} | ||||
|   @invalid_attrs %{count: nil, notes: nil, price_paid: nil} | ||||
|  | ||||
|   defp fixture(:ammo_group) do | ||||
|     {:ok, ammo_group} = Ammo.create_ammo_group(@create_attrs) | ||||
|     ammo_group | ||||
|   end | ||||
|  | ||||
|   defp create_ammo_group(_) do | ||||
|     ammo_group = fixture(:ammo_group) | ||||
|     %{ammo_group: ammo_group} | ||||
|   end | ||||
|  | ||||
|   describe "Index" do | ||||
|     setup [:create_ammo_group] | ||||
|  | ||||
|     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_group.notes | ||||
|     end | ||||
|  | ||||
|     test "saves new ammo_group", %{conn: conn} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("a", "New Ammo group") |> render_click() =~ | ||||
|                "New Ammo group" | ||||
|  | ||||
|       assert_patch(index_live, Routes.ammo_group_index_path(conn, :new)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#ammo_group-form", ammo_group: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#ammo_group-form", ammo_group: @create_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Ammo group created successfully" | ||||
|       assert html =~ "some notes" | ||||
|     end | ||||
|  | ||||
|     test "updates ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#ammo_group-#{ammo_group.id} a", "Edit") |> render_click() =~ | ||||
|                "Edit Ammo group" | ||||
|  | ||||
|       assert_patch(index_live, Routes.ammo_group_index_path(conn, :edit, ammo_group)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#ammo_group-form", ammo_group: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#ammo_group-form", ammo_group: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Ammo group updated successfully" | ||||
|       assert html =~ "some updated notes" | ||||
|     end | ||||
|  | ||||
|     test "deletes ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#ammo_group-#{ammo_group.id} a", "Delete") |> render_click() | ||||
|       refute has_element?(index_live, "#ammo_group-#{ammo_group.id}") | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   describe "Show" do | ||||
|     setup [:create_ammo_group] | ||||
|  | ||||
|     test "displays ammo_group", %{conn: conn, ammo_group: ammo_group} do | ||||
|       {:ok, _show_live, html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group)) | ||||
|  | ||||
|       assert html =~ "Show Ammo group" | ||||
|       assert html =~ ammo_group.notes | ||||
|     end | ||||
|  | ||||
|     test "updates ammo_group within modal", %{conn: conn, ammo_group: ammo_group} do | ||||
|       {:ok, show_live, _html} = live(conn, Routes.ammo_group_show_path(conn, :show, ammo_group)) | ||||
|  | ||||
|       assert show_live |> element("a", "Edit") |> render_click() =~ | ||||
|                "Edit Ammo group" | ||||
|  | ||||
|       assert_patch(show_live, Routes.ammo_group_show_path(conn, :edit, ammo_group)) | ||||
|  | ||||
|       assert show_live | ||||
|              |> form("#ammo_group-form", ammo_group: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         show_live | ||||
|         |> form("#ammo_group-form", ammo_group: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.ammo_group_show_path(conn, :show, ammo_group)) | ||||
|  | ||||
|       assert html =~ "Ammo group updated successfully" | ||||
|       assert html =~ "some updated notes" | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										116
									
								
								test/cannery_web/live/ammo_type_live_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								test/cannery_web/live/ammo_type_live_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | ||||
| defmodule CanneryWeb.AmmoTypeLiveTest do | ||||
|   use CanneryWeb.ConnCase | ||||
|  | ||||
|   import Phoenix.LiveViewTest | ||||
|  | ||||
|   alias Cannery.Ammo | ||||
|  | ||||
|   @create_attrs %{bullet_type: "some bullet_type", case_material: "some case_material", desc: "some desc", manufacturer: "some manufacturer", name: "some name", weight: 120.5} | ||||
|   @update_attrs %{bullet_type: "some updated bullet_type", case_material: "some updated case_material", desc: "some updated desc", manufacturer: "some updated manufacturer", name: "some updated name", weight: 456.7} | ||||
|   @invalid_attrs %{bullet_type: nil, case_material: nil, desc: nil, manufacturer: nil, name: nil, weight: nil} | ||||
|  | ||||
|   defp fixture(:ammo_type) do | ||||
|     {:ok, ammo_type} = Ammo.create_ammo_type(@create_attrs) | ||||
|     ammo_type | ||||
|   end | ||||
|  | ||||
|   defp create_ammo_type(_) do | ||||
|     ammo_type = fixture(:ammo_type) | ||||
|     %{ammo_type: ammo_type} | ||||
|   end | ||||
|  | ||||
|   describe "Index" do | ||||
|     setup [:create_ammo_type] | ||||
|  | ||||
|     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_type.bullet_type | ||||
|     end | ||||
|  | ||||
|     test "saves new ammo_type", %{conn: conn} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("a", "New Ammo type") |> render_click() =~ | ||||
|                "New Ammo type" | ||||
|  | ||||
|       assert_patch(index_live, Routes.ammo_type_index_path(conn, :new)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#ammo_type-form", ammo_type: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#ammo_type-form", ammo_type: @create_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Ammo type created successfully" | ||||
|       assert html =~ "some bullet_type" | ||||
|     end | ||||
|  | ||||
|     test "updates ammo_type in listing", %{conn: conn, ammo_type: ammo_type} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#ammo_type-#{ammo_type.id} a", "Edit") |> render_click() =~ | ||||
|                "Edit Ammo type" | ||||
|  | ||||
|       assert_patch(index_live, Routes.ammo_type_index_path(conn, :edit, ammo_type)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#ammo_type-form", ammo_type: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#ammo_type-form", ammo_type: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.ammo_type_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Ammo type updated successfully" | ||||
|       assert html =~ "some updated bullet_type" | ||||
|     end | ||||
|  | ||||
|     test "deletes ammo_type in listing", %{conn: conn, ammo_type: ammo_type} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.ammo_type_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#ammo_type-#{ammo_type.id} a", "Delete") |> render_click() | ||||
|       refute has_element?(index_live, "#ammo_type-#{ammo_type.id}") | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   describe "Show" do | ||||
|     setup [:create_ammo_type] | ||||
|  | ||||
|     test "displays ammo_type", %{conn: conn, ammo_type: ammo_type} do | ||||
|       {:ok, _show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type)) | ||||
|  | ||||
|       assert html =~ "Show Ammo type" | ||||
|       assert html =~ ammo_type.bullet_type | ||||
|     end | ||||
|  | ||||
|     test "updates ammo_type within modal", %{conn: conn, ammo_type: ammo_type} do | ||||
|       {:ok, show_live, _html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type)) | ||||
|  | ||||
|       assert show_live |> element("a", "Edit") |> render_click() =~ | ||||
|                "Edit Ammo type" | ||||
|  | ||||
|       assert_patch(show_live, Routes.ammo_type_show_path(conn, :edit, ammo_type)) | ||||
|  | ||||
|       assert show_live | ||||
|              |> form("#ammo_type-form", ammo_type: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         show_live | ||||
|         |> form("#ammo_type-form", ammo_type: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.ammo_type_show_path(conn, :show, ammo_type)) | ||||
|  | ||||
|       assert html =~ "Ammo type updated successfully" | ||||
|       assert html =~ "some updated bullet_type" | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										116
									
								
								test/cannery_web/live/container_live_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								test/cannery_web/live/container_live_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | ||||
| defmodule CanneryWeb.ContainerLiveTest do | ||||
|   use CanneryWeb.ConnCase | ||||
|  | ||||
|   import Phoenix.LiveViewTest | ||||
|  | ||||
|   alias Cannery.Containers | ||||
|  | ||||
|   @create_attrs %{desc: "some desc", location: "some location", name: "some name", type: "some type"} | ||||
|   @update_attrs %{desc: "some updated desc", location: "some updated location", name: "some updated name", type: "some updated type"} | ||||
|   @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil} | ||||
|  | ||||
|   defp fixture(:container) do | ||||
|     {:ok, container} = Containers.create_container(@create_attrs) | ||||
|     container | ||||
|   end | ||||
|  | ||||
|   defp create_container(_) do | ||||
|     container = fixture(:container) | ||||
|     %{container: container} | ||||
|   end | ||||
|  | ||||
|   describe "Index" do | ||||
|     setup [:create_container] | ||||
|  | ||||
|     test "lists all containers", %{conn: conn, container: container} do | ||||
|       {:ok, _index_live, html} = live(conn, Routes.container_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Listing Containers" | ||||
|       assert html =~ container.desc | ||||
|     end | ||||
|  | ||||
|     test "saves new container", %{conn: conn} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("a", "New Container") |> render_click() =~ | ||||
|                "New Container" | ||||
|  | ||||
|       assert_patch(index_live, Routes.container_index_path(conn, :new)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#container-form", container: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#container-form", container: @create_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.container_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Container created successfully" | ||||
|       assert html =~ "some desc" | ||||
|     end | ||||
|  | ||||
|     test "updates container in listing", %{conn: conn, container: container} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#container-#{container.id} a", "Edit") |> render_click() =~ | ||||
|                "Edit Container" | ||||
|  | ||||
|       assert_patch(index_live, Routes.container_index_path(conn, :edit, container)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#container-form", container: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#container-form", container: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.container_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Container updated successfully" | ||||
|       assert html =~ "some updated desc" | ||||
|     end | ||||
|  | ||||
|     test "deletes container in listing", %{conn: conn, container: container} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.container_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#container-#{container.id} a", "Delete") |> render_click() | ||||
|       refute has_element?(index_live, "#container-#{container.id}") | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   describe "Show" do | ||||
|     setup [:create_container] | ||||
|  | ||||
|     test "displays container", %{conn: conn, container: container} do | ||||
|       {:ok, _show_live, html} = live(conn, Routes.container_show_path(conn, :show, container)) | ||||
|  | ||||
|       assert html =~ "Show Container" | ||||
|       assert html =~ container.desc | ||||
|     end | ||||
|  | ||||
|     test "updates container within modal", %{conn: conn, container: container} do | ||||
|       {:ok, show_live, _html} = live(conn, Routes.container_show_path(conn, :show, container)) | ||||
|  | ||||
|       assert show_live |> element("a", "Edit") |> render_click() =~ | ||||
|                "Edit Container" | ||||
|  | ||||
|       assert_patch(show_live, Routes.container_show_path(conn, :edit, container)) | ||||
|  | ||||
|       assert show_live | ||||
|              |> form("#container-form", container: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         show_live | ||||
|         |> form("#container-form", container: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.container_show_path(conn, :show, container)) | ||||
|  | ||||
|       assert html =~ "Container updated successfully" | ||||
|       assert html =~ "some updated desc" | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										116
									
								
								test/cannery_web/live/tag_live_test.exs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								test/cannery_web/live/tag_live_test.exs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | ||||
| defmodule CanneryWeb.TagLiveTest do | ||||
|   use CanneryWeb.ConnCase | ||||
|  | ||||
|   import Phoenix.LiveViewTest | ||||
|  | ||||
|   alias Cannery.Tags | ||||
|  | ||||
|   @create_attrs %{"bg-color": "some bg-color", name: "some name", "text-color": "some text-color"} | ||||
|   @update_attrs %{"bg-color": "some updated bg-color", name: "some updated name", "text-color": "some updated text-color"} | ||||
|   @invalid_attrs %{"bg-color": nil, name: nil, "text-color": nil} | ||||
|  | ||||
|   defp fixture(:tag) do | ||||
|     {:ok, tag} = Tags.create_tag(@create_attrs) | ||||
|     tag | ||||
|   end | ||||
|  | ||||
|   defp create_tag(_) do | ||||
|     tag = fixture(:tag) | ||||
|     %{tag: tag} | ||||
|   end | ||||
|  | ||||
|   describe "Index" do | ||||
|     setup [:create_tag] | ||||
|  | ||||
|     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 =~ tag.bg-color | ||||
|     end | ||||
|  | ||||
|     test "saves new tag", %{conn: conn} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("a", "New Tag") |> render_click() =~ | ||||
|                "New Tag" | ||||
|  | ||||
|       assert_patch(index_live, Routes.tag_index_path(conn, :new)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#tag-form", tag: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#tag-form", tag: @create_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.tag_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Tag created successfully" | ||||
|       assert html =~ "some bg-color" | ||||
|     end | ||||
|  | ||||
|     test "updates tag in listing", %{conn: conn, tag: tag} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#tag-#{tag.id} a", "Edit") |> render_click() =~ | ||||
|                "Edit Tag" | ||||
|  | ||||
|       assert_patch(index_live, Routes.tag_index_path(conn, :edit, tag)) | ||||
|  | ||||
|       assert index_live | ||||
|              |> form("#tag-form", tag: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         index_live | ||||
|         |> form("#tag-form", tag: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.tag_index_path(conn, :index)) | ||||
|  | ||||
|       assert html =~ "Tag updated successfully" | ||||
|       assert html =~ "some updated bg-color" | ||||
|     end | ||||
|  | ||||
|     test "deletes tag in listing", %{conn: conn, tag: tag} do | ||||
|       {:ok, index_live, _html} = live(conn, Routes.tag_index_path(conn, :index)) | ||||
|  | ||||
|       assert index_live |> element("#tag-#{tag.id} a", "Delete") |> render_click() | ||||
|       refute has_element?(index_live, "#tag-#{tag.id}") | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   describe "Show" do | ||||
|     setup [:create_tag] | ||||
|  | ||||
|     test "displays tag", %{conn: conn, tag: tag} do | ||||
|       {:ok, _show_live, html} = live(conn, Routes.tag_show_path(conn, :show, tag)) | ||||
|  | ||||
|       assert html =~ "Show Tag" | ||||
|       assert html =~ tag.bg-color | ||||
|     end | ||||
|  | ||||
|     test "updates tag within modal", %{conn: conn, tag: tag} do | ||||
|       {:ok, show_live, _html} = live(conn, Routes.tag_show_path(conn, :show, tag)) | ||||
|  | ||||
|       assert show_live |> element("a", "Edit") |> render_click() =~ | ||||
|                "Edit Tag" | ||||
|  | ||||
|       assert_patch(show_live, Routes.tag_show_path(conn, :edit, tag)) | ||||
|  | ||||
|       assert show_live | ||||
|              |> form("#tag-form", tag: @invalid_attrs) | ||||
|              |> render_change() =~ "can't be blank" | ||||
|  | ||||
|       {:ok, _, html} = | ||||
|         show_live | ||||
|         |> form("#tag-form", tag: @update_attrs) | ||||
|         |> render_submit() | ||||
|         |> follow_redirect(conn, Routes.tag_show_path(conn, :show, tag)) | ||||
|  | ||||
|       assert html =~ "Tag updated successfully" | ||||
|       assert html =~ "some updated bg-color" | ||||
|     end | ||||
|   end | ||||
| end | ||||
		Reference in New Issue
	
	Block a user