memEx/test/memex_web/live/invite_live_test.exs

80 lines
2.4 KiB
Elixir
Raw Permalink Normal View History

2022-07-25 19:31:54 -04:00
defmodule MemexWeb.InviteLiveTest do
2022-02-25 21:53:15 -05:00
@moduledoc """
Tests the invite liveview
"""
2023-04-14 23:50:16 -04:00
use MemexWeb.ConnCase, async: true
2022-02-25 21:53:15 -05:00
import Phoenix.LiveViewTest
2023-02-04 17:22:06 -05:00
alias Memex.Accounts.Invites
2022-02-25 21:53:15 -05:00
@moduletag :invite_live_test
2023-03-22 22:08:37 -04:00
@create_attrs %{name: "some name"}
@update_attrs %{name: "some updated name"}
2023-03-28 22:03:00 -04:00
@invalid_attrs %{name: nil}
2022-02-25 21:53:15 -05:00
describe "Index" do
setup [:register_and_log_in_user]
2023-02-04 17:22:06 -05:00
setup %{current_user: current_user} do
{:ok, invite} = Invites.create_invite(current_user, @create_attrs)
%{invite: invite, current_user: current_user}
2022-02-25 21:53:15 -05:00
end
test "lists all invites", %{conn: conn, invite: invite} do
2023-04-13 23:29:29 -04:00
{:ok, _index_live, html} = live(conn, ~p"/invites")
2023-03-22 22:08:37 -04:00
assert html =~ "invites"
2022-02-25 21:53:15 -05:00
assert html =~ invite.name
end
test "saves new invite", %{conn: conn} do
2023-04-13 23:29:29 -04:00
{:ok, index_live, _html} = live(conn, ~p"/invites")
2023-03-22 22:08:37 -04:00
assert index_live |> element("a", "create invite") |> render_click() =~ "new invite"
2023-04-13 23:29:29 -04:00
assert_patch(index_live, ~p"/invites/new")
2022-02-25 21:53:15 -05:00
2023-03-28 22:03:00 -04:00
assert index_live
|> form("#invite-form")
|> render_change(invite: @invalid_attrs) =~ "can't be blank"
2022-02-25 21:53:15 -05:00
2023-02-04 17:36:27 -05:00
{:ok, _live, html} =
2022-02-25 21:53:15 -05:00
index_live
2023-03-22 22:08:37 -04:00
|> form("#invite-form")
|> render_submit(invite: @create_attrs)
2023-04-13 23:29:29 -04:00
|> follow_redirect(conn, ~p"/invites")
2022-02-25 21:53:15 -05:00
2023-03-22 22:08:37 -04:00
assert html =~ "some name created successfully"
2022-02-25 21:53:15 -05:00
end
test "updates invite in listing", %{conn: conn, invite: invite} do
2023-04-13 23:29:29 -04:00
{:ok, index_live, _html} = live(conn, ~p"/invites")
2022-02-25 21:53:15 -05:00
2023-03-14 23:51:50 -04:00
assert index_live
|> element(~s/a[aria-label="edit invite for #{invite.name}"]/)
2023-03-22 22:08:37 -04:00
|> render_click() =~ "edit invite"
2022-02-25 21:53:15 -05:00
2023-04-16 00:48:04 -04:00
assert_patch(index_live, ~p"/invites/edit/#{invite}")
2022-02-25 21:53:15 -05:00
2023-03-28 22:03:00 -04:00
assert index_live
|> form("#invite-form")
|> render_change(invite: @invalid_attrs) =~ "can't be blank"
2022-02-25 21:53:15 -05:00
2023-02-04 17:36:27 -05:00
{:ok, _live, html} =
2022-02-25 21:53:15 -05:00
index_live
2023-03-22 22:08:37 -04:00
|> form("#invite-form")
|> render_submit(invite: @update_attrs)
2023-04-13 23:29:29 -04:00
|> follow_redirect(conn, ~p"/invites")
2022-02-25 21:53:15 -05:00
2023-03-22 22:08:37 -04:00
assert html =~ "some updated name updated successfully"
2022-02-25 21:53:15 -05:00
end
test "deletes invite in listing", %{conn: conn, invite: invite} do
2023-04-13 23:29:29 -04:00
{:ok, index_live, _html} = live(conn, ~p"/invites")
2022-02-25 21:53:15 -05:00
2023-03-14 23:51:50 -04:00
assert index_live
|> element(~s/a[aria-label="delete invite for #{invite.name}"]/)
|> render_click()
2022-02-25 21:53:15 -05:00
refute has_element?(index_live, "#invite-#{invite.id}")
end
end
end