Add Authors
mix phx.gen.live Authors Author authors name:string description:text homepage_name:string homepage_url:string
This commit is contained in:
65
test/outlook/authors_test.exs
Normal file
65
test/outlook/authors_test.exs
Normal file
@ -0,0 +1,65 @@
|
||||
defmodule Outlook.AuthorsTest do
|
||||
use Outlook.DataCase
|
||||
|
||||
alias Outlook.Authors
|
||||
|
||||
describe "authors" do
|
||||
alias Outlook.Authors.Author
|
||||
|
||||
import Outlook.AuthorsFixtures
|
||||
|
||||
@invalid_attrs %{description: nil, homepage_name: nil, homepage_url: nil, name: nil}
|
||||
|
||||
test "list_authors/0 returns all authors" do
|
||||
author = author_fixture()
|
||||
assert Authors.list_authors() == [author]
|
||||
end
|
||||
|
||||
test "get_author!/1 returns the author with given id" do
|
||||
author = author_fixture()
|
||||
assert Authors.get_author!(author.id) == author
|
||||
end
|
||||
|
||||
test "create_author/1 with valid data creates a author" do
|
||||
valid_attrs = %{description: "some description", homepage_name: "some homepage_name", homepage_url: "some homepage_url", name: "some name"}
|
||||
|
||||
assert {:ok, %Author{} = author} = Authors.create_author(valid_attrs)
|
||||
assert author.description == "some description"
|
||||
assert author.homepage_name == "some homepage_name"
|
||||
assert author.homepage_url == "some homepage_url"
|
||||
assert author.name == "some name"
|
||||
end
|
||||
|
||||
test "create_author/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Authors.create_author(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_author/2 with valid data updates the author" do
|
||||
author = author_fixture()
|
||||
update_attrs = %{description: "some updated description", homepage_name: "some updated homepage_name", homepage_url: "some updated homepage_url", name: "some updated name"}
|
||||
|
||||
assert {:ok, %Author{} = author} = Authors.update_author(author, update_attrs)
|
||||
assert author.description == "some updated description"
|
||||
assert author.homepage_name == "some updated homepage_name"
|
||||
assert author.homepage_url == "some updated homepage_url"
|
||||
assert author.name == "some updated name"
|
||||
end
|
||||
|
||||
test "update_author/2 with invalid data returns error changeset" do
|
||||
author = author_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Authors.update_author(author, @invalid_attrs)
|
||||
assert author == Authors.get_author!(author.id)
|
||||
end
|
||||
|
||||
test "delete_author/1 deletes the author" do
|
||||
author = author_fixture()
|
||||
assert {:ok, %Author{}} = Authors.delete_author(author)
|
||||
assert_raise Ecto.NoResultsError, fn -> Authors.get_author!(author.id) end
|
||||
end
|
||||
|
||||
test "change_author/1 returns a author changeset" do
|
||||
author = author_fixture()
|
||||
assert %Ecto.Changeset{} = Authors.change_author(author)
|
||||
end
|
||||
end
|
||||
end
|
||||
110
test/outlook_web/live/author_live_test.exs
Normal file
110
test/outlook_web/live/author_live_test.exs
Normal file
@ -0,0 +1,110 @@
|
||||
defmodule OutlookWeb.AuthorLiveTest do
|
||||
use OutlookWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Outlook.AuthorsFixtures
|
||||
|
||||
@create_attrs %{description: "some description", homepage_name: "some homepage_name", homepage_url: "some homepage_url", name: "some name"}
|
||||
@update_attrs %{description: "some updated description", homepage_name: "some updated homepage_name", homepage_url: "some updated homepage_url", name: "some updated name"}
|
||||
@invalid_attrs %{description: nil, homepage_name: nil, homepage_url: nil, name: nil}
|
||||
|
||||
defp create_author(_) do
|
||||
author = author_fixture()
|
||||
%{author: author}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_author]
|
||||
|
||||
test "lists all authors", %{conn: conn, author: author} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/authors")
|
||||
|
||||
assert html =~ "Listing Authors"
|
||||
assert html =~ author.description
|
||||
end
|
||||
|
||||
test "saves new author", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/authors")
|
||||
|
||||
assert index_live |> element("a", "New Author") |> render_click() =~
|
||||
"New Author"
|
||||
|
||||
assert_patch(index_live, ~p"/authors/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#author-form", author: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#author-form", author: @create_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/authors")
|
||||
|
||||
assert html =~ "Author created successfully"
|
||||
assert html =~ "some description"
|
||||
end
|
||||
|
||||
test "updates author in listing", %{conn: conn, author: author} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/authors")
|
||||
|
||||
assert index_live |> element("#authors-#{author.id} a", "Edit") |> render_click() =~
|
||||
"Edit Author"
|
||||
|
||||
assert_patch(index_live, ~p"/authors/#{author}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#author-form", author: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#author-form", author: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/authors")
|
||||
|
||||
assert html =~ "Author updated successfully"
|
||||
assert html =~ "some updated description"
|
||||
end
|
||||
|
||||
test "deletes author in listing", %{conn: conn, author: author} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/authors")
|
||||
|
||||
assert index_live |> element("#authors-#{author.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#author-#{author.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_author]
|
||||
|
||||
test "displays author", %{conn: conn, author: author} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/authors/#{author}")
|
||||
|
||||
assert html =~ "Show Author"
|
||||
assert html =~ author.description
|
||||
end
|
||||
|
||||
test "updates author within modal", %{conn: conn, author: author} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/authors/#{author}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Author"
|
||||
|
||||
assert_patch(show_live, ~p"/authors/#{author}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#author-form", author: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
show_live
|
||||
|> form("#author-form", author: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/authors/#{author}")
|
||||
|
||||
assert html =~ "Author updated successfully"
|
||||
assert html =~ "some updated description"
|
||||
end
|
||||
end
|
||||
end
|
||||
23
test/support/fixtures/authors_fixtures.ex
Normal file
23
test/support/fixtures/authors_fixtures.ex
Normal file
@ -0,0 +1,23 @@
|
||||
defmodule Outlook.AuthorsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Outlook.Authors` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a author.
|
||||
"""
|
||||
def author_fixture(attrs \\ %{}) do
|
||||
{:ok, author} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
description: "some description",
|
||||
homepage_name: "some homepage_name",
|
||||
homepage_url: "some homepage_url",
|
||||
name: "some name"
|
||||
})
|
||||
|> Outlook.Authors.create_author()
|
||||
|
||||
author
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user