mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-10 21:46:46 +08:00
Improve tests
This commit is contained in:
parent
f4fc76f4f0
commit
be32b94475
3 changed files with 23 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
defmodule Livebook.LiveMarkdown.ExportTest do
|
defmodule Livebook.LiveMarkdown.ExportTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
|
import Livebook.TestHelpers
|
||||||
|
|
||||||
alias Livebook.LiveMarkdown.Export
|
alias Livebook.LiveMarkdown.Export
|
||||||
alias Livebook.Notebook
|
alias Livebook.Notebook
|
||||||
|
|
||||||
|
@ -1327,7 +1329,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
|
||||||
|
|
||||||
describe "file entries" do
|
describe "file entries" do
|
||||||
test "persists file entries" do
|
test "persists file entries" do
|
||||||
file = Livebook.FileSystem.File.new(Livebook.FileSystem.Local.new(), "/document.pdf")
|
file = Livebook.FileSystem.File.new(Livebook.FileSystem.Local.new(), p("/document.pdf"))
|
||||||
|
|
||||||
notebook = %{
|
notebook = %{
|
||||||
Notebook.new()
|
Notebook.new()
|
||||||
|
@ -1340,7 +1342,7 @@ defmodule Livebook.LiveMarkdown.ExportTest do
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_document = """
|
expected_document = """
|
||||||
<!-- livebook:{"file_entries":[{"name":"data.csv","type":"url","url":"https://example.com/data.csv"},{"file":{"file_system_id":"local","path":"/document.pdf"},"name":"document.pdf","type":"file"},{"name":"image.jpg","type":"attachment"}]} -->
|
<!-- livebook:{"file_entries":[{"name":"data.csv","type":"url","url":"https://example.com/data.csv"},{"file":{"file_system_id":"local","path":"#{p("/document.pdf")}"},"name":"document.pdf","type":"file"},{"name":"image.jpg","type":"attachment"}]} -->
|
||||||
|
|
||||||
# My Notebook
|
# My Notebook
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -42,6 +42,12 @@ defmodule LivebookWeb.AppLiveTest do
|
||||||
|
|
||||||
Livebook.Session.app_deactivate(session_pid2)
|
Livebook.Session.app_deactivate(session_pid2)
|
||||||
|
|
||||||
|
assert_receive {:app_updated,
|
||||||
|
%{
|
||||||
|
pid: ^app_pid,
|
||||||
|
sessions: [%{app_status: %{lifecycle: :deactivated}}, _]
|
||||||
|
}}
|
||||||
|
|
||||||
{:ok, view, _} = live(conn, ~p"/apps/#{slug}")
|
{:ok, view, _} = live(conn, ~p"/apps/#{slug}")
|
||||||
|
|
||||||
assert render(view) =~ ~p"/apps/#{slug}/#{session_id1}"
|
assert render(view) =~ ~p"/apps/#{slug}/#{session_id1}"
|
||||||
|
|
|
@ -1524,6 +1524,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
@tag :tmp_dir
|
@tag :tmp_dir
|
||||||
test "adding :attachment file entry from file",
|
test "adding :attachment file entry from file",
|
||||||
%{conn: conn, session: session, tmp_dir: tmp_dir} do
|
%{conn: conn, session: session, tmp_dir: tmp_dir} do
|
||||||
|
Session.subscribe(session.id)
|
||||||
|
|
||||||
path = Path.join(tmp_dir, "image.jpg")
|
path = Path.join(tmp_dir, "image.jpg")
|
||||||
File.write!(path, "content")
|
File.write!(path, "content")
|
||||||
|
|
||||||
|
@ -1543,6 +1545,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
|> element(~s{#add-file-entry-form})
|
|> element(~s{#add-file-entry-form})
|
||||||
|> render_submit(%{"data" => %{"name" => "image.jpg", "copy" => "true"}})
|
|> render_submit(%{"data" => %{"name" => "image.jpg", "copy" => "true"}})
|
||||||
|
|
||||||
|
assert_receive {:operation, {:add_file_entries, _client_id, [%{name: "image.jpg"}]}}
|
||||||
|
|
||||||
assert %{notebook: %{file_entries: [%{type: :attachment, name: "image.jpg"}]}} =
|
assert %{notebook: %{file_entries: [%{type: :attachment, name: "image.jpg"}]}} =
|
||||||
Session.get_data(session.pid)
|
Session.get_data(session.pid)
|
||||||
|
|
||||||
|
@ -1579,6 +1583,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "adding :attachment file entry from url", %{conn: conn, session: session} do
|
test "adding :attachment file entry from url", %{conn: conn, session: session} do
|
||||||
|
Session.subscribe(session.id)
|
||||||
|
|
||||||
bypass = Bypass.open()
|
bypass = Bypass.open()
|
||||||
file_url = "http://localhost:#{bypass.port}/image.jpg"
|
file_url = "http://localhost:#{bypass.port}/image.jpg"
|
||||||
|
|
||||||
|
@ -1603,6 +1609,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
"data" => %{"name" => "image.jpg", "copy" => "true", "url" => file_url}
|
"data" => %{"name" => "image.jpg", "copy" => "true", "url" => file_url}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
assert_receive {:operation, {:add_file_entries, _client_id, [%{name: "image.jpg"}]}}
|
||||||
|
|
||||||
assert %{notebook: %{file_entries: [%{type: :attachment, name: "image.jpg"}]}} =
|
assert %{notebook: %{file_entries: [%{type: :attachment, name: "image.jpg"}]}} =
|
||||||
Session.get_data(session.pid)
|
Session.get_data(session.pid)
|
||||||
|
|
||||||
|
@ -1703,6 +1711,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
|
|
||||||
@tag :tmp_dir
|
@tag :tmp_dir
|
||||||
test "transferring file entry", %{conn: conn, session: session, tmp_dir: tmp_dir} do
|
test "transferring file entry", %{conn: conn, session: session, tmp_dir: tmp_dir} do
|
||||||
|
Session.subscribe(session.id)
|
||||||
|
|
||||||
tmp_dir = FileSystem.File.local(tmp_dir <> "/")
|
tmp_dir = FileSystem.File.local(tmp_dir <> "/")
|
||||||
image_file = FileSystem.File.resolve(tmp_dir, "image.jpg")
|
image_file = FileSystem.File.resolve(tmp_dir, "image.jpg")
|
||||||
:ok = FileSystem.File.write(image_file, "content")
|
:ok = FileSystem.File.write(image_file, "content")
|
||||||
|
@ -1716,11 +1726,13 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
|> element(~s/[data-el-files-list] menu button/, "Copy to files")
|
|> element(~s/[data-el-files-list] menu button/, "Copy to files")
|
||||||
|> render_click()
|
|> render_click()
|
||||||
|
|
||||||
assert {:ok, true} = FileSystem.File.exists?(image_file)
|
assert_receive {:operation, {:add_file_entries, _client_id, [%{name: "image.jpg"}]}}
|
||||||
|
|
||||||
assert %{notebook: %{file_entries: [%{type: :attachment, name: "image.jpg"}]}} =
|
assert %{notebook: %{file_entries: [%{type: :attachment, name: "image.jpg"}]}} =
|
||||||
Session.get_data(session.pid)
|
Session.get_data(session.pid)
|
||||||
|
|
||||||
|
assert {:ok, true} = FileSystem.File.exists?(image_file)
|
||||||
|
|
||||||
assert FileSystem.File.resolve(session.files_dir, "image.jpg") |> FileSystem.File.read() ==
|
assert FileSystem.File.resolve(session.files_dir, "image.jpg") |> FileSystem.File.read() ==
|
||||||
{:ok, "content"}
|
{:ok, "content"}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue