Compare commits

...

2 Commits

Author SHA1 Message Date
KKlochko 00467d249a Add tests for Links' LiveViews.
continuous-integration/drone/push Build is passing Details
8 months ago
KKlochko 15d12bd937 Update the show LiveView template for Links.
8 months ago

@ -1,6 +1,6 @@
<.header>
Link <%= @link.id %>
<:subtitle>This is a link record from your database.</:subtitle>
<:subtitle>This is a link record.</:subtitle>
<:actions>
<.link patch={~p"/links/#{@link}/show/edit"} phx-click={JS.push_focus()}>
<.button>Edit link</.button>
@ -9,6 +9,9 @@
</.header>
<.list>
<:item title="Name"><%= @link.name %></:item>
<:item title="Url"><%= @link.url %></:item>
<:item title="Shorten"><%= @link.shorten %></:item>
</.list>
<.back navigate={~p"/links"}>Back to links</.back>
@ -20,6 +23,7 @@
title={@page_title}
action={@live_action}
link={@link}
current_user={@current_user}
patch={~p"/links/#{@link}"}
/>
</.modal>

@ -0,0 +1,115 @@
defmodule LinkShortenerWeb.LinkLiveTest do
use LinkShortenerWeb.ConnCase
import Phoenix.LiveViewTest
import LinkShortener.LinksFixtures
import LinkShortener.AccountsFixtures
alias LinkShortener.Factories.LinkFactory
@create_attrs %{name: "some name", shorten: "some shorten", url: "some url"}
@update_attrs %{name: "some updated name", shorten: "some updated shorten", url: "some updated url"}
@invalid_attrs %{name: nil, shorten: nil, url: nil}
setup %{conn: conn} do
user = user_fixture()
link = LinkFactory.create_link(%{user_id: user.id})
%{conn: log_in_user(conn, user),
link: link}
end
describe "Index" do
test "lists all links", %{conn: conn, link: link} do
{:ok, _index_live, html} = live(conn, ~p"/links")
assert html =~ "Listing Links"
assert html =~ link.name
end
test "saves new link", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/links")
assert index_live |> element("a", "New Link") |> render_click() =~
"New Link"
assert_patch(index_live, ~p"/links/new")
assert index_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
assert index_live
|> form("#link-form", link: @create_attrs)
|> render_submit()
assert_patch(index_live, ~p"/links")
html = render(index_live)
assert html =~ "Link created successfully"
assert html =~ "some name"
end
test "updates link in listing", %{conn: conn, link: link} do
{:ok, index_live, _html} = live(conn, ~p"/links")
assert index_live |> element("#links-#{link.id} a", "Edit") |> render_click() =~
"Edit Link"
assert_patch(index_live, ~p"/links/#{link}/edit")
assert index_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
assert index_live
|> form("#link-form", link: @update_attrs)
|> render_submit()
assert_patch(index_live, ~p"/links")
html = render(index_live)
assert html =~ "Link updated successfully"
assert html =~ "some updated name"
end
test "deletes link in listing", %{conn: conn, link: link} do
{:ok, index_live, _html} = live(conn, ~p"/links")
assert index_live |> element("#links-#{link.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#links-#{link.id}")
end
end
describe "Show" do
test "displays link", %{conn: conn, link: link} do
{:ok, _show_live, html} = live(conn, ~p"/links/#{link}")
assert html =~ "Show Link"
assert html =~ link.name
end
test "updates link within modal", %{conn: conn, link: link} do
{:ok, show_live, _html} = live(conn, ~p"/links/#{link}")
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Link"
assert_patch(show_live, ~p"/links/#{link}/show/edit")
assert show_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
assert show_live
|> form("#link-form", link: @update_attrs)
|> render_submit()
assert_patch(show_live, ~p"/links/#{link}")
html = render(show_live)
assert html =~ "Link updated successfully"
assert html =~ "some updated name"
end
end
end
Loading…
Cancel
Save