2022-09-21 18:06:22 +08:00
|
|
|
defmodule LivebookWeb.LearnLiveTest do
|
2022-01-29 23:39:41 +08:00
|
|
|
use LivebookWeb.ConnCase, async: true
|
2021-06-03 03:51:43 +08:00
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
|
|
|
|
test "link to introductory notebook correctly creates a new session", %{conn: conn} do
|
2022-09-21 18:06:22 +08:00
|
|
|
{:ok, view, _} = live(conn, "/learn")
|
2021-06-03 03:51:43 +08:00
|
|
|
|
|
|
|
assert {:error, {:live_redirect, %{to: to}}} =
|
|
|
|
view
|
2022-08-29 01:08:43 +08:00
|
|
|
|> element(~s{#welcome-to-livebook a}, "Open notebook")
|
2021-06-03 03:51:43 +08:00
|
|
|
|> render_click()
|
|
|
|
|
|
|
|
assert to =~ "/sessions/"
|
|
|
|
|
|
|
|
{:ok, view, _} = live(conn, to)
|
|
|
|
assert render(view) =~ "Welcome to Livebook"
|
2023-01-05 23:12:45 +08:00
|
|
|
|
|
|
|
close_session_by_path(to)
|
2021-06-03 03:51:43 +08:00
|
|
|
end
|
2021-06-15 03:25:18 +08:00
|
|
|
|
|
|
|
test "link to a new notebook creates an empty session", %{conn: conn} do
|
2023-01-05 23:12:45 +08:00
|
|
|
assert {:error, {:live_redirect, %{to: to}}} = result = live(conn, "/learn/notebooks/new")
|
|
|
|
{:ok, view, _} = follow_redirect(result, conn)
|
2021-06-15 03:25:18 +08:00
|
|
|
|
|
|
|
assert render(view) =~ "Untitled notebook"
|
2023-01-05 23:12:45 +08:00
|
|
|
|
|
|
|
close_session_by_path(to)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp close_session_by_path("/sessions/" <> session_id) do
|
|
|
|
{:ok, session} = Livebook.Sessions.fetch_session(session_id)
|
|
|
|
Livebook.Session.close(session.pid)
|
2021-06-15 03:25:18 +08:00
|
|
|
end
|
2021-06-03 03:51:43 +08:00
|
|
|
end
|