livebook/test/live_book_web/live/sessions_live_test.exs
Jonatan Kłosko 5cdcb15e3d
Add module for managing multiple running sessions (#3)
* Add dynamic supervisor for session processes

* Add basic UI listing current sessions

* Handle review comments

* Make tests not dependent on restarting SessionSupervisor
2021-01-08 14:14:26 +01:00

42 lines
1.2 KiB
Elixir

defmodule LiveBookWeb.SessionsLiveTest do
use LiveBookWeb.ConnCase
import Phoenix.LiveViewTest
test "disconnected and connected render", %{conn: conn} do
{:ok, view, disconnected_html} = live(conn, "/sessions")
assert disconnected_html =~ "Sessions"
assert render(view) =~ "Sessions"
end
test "lists running sessions", %{conn: conn} do
{:ok, id1} = LiveBook.SessionSupervisor.create_session()
{:ok, id2} = LiveBook.SessionSupervisor.create_session()
{:ok, view, _} = live(conn, "/sessions")
assert render(view) =~ id1
assert render(view) =~ id2
end
test "redirects to session upon creation", %{conn: conn} do
{:ok, view, _} = live(conn, "/sessions")
assert {:error, {:live_redirect, %{to: to}}} =
view
|> element("button", "New session")
|> render_click()
assert to =~ "/sessions/"
end
test "updates UI whenever a session is added or deleted", %{conn: conn} do
{:ok, view, _} = live(conn, "/sessions")
{:ok, id} = LiveBook.SessionSupervisor.create_session()
assert render(view) =~ id
LiveBook.SessionSupervisor.delete_session(id)
refute render(view) =~ id
end
end