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
|
|
|
|
"""
|
|
|
|
|
2022-07-25 19:31:54 -04:00
|
|
|
use MemexWeb.ConnCase
|
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
|
|
|
|
{:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index))
|
|
|
|
|
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
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
|
2023-03-22 22:08:37 -04:00
|
|
|
assert index_live |> element("a", "create invite") |> render_click() =~ "new invite"
|
2022-02-25 21:53:15 -05:00
|
|
|
assert_patch(index_live, Routes.invite_index_path(conn, :new))
|
|
|
|
|
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)
|
2022-02-25 21:53:15 -05:00
|
|
|
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
|
|
|
|
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
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
|
|
|
|
|
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
|
|
|
|
|
|
|
assert_patch(index_live, Routes.invite_index_path(conn, :edit, invite))
|
|
|
|
|
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)
|
2022-02-25 21:53:15 -05:00
|
|
|
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
|
|
|
|
|
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
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.invite_index_path(conn, :index))
|
|
|
|
|
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
|