mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-15 20:37:55 +08:00
90e7941fe4
* Update cell actions * Add new focus indicator * Update headings typography * Update cell actions and insert buttons * Add sidebar menu * Add settings modal * Update homepage * Update settings dialog * Rename classes * Add floating menu * Update icon colors on hover * Fix homepage tests * Format assets source * Update monaco editor * Fix editor width on resize * Add more padding to the notebook content * Update settings dialog title * Show reevaluate button when the cell is in evaluated state * Show section actions on focus or hover only * Pre-fill runtime selector with the current configuration * Ignore cmd + enter in Markdown cells
118 lines
3 KiB
Elixir
118 lines
3 KiB
Elixir
defmodule LivebookWeb.HomeLiveTest do
|
|
use LivebookWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
alias Livebook.SessionSupervisor
|
|
|
|
test "disconnected and connected render", %{conn: conn} do
|
|
{:ok, view, disconnected_html} = live(conn, "/")
|
|
assert disconnected_html =~ "Running Sessions"
|
|
assert render(view) =~ "Running Sessions"
|
|
end
|
|
|
|
test "redirects to session upon creation", %{conn: conn} do
|
|
{:ok, view, _} = live(conn, "/")
|
|
|
|
assert {:error, {:live_redirect, %{to: to}}} =
|
|
view
|
|
|> element("button", "New Notebook")
|
|
|> render_click()
|
|
|
|
assert to =~ "/sessions/"
|
|
end
|
|
|
|
describe "file selection" do
|
|
test "updates the list of files as the input changes", %{conn: conn} do
|
|
{:ok, view, _} = live(conn, "/")
|
|
|
|
path = Path.expand("../../../lib", __DIR__) <> "/"
|
|
|
|
assert view
|
|
|> element("form")
|
|
|> render_change(%{path: path}) =~ "livebook_web"
|
|
end
|
|
|
|
test "allows importing when a notebook file is selected", %{conn: conn} do
|
|
{:ok, view, _} = live(conn, "/")
|
|
|
|
path = test_notebook_path("basic")
|
|
|
|
view
|
|
|> element("form")
|
|
|> render_change(%{path: path})
|
|
|
|
assert assert {:error, {:live_redirect, %{to: to}}} =
|
|
view
|
|
|> element(~s{button[phx-click="fork"]}, "Fork")
|
|
|> render_click()
|
|
|
|
assert to =~ "/sessions/"
|
|
end
|
|
|
|
test "disables import when a directory is selected", %{conn: conn} do
|
|
{:ok, view, _} = live(conn, "/")
|
|
|
|
path = File.cwd!()
|
|
|
|
view
|
|
|> element("form")
|
|
|> render_change(%{path: path})
|
|
|
|
assert view
|
|
|> element(~s{button[phx-click="fork"][disabled]}, "Fork")
|
|
|> has_element?()
|
|
end
|
|
|
|
test "disables import when a nonexistent file is selected", %{conn: conn} do
|
|
{:ok, view, _} = live(conn, "/")
|
|
|
|
path = File.cwd!() |> Path.join("nonexistent.livemd")
|
|
|
|
view
|
|
|> element("form")
|
|
|> render_change(%{path: path})
|
|
|
|
assert view
|
|
|> element(~s{button[phx-click="fork"][disabled]}, "Fork")
|
|
|> has_element?()
|
|
end
|
|
end
|
|
|
|
describe "sessions list" do
|
|
test "lists running sessions", %{conn: conn} do
|
|
{:ok, id1} = SessionSupervisor.create_session()
|
|
{:ok, id2} = SessionSupervisor.create_session()
|
|
|
|
{:ok, view, _} = live(conn, "/")
|
|
|
|
assert render(view) =~ id1
|
|
assert render(view) =~ id2
|
|
end
|
|
|
|
test "updates UI whenever a session is added or deleted", %{conn: conn} do
|
|
{:ok, view, _} = live(conn, "/")
|
|
|
|
{:ok, id} = SessionSupervisor.create_session()
|
|
assert render(view) =~ id
|
|
|
|
SessionSupervisor.delete_session(id)
|
|
refute render(view) =~ id
|
|
end
|
|
end
|
|
|
|
# Helpers
|
|
|
|
defp test_notebook_path(name) do
|
|
path =
|
|
["../../support/notebooks", name <> ".livemd"]
|
|
|> Path.join()
|
|
|> Path.expand(__DIR__)
|
|
|
|
unless File.exists?(path) do
|
|
raise "Cannot find test notebook with the name: #{name}"
|
|
end
|
|
|
|
path
|
|
end
|
|
end
|