2022-07-23 01:44:03 +02:00
|
|
|
defmodule ClaperWeb.EventLiveTest do
|
|
|
|
|
use ClaperWeb.ConnCase
|
|
|
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
2022-07-28 14:36:32 +02:00
|
|
|
import Claper.{PresentationsFixtures}
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
@update_attrs %{name: "some updated name"}
|
|
|
|
|
|
|
|
|
|
defp create_event(params) do
|
2022-07-28 14:36:32 +02:00
|
|
|
presentation_file = presentation_file_fixture(%{user: params.user}, [:event])
|
|
|
|
|
presentation_state_fixture(%{presentation_file: presentation_file})
|
|
|
|
|
params |> Map.put(:presentation_file, presentation_file)
|
2022-07-23 01:44:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "Index" do
|
2022-07-28 14:36:32 +02:00
|
|
|
setup [:register_and_log_in_user, :create_event]
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
test "lists all events", %{conn: conn, presentation_file: presentation_file} do
|
2022-07-23 01:44:03 +02:00
|
|
|
{:ok, _index_live, html} = live(conn, Routes.event_index_path(conn, :index))
|
|
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
assert html =~ "presentations"
|
|
|
|
|
assert html =~ presentation_file.event.name
|
2022-07-23 01:44:03 +02:00
|
|
|
end
|
|
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
test "updates event in listing", %{conn: conn, presentation_file: presentation_file} do
|
2022-07-23 01:44:03 +02:00
|
|
|
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
|
|
|
|
|
|
2022-11-17 13:37:34 +01:00
|
|
|
assert index_live
|
|
|
|
|
|> element("#event-#{presentation_file.event.uuid} a", "Edit")
|
|
|
|
|
|> render_click() =~
|
2022-07-28 14:36:32 +02:00
|
|
|
"Edit"
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
assert_patch(index_live, Routes.event_index_path(conn, :edit, presentation_file.event.uuid))
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
{:ok, _, html} =
|
|
|
|
|
index_live
|
2022-07-28 14:36:32 +02:00
|
|
|
|> form("#event-form", event: @update_attrs)
|
2022-07-23 01:44:03 +02:00
|
|
|
|> render_submit()
|
|
|
|
|
|> follow_redirect(conn, Routes.event_index_path(conn, :index))
|
|
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
assert html =~ "Updated successfully"
|
|
|
|
|
assert html =~ "some updated name"
|
2022-07-23 01:44:03 +02:00
|
|
|
end
|
|
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
test "deletes event in listing", %{conn: conn, presentation_file: presentation_file} do
|
2022-07-23 01:44:03 +02:00
|
|
|
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
|
|
|
|
|
|
2022-11-17 13:37:34 +01:00
|
|
|
assert index_live
|
|
|
|
|
|> element("#event-#{presentation_file.event.uuid} a", "Edit")
|
|
|
|
|
|> render_click() =~
|
2022-07-28 14:36:32 +02:00
|
|
|
"Edit"
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2022-11-17 13:37:34 +01:00
|
|
|
{:ok, conn} =
|
|
|
|
|
index_live
|
|
|
|
|
|> element(~s{a[phx-value-id=#{presentation_file.event.uuid}]})
|
|
|
|
|
|> render_click()
|
|
|
|
|
|> follow_redirect(conn, Routes.event_index_path(conn, :index))
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
|
|
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
refute has_element?(index_live, "#event-#{presentation_file.event.uuid}")
|
2022-07-23 01:44:03 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "Show" do
|
2022-07-28 14:36:32 +02:00
|
|
|
setup [:register_and_log_in_user, :create_event]
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
test "displays event", %{conn: conn, presentation_file: presentation_file} do
|
2022-11-17 13:37:34 +01:00
|
|
|
{:ok, _show_live, html} =
|
|
|
|
|
live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code))
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2022-07-28 14:36:32 +02:00
|
|
|
assert html =~ "Be the first to react"
|
|
|
|
|
assert html =~ presentation_file.event.name
|
2022-07-23 01:44:03 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|