Files
Claper/test/claper_web/live/event_live_test.exs

80 lines
2.6 KiB
Elixir
Raw Normal View History

defmodule ClaperWeb.EventLiveTest do
use ClaperWeb.ConnCase
import Phoenix.LiveViewTest
2022-07-28 14:36:32 +02:00
import Claper.{PresentationsFixtures}
@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)
end
describe "Index" do
2022-07-28 14:36:32 +02:00
setup [:register_and_log_in_user, :create_event]
2022-07-28 14:36:32 +02:00
test "lists all events", %{conn: conn, presentation_file: presentation_file} do
2024-04-06 11:48:47 +02:00
{:ok, _index_live, html} = live(conn, ~p"/events")
2024-04-06 11:48:47 +02:00
assert html =~ "events"
2022-07-28 14:36:32 +02:00
assert html =~ presentation_file.event.name
end
2022-07-28 14:36:32 +02:00
test "updates event in listing", %{conn: conn, presentation_file: presentation_file} do
2024-07-11 16:33:02 +02:00
{:ok, index_live, _html} = live(conn, ~p"/events/#{presentation_file.event.uuid}/edit")
2024-04-07 12:47:03 +02:00
{:ok, conn} =
index_live
2022-07-28 14:36:32 +02:00
|> form("#event-form", event: @update_attrs)
|> render_submit()
2024-04-06 11:48:47 +02:00
|> follow_redirect(conn, ~p"/events")
2024-04-07 12:47:03 +02:00
assert html_response(conn, 200) =~ "Updated successfully"
assert html_response(conn, 200) =~ "some updated name"
end
2022-07-28 14:36:32 +02:00
test "deletes event in listing", %{conn: conn, presentation_file: presentation_file} do
2024-07-11 16:33:02 +02:00
{:ok, index_live, _html} = live(conn, ~p"/events/#{presentation_file.event.uuid}/edit")
2022-11-17 13:37:34 +01:00
{:ok, conn} =
index_live
|> element(~s{a[phx-click="delete"][phx-value-id=#{presentation_file.event.uuid}]})
2022-11-17 13:37:34 +01:00
|> render_click()
2024-04-06 11:48:47 +02:00
|> follow_redirect(conn, ~p"/events")
2024-04-06 11:48:47 +02:00
{:ok, index_live, _html} = live(conn, ~p"/events")
2022-07-28 14:36:32 +02:00
refute has_element?(index_live, "#event-#{presentation_file.event.uuid}")
end
end
describe "Show" do
2022-07-28 14:36:32 +02:00
setup [:register_and_log_in_user, :create_event]
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} =
2024-04-06 11:48:47 +02:00
live(conn, ~p"/e/#{presentation_file.event.code}")
2024-04-06 11:48:47 +02:00
assert html =~ "Be the first to react !"
2022-07-28 14:36:32 +02:00
assert html =~ presentation_file.event.name
end
end
describe "Join" do
test "renders the join page", %{conn: conn} do
{:ok, join_live, html} = live(conn, ~p"/")
assert html =~ "Join the event"
assert html =~ "Event code"
assert html =~ "Are you a presenter?"
assert html =~ "Start creating for free"
refute html =~ "Turn your slides into conversations"
assert has_element?(join_live, "#form")
assert has_element?(join_live, "#input[placeholder='ABCD1234']")
end
end
end