cannery/test/cannery_web/live/invite_live_test.exs

82 lines
2.4 KiB
Elixir
Raw Normal View History

2021-09-10 00:23:26 -04:00
defmodule CanneryWeb.InviteLiveTest do
2022-02-16 23:03:11 -05:00
@moduledoc """
Tests the invite liveview
"""
2021-09-10 00:23:26 -04:00
use CanneryWeb.ConnCase
import Phoenix.LiveViewTest
2023-02-04 16:46:37 -05:00
alias Cannery.Accounts.Invites
2021-09-10 00:23:26 -04:00
2022-02-16 23:03:11 -05:00
@moduletag :invite_live_test
2023-03-28 21:57:29 -04:00
@create_attrs %{name: "some name"}
@update_attrs %{name: "some updated name"}
@invalid_attrs %{name: nil}
2021-09-10 00:23:26 -04:00
describe "Index" do
2022-02-16 23:03:11 -05:00
setup [:register_and_log_in_user]
setup %{current_user: current_user} do
{:ok, invite} = Invites.create_invite(current_user, @create_attrs)
%{invite: invite, current_user: current_user}
end
2021-09-10 00:23:26 -04:00
test "lists all invites", %{conn: conn, invite: invite} do
2023-04-14 23:34:11 -04:00
{:ok, _index_live, html} = live(conn, ~p"/invites")
2021-09-10 00:23:26 -04:00
2023-03-28 21:57:29 -04:00
assert html =~ "Invites"
2021-09-10 00:23:26 -04:00
assert html =~ invite.name
end
test "saves new invite", %{conn: conn} do
2023-04-14 23:34:11 -04:00
{:ok, index_live, _html} = live(conn, ~p"/invites")
2021-09-10 00:23:26 -04:00
2023-03-28 21:57:29 -04:00
assert index_live |> element("a", "Create Invite") |> render_click() =~ "New Invite"
2023-04-14 23:34:11 -04:00
assert_patch(index_live, ~p"/invites/new")
2021-09-10 00:23:26 -04:00
2023-03-28 21:57:29 -04:00
assert index_live
|> form("#invite-form")
|> render_change(invite: @invalid_attrs) =~ "can't be blank"
2021-09-10 00:23:26 -04:00
2023-02-04 16:46:37 -05:00
{:ok, _live, html} =
2021-09-10 00:23:26 -04:00
index_live
2023-03-28 21:57:29 -04:00
|> form("#invite-form")
|> render_submit(invite: @create_attrs)
2023-04-14 23:34:11 -04:00
|> follow_redirect(conn, ~p"/invites")
2021-09-10 00:23:26 -04:00
2023-03-28 21:57:29 -04:00
assert html =~ "some name created successfully"
2021-09-10 00:23:26 -04:00
end
test "updates invite in listing", %{conn: conn, invite: invite} do
2023-04-14 23:34:11 -04:00
{:ok, index_live, _html} = live(conn, ~p"/invites")
2021-09-10 00:23:26 -04:00
2023-03-15 00:45:08 -04:00
assert index_live
|> element(~s/a[aria-label="Edit invite for #{invite.name}"]/)
2023-03-28 21:57:29 -04:00
|> render_click() =~ "Edit Invite"
2021-09-10 00:23:26 -04:00
2023-04-14 23:34:11 -04:00
assert_patch(index_live, ~p"/invites/#{invite}/edit")
2021-09-10 00:23:26 -04:00
2023-03-28 21:57:29 -04:00
assert index_live
|> form("#invite-form")
|> render_change(invite: @invalid_attrs) =~ "can't be blank"
2021-09-10 00:23:26 -04:00
2023-02-04 16:46:37 -05:00
{:ok, _live, html} =
2021-09-10 00:23:26 -04:00
index_live
2023-03-28 21:57:29 -04:00
|> form("#invite-form")
|> render_submit(invite: @update_attrs)
2023-04-14 23:34:11 -04:00
|> follow_redirect(conn, ~p"/invites")
2021-09-10 00:23:26 -04:00
2023-03-28 21:57:29 -04:00
assert html =~ "some updated name updated successfully"
2021-09-10 00:23:26 -04:00
end
test "deletes invite in listing", %{conn: conn, invite: invite} do
2023-04-14 23:34:11 -04:00
{:ok, index_live, _html} = live(conn, ~p"/invites")
2021-09-10 00:23:26 -04:00
2023-03-15 00:45:08 -04:00
assert index_live
|> element(~s/a[aria-label="Delete invite for #{invite.name}"]/)
|> render_click()
2021-09-10 00:23:26 -04:00
refute has_element?(index_live, "#invite-#{invite.id}")
end
end
end