Autogen Yield liveviews
This commit is contained in:
65
test/osuuspuutarha/harvest_test.exs
Normal file
65
test/osuuspuutarha/harvest_test.exs
Normal file
@@ -0,0 +1,65 @@
|
||||
defmodule Osuuspuutarha.HarvestTest do
|
||||
use Osuuspuutarha.DataCase
|
||||
|
||||
alias Osuuspuutarha.Harvest
|
||||
|
||||
describe "yields" do
|
||||
alias Osuuspuutarha.Harvest.Yield
|
||||
|
||||
import Osuuspuutarha.HarvestFixtures
|
||||
|
||||
@invalid_attrs %{amount: nil, date: nil, plant: nil, unit: nil}
|
||||
|
||||
test "list_yields/0 returns all yields" do
|
||||
yield = yield_fixture()
|
||||
assert Harvest.list_yields() == [yield]
|
||||
end
|
||||
|
||||
test "get_yield!/1 returns the yield with given id" do
|
||||
yield = yield_fixture()
|
||||
assert Harvest.get_yield!(yield.id) == yield
|
||||
end
|
||||
|
||||
test "create_yield/1 with valid data creates a yield" do
|
||||
valid_attrs = %{amount: "120.5", date: ~D[2023-06-07], plant: :salad, unit: :kg}
|
||||
|
||||
assert {:ok, %Yield{} = yield} = Harvest.create_yield(valid_attrs)
|
||||
assert yield.amount == Decimal.new("120.5")
|
||||
assert yield.date == ~D[2023-06-07]
|
||||
assert yield.plant == :salad
|
||||
assert yield.unit == :kg
|
||||
end
|
||||
|
||||
test "create_yield/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Harvest.create_yield(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_yield/2 with valid data updates the yield" do
|
||||
yield = yield_fixture()
|
||||
update_attrs = %{amount: "456.7", date: ~D[2023-06-08], plant: :carrot, unit: :kpl}
|
||||
|
||||
assert {:ok, %Yield{} = yield} = Harvest.update_yield(yield, update_attrs)
|
||||
assert yield.amount == Decimal.new("456.7")
|
||||
assert yield.date == ~D[2023-06-08]
|
||||
assert yield.plant == :carrot
|
||||
assert yield.unit == :kpl
|
||||
end
|
||||
|
||||
test "update_yield/2 with invalid data returns error changeset" do
|
||||
yield = yield_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Harvest.update_yield(yield, @invalid_attrs)
|
||||
assert yield == Harvest.get_yield!(yield.id)
|
||||
end
|
||||
|
||||
test "delete_yield/1 deletes the yield" do
|
||||
yield = yield_fixture()
|
||||
assert {:ok, %Yield{}} = Harvest.delete_yield(yield)
|
||||
assert_raise Ecto.NoResultsError, fn -> Harvest.get_yield!(yield.id) end
|
||||
end
|
||||
|
||||
test "change_yield/1 returns a yield changeset" do
|
||||
yield = yield_fixture()
|
||||
assert %Ecto.Changeset{} = Harvest.change_yield(yield)
|
||||
end
|
||||
end
|
||||
end
|
||||
105
test/osuuspuutarha_web/live/yield_live_test.exs
Normal file
105
test/osuuspuutarha_web/live/yield_live_test.exs
Normal file
@@ -0,0 +1,105 @@
|
||||
defmodule OsuuspuutarhaWeb.YieldLiveTest do
|
||||
use OsuuspuutarhaWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Osuuspuutarha.HarvestFixtures
|
||||
|
||||
@create_attrs %{amount: "120.5", date: %{day: 7, month: 6, year: 2023}, plant: :salad, unit: :kg}
|
||||
@update_attrs %{amount: "456.7", date: %{day: 8, month: 6, year: 2023}, plant: :carrot, unit: :kpl}
|
||||
@invalid_attrs %{amount: nil, date: %{day: 30, month: 2, year: 2023}, plant: nil, unit: nil}
|
||||
|
||||
defp create_yield(_) do
|
||||
yield = yield_fixture()
|
||||
%{yield: yield}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_yield]
|
||||
|
||||
test "lists all yields", %{conn: conn} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.yield_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Listing Yields"
|
||||
end
|
||||
|
||||
test "saves new yield", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.yield_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "New Yield") |> render_click() =~
|
||||
"New Yield"
|
||||
|
||||
assert_patch(index_live, Routes.yield_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#yield-form", yield: @invalid_attrs)
|
||||
|> render_change() =~ "is invalid"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#yield-form", yield: @create_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.yield_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Yield created successfully"
|
||||
end
|
||||
|
||||
test "updates yield in listing", %{conn: conn, yield: yield} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.yield_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#yield-#{yield.id} a", "Edit") |> render_click() =~
|
||||
"Edit Yield"
|
||||
|
||||
assert_patch(index_live, Routes.yield_index_path(conn, :edit, yield))
|
||||
|
||||
assert index_live
|
||||
|> form("#yield-form", yield: @invalid_attrs)
|
||||
|> render_change() =~ "is invalid"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#yield-form", yield: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.yield_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Yield updated successfully"
|
||||
end
|
||||
|
||||
test "deletes yield in listing", %{conn: conn, yield: yield} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.yield_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#yield-#{yield.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#yield-#{yield.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_yield]
|
||||
|
||||
test "displays yield", %{conn: conn, yield: yield} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.yield_show_path(conn, :show, yield))
|
||||
|
||||
assert html =~ "Show Yield"
|
||||
end
|
||||
|
||||
test "updates yield within modal", %{conn: conn, yield: yield} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.yield_show_path(conn, :show, yield))
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Yield"
|
||||
|
||||
assert_patch(show_live, Routes.yield_show_path(conn, :edit, yield))
|
||||
|
||||
assert show_live
|
||||
|> form("#yield-form", yield: @invalid_attrs)
|
||||
|> render_change() =~ "is invalid"
|
||||
|
||||
{:ok, _, html} =
|
||||
show_live
|
||||
|> form("#yield-form", yield: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.yield_show_path(conn, :show, yield))
|
||||
|
||||
assert html =~ "Yield updated successfully"
|
||||
end
|
||||
end
|
||||
end
|
||||
23
test/support/fixtures/harvest_fixtures.ex
Normal file
23
test/support/fixtures/harvest_fixtures.ex
Normal file
@@ -0,0 +1,23 @@
|
||||
defmodule Osuuspuutarha.HarvestFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Osuuspuutarha.Harvest` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a yield.
|
||||
"""
|
||||
def yield_fixture(attrs \\ %{}) do
|
||||
{:ok, yield} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
amount: "120.5",
|
||||
date: ~D[2023-06-07],
|
||||
plant: :salad,
|
||||
unit: :kg
|
||||
})
|
||||
|> Osuuspuutarha.Harvest.create_yield()
|
||||
|
||||
yield
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user