get started on route for creating links, dividing steps into components

This commit is contained in:
2021-08-19 22:35:12 -04:00
parent 1542213875
commit dfaa328af4
24 changed files with 618 additions and 36 deletions

View File

@@ -0,0 +1,66 @@
defmodule Entendu.LinksTest do
use Entendu.DataCase
alias Entendu.Links
describe "links" do
alias Entendu.Links.Link
@valid_attrs %{burn_after_reading: true, expires: "2010-04-17T14:00:00Z"}
@update_attrs %{burn_after_reading: false, expires: "2011-05-18T15:01:01Z"}
@invalid_attrs %{burn_after_reading: nil, expires: nil}
def link_fixture(attrs \\ %{}) do
{:ok, link} =
attrs
|> Enum.into(@valid_attrs)
|> Links.create_link()
link
end
test "list_links/0 returns all links" do
link = link_fixture()
assert Links.list_links() == [link]
end
test "get_link!/1 returns the link with given id" do
link = link_fixture()
assert Links.get_link!(link.id) == link
end
test "create_link/1 with valid data creates a link" do
assert {:ok, %Link{} = link} = Links.create_link(@valid_attrs)
assert link.burn_after_reading == true
assert link.expires == DateTime.from_naive!(~N[2010-04-17T14:00:00Z], "Etc/UTC")
end
test "create_link/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Links.create_link(@invalid_attrs)
end
test "update_link/2 with valid data updates the link" do
link = link_fixture()
assert {:ok, %Link{} = link} = Links.update_link(link, @update_attrs)
assert link.burn_after_reading == false
assert link.expires == DateTime.from_naive!(~N[2011-05-18T15:01:01Z], "Etc/UTC")
end
test "update_link/2 with invalid data returns error changeset" do
link = link_fixture()
assert {:error, %Ecto.Changeset{}} = Links.update_link(link, @invalid_attrs)
assert link == Links.get_link!(link.id)
end
test "delete_link/1 deletes the link" do
link = link_fixture()
assert {:ok, %Link{}} = Links.delete_link(link)
assert_raise Ecto.NoResultsError, fn -> Links.get_link!(link.id) end
end
test "change_link/1 returns a link changeset" do
link = link_fixture()
assert %Ecto.Changeset{} = Links.change_link(link)
end
end
end

View File

@@ -0,0 +1,111 @@
defmodule EntenduWeb.LinkLiveTest do
use EntenduWeb.ConnCase
import Phoenix.LiveViewTest
alias Entendu.Links
@create_attrs %{burn_after_reading: true, expires: "2010-04-17T14:00:00Z"}
@update_attrs %{burn_after_reading: false, expires: "2011-05-18T15:01:01Z"}
@invalid_attrs %{burn_after_reading: nil, expires: nil}
defp fixture(:link) do
{:ok, link} = Links.create_link(@create_attrs)
link
end
defp create_link(_) do
link = fixture(:link)
%{link: link}
end
describe "Index" do
setup [:create_link]
test "lists all links", %{conn: conn, link: link} do
{:ok, _index_live, html} = live(conn, Routes.link_index_path(conn, :index))
assert html =~ "Listing Links"
end
test "saves new link", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.link_index_path(conn, :index))
assert index_live |> element("a", "New Link") |> render_click() =~
"New Link"
assert_patch(index_live, Routes.link_index_path(conn, :new))
assert index_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#link-form", link: @create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.link_index_path(conn, :index))
assert html =~ "Link created successfully"
end
test "updates link in listing", %{conn: conn, link: link} do
{:ok, index_live, _html} = live(conn, Routes.link_index_path(conn, :index))
assert index_live |> element("#link-#{link.id} a", "Edit") |> render_click() =~
"Edit Link"
assert_patch(index_live, Routes.link_index_path(conn, :edit, link))
assert index_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#link-form", link: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.link_index_path(conn, :index))
assert html =~ "Link updated successfully"
end
test "deletes link in listing", %{conn: conn, link: link} do
{:ok, index_live, _html} = live(conn, Routes.link_index_path(conn, :index))
assert index_live |> element("#link-#{link.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#link-#{link.id}")
end
end
describe "Show" do
setup [:create_link]
test "displays link", %{conn: conn, link: link} do
{:ok, _show_live, html} = live(conn, Routes.link_show_path(conn, :show, link))
assert html =~ "Show Link"
end
test "updates link within modal", %{conn: conn, link: link} do
{:ok, show_live, _html} = live(conn, Routes.link_show_path(conn, :show, link))
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Link"
assert_patch(show_live, Routes.link_show_path(conn, :edit, link))
assert show_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
show_live
|> form("#link-form", link: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.link_show_path(conn, :show, link))
assert html =~ "Link updated successfully"
end
end
end