2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.PathSelectComponentTest do
|
2021-04-21 01:34:17 +08:00
|
|
|
# Note: we cannot run asynchronously, because we use `File.cd!`
|
|
|
|
use LivebookWeb.ConnCase, async: false
|
2021-02-21 23:54:44 +08:00
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
|
2021-03-04 05:56:28 +08:00
|
|
|
alias LivebookWeb.PathSelectComponent
|
2021-02-21 23:54:44 +08:00
|
|
|
|
|
|
|
test "when the path has a trailing slash, lists that directory" do
|
|
|
|
path = notebooks_path() <> "/"
|
|
|
|
assert render_component(PathSelectComponent, attrs(path: path)) =~ "basic.livemd"
|
|
|
|
assert render_component(PathSelectComponent, attrs(path: path)) =~ ".."
|
|
|
|
end
|
|
|
|
|
|
|
|
test "when the path has no trailing slash, lists the parent directory" do
|
|
|
|
path = notebooks_path()
|
|
|
|
assert render_component(PathSelectComponent, attrs(path: path)) =~ "notebooks"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not show parent directory when in root" do
|
|
|
|
path = "/"
|
|
|
|
refute render_component(PathSelectComponent, attrs(path: path)) =~ ".."
|
|
|
|
end
|
|
|
|
|
|
|
|
test "relative paths are expanded from the current working directory" do
|
2021-04-22 05:02:09 +08:00
|
|
|
File.cd!(notebooks_path(), fn ->
|
|
|
|
path = ""
|
|
|
|
assert render_component(PathSelectComponent, attrs(path: path)) =~ "basic.livemd"
|
|
|
|
end)
|
2021-02-21 23:54:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
defp attrs(attrs) do
|
2021-02-27 03:53:29 +08:00
|
|
|
Keyword.merge(
|
2021-04-13 04:59:48 +08:00
|
|
|
[
|
|
|
|
id: 1,
|
|
|
|
path: "/",
|
|
|
|
extnames: [".livemd"],
|
|
|
|
running_paths: [],
|
|
|
|
phx_target: nil,
|
|
|
|
phx_submit: nil
|
|
|
|
],
|
2021-02-27 03:53:29 +08:00
|
|
|
attrs
|
|
|
|
)
|
2021-02-21 23:54:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
defp notebooks_path() do
|
|
|
|
Path.expand("../../support/notebooks", __DIR__)
|
|
|
|
end
|
|
|
|
end
|