add models, context and liveviews

This commit is contained in:
2021-09-02 23:31:14 -04:00
committed by oliviasculley
parent feba4e1d14
commit d6ddf2a9bb
52 changed files with 2325 additions and 13 deletions

View 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

View 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

View 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

View 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