mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-06 19:46:00 +08:00
Don't create online team hubs in off-hub tests (#2307)
This commit is contained in:
parent
e2eba37ea7
commit
e1b9e931cf
6 changed files with 20 additions and 33 deletions
|
@ -104,13 +104,9 @@ defmodule Livebook.Hubs do
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec unset_default_hub(String.t()) :: :ok
|
@spec unset_default_hub() :: :ok
|
||||||
def unset_default_hub(id) do
|
def unset_default_hub() do
|
||||||
with {:ok, _hub} <- fetch_hub(id) do
|
:ok = Storage.delete(:default_hub, "default_hub")
|
||||||
:ok = Storage.delete(:default_hub, "default_hub")
|
|
||||||
end
|
|
||||||
|
|
||||||
:ok
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_default_hub() :: Provider.t()
|
@spec get_default_hub() :: Provider.t()
|
||||||
|
@ -124,7 +120,7 @@ defmodule Livebook.Hubs do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_unset_default_hub(hub_id) do
|
defp maybe_unset_default_hub(hub_id) do
|
||||||
if get_default_hub().id == hub_id, do: unset_default_hub(hub_id), else: :ok
|
if get_default_hub().id == hub_id, do: unset_default_hub(), else: :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
defp disconnect_hub(hub) do
|
defp disconnect_hub(hub) do
|
||||||
|
|
|
@ -433,7 +433,7 @@ defmodule LivebookWeb.Hub.Edit.TeamComponent do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("remove_as_default", _, socket) do
|
def handle_event("remove_as_default", _, socket) do
|
||||||
Hubs.unset_default_hub(socket.assigns.hub.id)
|
Hubs.unset_default_hub()
|
||||||
{:noreply, push_navigate(socket, to: ~p"/hub/#{socket.assigns.hub.id}")}
|
{:noreply, push_navigate(socket, to: ~p"/hub/#{socket.assigns.hub.id}")}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -749,7 +749,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "imports notebook hub id when exists" do
|
test "imports notebook hub id when exists" do
|
||||||
%{id: hub_id} = Livebook.Factory.insert_hub(:team)
|
%{id: hub_id} = Livebook.HubHelpers.offline_hub()
|
||||||
|
|
||||||
markdown = """
|
markdown = """
|
||||||
<!-- livebook:{"hub_id":"#{hub_id}"} -->
|
<!-- livebook:{"hub_id":"#{hub_id}"} -->
|
||||||
|
@ -1216,7 +1216,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "sets :teams_enabled to true when the teams hub exist regardless the stamp" do
|
test "sets :teams_enabled to true when the teams hub exist regardless the stamp" do
|
||||||
%{id: hub_id} = Livebook.Factory.insert_hub(:team)
|
%{id: hub_id} = Livebook.HubHelpers.offline_hub()
|
||||||
|
|
||||||
markdown = """
|
markdown = """
|
||||||
<!-- livebook:{"hub_id":"#{hub_id}"} -->
|
<!-- livebook:{"hub_id":"#{hub_id}"} -->
|
||||||
|
|
|
@ -1913,31 +1913,35 @@ defmodule Livebook.SessionTest do
|
||||||
|
|
||||||
describe "default hub for new notebooks" do
|
describe "default hub for new notebooks" do
|
||||||
test "use the default hub as default for new notebooks" do
|
test "use the default hub as default for new notebooks" do
|
||||||
hub = Livebook.Factory.insert_hub(:team)
|
hub = Livebook.HubHelpers.offline_hub()
|
||||||
Livebook.Hubs.set_default_hub(hub.id)
|
Livebook.Hubs.set_default_hub(hub.id)
|
||||||
notebook = Livebook.Session.default_notebook()
|
notebook = Livebook.Session.default_notebook()
|
||||||
|
|
||||||
assert notebook.hub_id == hub.id
|
assert notebook.hub_id == hub.id
|
||||||
Livebook.Hubs.delete_hub(hub.id)
|
|
||||||
|
Livebook.Hubs.unset_default_hub()
|
||||||
end
|
end
|
||||||
|
|
||||||
test "fallback to personal-hub when there's no default" do
|
test "fallback to personal-hub when there's no default" do
|
||||||
hub = Livebook.Factory.insert_hub(:team)
|
hub = Livebook.HubHelpers.offline_hub()
|
||||||
Livebook.Hubs.unset_default_hub(hub.id)
|
Livebook.Hubs.set_default_hub(hub.id)
|
||||||
|
Livebook.Hubs.unset_default_hub()
|
||||||
notebook = Livebook.Session.default_notebook()
|
notebook = Livebook.Session.default_notebook()
|
||||||
|
|
||||||
assert notebook.hub_id == "personal-hub"
|
assert notebook.hub_id == "personal-hub"
|
||||||
Livebook.Hubs.delete_hub(hub.id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "fallback to personal-hub when the default doesn't exist" do
|
test "fallback to personal-hub when the default doesn't exist" do
|
||||||
hub = Livebook.Factory.insert_hub(:team)
|
hub = Livebook.Factory.build(:team)
|
||||||
|
Livebook.Hubs.save_hub(hub)
|
||||||
Livebook.Hubs.set_default_hub(hub.id)
|
Livebook.Hubs.set_default_hub(hub.id)
|
||||||
Livebook.Hubs.delete_hub(hub.id)
|
Livebook.Hubs.delete_hub(hub.id)
|
||||||
notebook = Livebook.Session.default_notebook()
|
notebook = Livebook.Session.default_notebook()
|
||||||
|
|
||||||
refute Livebook.Hubs.hub_exists?(hub.id)
|
refute Livebook.Hubs.hub_exists?(hub.id)
|
||||||
assert notebook.hub_id == "personal-hub"
|
assert notebook.hub_id == "personal-hub"
|
||||||
|
|
||||||
|
Livebook.Hubs.unset_default_hub()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -205,20 +205,13 @@ defmodule LivebookWeb.HomeLiveTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "hubs" do
|
describe "hubs" do
|
||||||
test "renders sidebar section", %{conn: conn} do
|
test "renders persisted hubs in the sidebar", %{conn: conn} do
|
||||||
{:ok, view, _} = live(conn, ~p"/")
|
team = Livebook.HubHelpers.offline_hub()
|
||||||
assert render(view) =~ "HUBS"
|
|
||||||
assert render(view) =~ "Add Organization"
|
|
||||||
end
|
|
||||||
|
|
||||||
test "renders sidebar persisted hubs", %{conn: conn} do
|
|
||||||
team = insert_hub(:team, id: "team-foo-bar-id")
|
|
||||||
|
|
||||||
{:ok, view, _} = live(conn, ~p"/")
|
{:ok, view, _} = live(conn, ~p"/")
|
||||||
assert render(view) =~ "HUBS"
|
assert render(view) =~ "HUBS"
|
||||||
assert render(view) =~ team.hub_name
|
assert render(view) =~ team.hub_name
|
||||||
|
assert render(view) =~ "Add Organization"
|
||||||
Livebook.Hubs.delete_hub("team-foo-bar-id")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -89,12 +89,6 @@ defmodule Livebook.Factory do
|
||||||
factory_name |> build() |> struct!(attrs) |> Map.from_struct()
|
factory_name |> build() |> struct!(attrs) |> Map.from_struct()
|
||||||
end
|
end
|
||||||
|
|
||||||
def insert_hub(factory_name, attrs \\ %{}) do
|
|
||||||
factory_name
|
|
||||||
|> build(attrs)
|
|
||||||
|> Livebook.Hubs.save_hub()
|
|
||||||
end
|
|
||||||
|
|
||||||
def insert_secret(attrs \\ %{}) do
|
def insert_secret(attrs \\ %{}) do
|
||||||
secret = build(:secret, attrs)
|
secret = build(:secret, attrs)
|
||||||
hub = Livebook.Hubs.fetch_hub!(secret.hub_id)
|
hub = Livebook.Hubs.fetch_hub!(secret.hub_id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue