cannery/test/cannery_web/live/invite_live_test.exs

94 lines
3.0 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
2022-02-08 23:58:54 -05:00
import CanneryWeb.Gettext
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
@create_attrs %{"name" => "some name"}
@update_attrs %{"name" => "some updated name"}
2022-02-17 20:01:14 -05:00
# @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
{:ok, _index_live, html} = live(conn, Routes.invite_index_path(conn, :index))
2022-02-16 23:03:11 -05:00
assert html =~ gettext("Invites")
2021-09-10 00:23:26 -04: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))
2022-02-16 23:03:11 -05:00
assert index_live |> element("a", dgettext("actions", "Create Invite")) |> render_click() =~
gettext("New Invite")
2021-09-10 00:23:26 -04:00
assert_patch(index_live, Routes.invite_index_path(conn, :new))
2022-02-16 23:03:11 -05:00
# assert index_live
# |> form("#invite-form", invite: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "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
|> form("#invite-form", invite: @create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
2023-02-04 16:46:37 -05:00
assert html =~
dgettext("prompts", "%{invite_name} created successfully", invite_name: "some name")
2022-02-16 23:03:11 -05:00
2021-09-10 00:23:26 -04:00
assert html =~ "some name"
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-15 00:45:08 -04:00
assert index_live
|> element(~s/a[aria-label="Edit invite for #{invite.name}"]/)
|> render_click() =~
2022-02-16 23:03:11 -05:00
gettext("Edit Invite")
2021-09-10 00:23:26 -04:00
assert_patch(index_live, Routes.invite_index_path(conn, :edit, invite))
2022-02-16 23:03:11 -05:00
# assert index_live
# |> form("#invite-form", invite: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "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
|> form("#invite-form", invite: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.invite_index_path(conn, :index))
2022-02-16 23:03:11 -05:00
assert html =~
2023-02-04 16:46:37 -05:00
dgettext("prompts", "%{invite_name} updated successfully",
invite_name: "some updated name"
)
2022-02-16 23:03:11 -05:00
2021-09-10 00:23:26 -04:00
assert html =~ "some updated name"
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-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