2021-08-14 03:17:43 +08:00
|
|
|
defmodule LivebookWeb.FileSelectComponentTest do
|
|
|
|
use LivebookWeb.ConnCase, async: true
|
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
2022-04-12 02:34:31 +08:00
|
|
|
import Livebook.TestHelpers
|
2021-08-14 03:17:43 +08:00
|
|
|
|
|
|
|
alias Livebook.FileSystem
|
|
|
|
alias LivebookWeb.FileSelectComponent
|
|
|
|
|
|
|
|
test "when the path has a trailing slash, lists that directory" do
|
|
|
|
file = FileSystem.File.local(notebooks_path() <> "/")
|
|
|
|
assert render_component(FileSelectComponent, attrs(file: file)) =~ "basic.livemd"
|
|
|
|
assert render_component(FileSelectComponent, attrs(file: file)) =~ ".."
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when the path has no trailing slash, lists the parent directory" do
|
|
|
|
file = FileSystem.File.local(notebooks_path())
|
|
|
|
assert render_component(FileSelectComponent, attrs(file: file)) =~ "notebooks"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not show parent directory when in root" do
|
2022-04-12 02:34:31 +08:00
|
|
|
file = FileSystem.File.local(p("/"))
|
2021-08-14 03:17:43 +08:00
|
|
|
refute render_component(FileSelectComponent, attrs(file: file)) =~ ".."
|
|
|
|
end
|
|
|
|
|
|
|
|
defp attrs(attrs) do
|
|
|
|
Keyword.merge(
|
|
|
|
[
|
|
|
|
id: 1,
|
2022-04-12 02:34:31 +08:00
|
|
|
file: FileSystem.File.local(p("/")),
|
2021-08-14 03:17:43 +08:00
|
|
|
extnames: [".livemd"],
|
|
|
|
running_files: []
|
|
|
|
],
|
|
|
|
attrs
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp notebooks_path() do
|
|
|
|
Path.expand("../../support/notebooks", __DIR__)
|
|
|
|
end
|
|
|
|
end
|