2022-08-30 22:32:48 +08:00
|
|
|
defmodule LivebookWeb.Hub.EditLiveTest do
|
2023-06-01 23:01:43 +08:00
|
|
|
use LivebookWeb.ConnCase, async: true
|
2022-08-30 22:32:48 +08:00
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
2023-06-22 02:37:28 +08:00
|
|
|
import Livebook.HubHelpers
|
2023-05-11 00:23:08 +08:00
|
|
|
import Livebook.TestHelpers
|
2022-08-30 22:32:48 +08:00
|
|
|
|
|
|
|
alias Livebook.Hubs
|
|
|
|
|
2023-03-09 23:04:47 +08:00
|
|
|
describe "personal" do
|
|
|
|
setup do
|
2023-06-22 02:37:28 +08:00
|
|
|
Livebook.Hubs.subscribe([:crud, :secrets])
|
2023-03-09 23:04:47 +08:00
|
|
|
{:ok, hub: Hubs.fetch_hub!(Hubs.Personal.id())}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updates the hub", %{conn: conn, hub: hub} do
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}")
|
|
|
|
|
|
|
|
attrs = %{"hub_emoji" => "🐈"}
|
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#personal-form")
|
|
|
|
|> render_change(%{"personal" => attrs})
|
|
|
|
|
|
|
|
refute view
|
2023-06-01 23:01:43 +08:00
|
|
|
|> element("#personal-form .invalid-feedback")
|
2023-03-09 23:04:47 +08:00
|
|
|
|> has_element?()
|
|
|
|
|
|
|
|
assert {:ok, view, _html} =
|
|
|
|
view
|
|
|
|
|> element("#personal-form")
|
|
|
|
|> render_submit(%{"personal" => attrs})
|
|
|
|
|> follow_redirect(conn)
|
|
|
|
|
|
|
|
assert render(view) =~ "Hub updated successfully"
|
|
|
|
|
2023-06-22 02:37:28 +08:00
|
|
|
id = hub.id
|
|
|
|
assert_receive {:hub_changed, ^id}
|
|
|
|
|
|
|
|
assert_sidebar_hub(view, id, hub.hub_name, attrs["hub_emoji"])
|
2023-03-09 23:04:47 +08:00
|
|
|
refute Hubs.fetch_hub!(hub.id) == hub
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creates secret", %{conn: conn, hub: hub} do
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}")
|
|
|
|
secret = build(:secret, name: "PERSONAL_ADD_SECRET")
|
|
|
|
|
|
|
|
attrs = %{
|
|
|
|
secret: %{
|
|
|
|
name: secret.name,
|
|
|
|
value: secret.value,
|
|
|
|
hub_id: secret.hub_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refute render(view) =~ secret.name
|
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#add-secret")
|
|
|
|
|> render_click(%{})
|
|
|
|
|
|
|
|
assert_patch(view, ~p"/hub/#{hub.id}/secrets/new")
|
2023-03-10 00:41:40 +08:00
|
|
|
assert render(view) =~ "Add secret"
|
2023-03-09 23:04:47 +08:00
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#secrets-form")
|
|
|
|
|> render_change(attrs)
|
|
|
|
|
|
|
|
refute view
|
|
|
|
|> element("#secrets-form button[disabled]")
|
|
|
|
|> has_element?()
|
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#secrets-form")
|
|
|
|
|> render_submit(attrs)
|
|
|
|
|
|
|
|
assert_receive {:secret_created, ^secret}
|
2023-06-16 04:33:22 +08:00
|
|
|
%{"success" => "Secret created successfully"} = assert_redirect(view, "/hub/#{hub.id}")
|
|
|
|
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}")
|
|
|
|
|
2023-05-27 02:40:45 +08:00
|
|
|
assert render(element(view, "#hub-secrets-list")) =~ secret.name
|
2023-03-09 23:04:47 +08:00
|
|
|
assert secret in Livebook.Hubs.get_secrets(hub)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updates secret", %{conn: conn, hub: hub} do
|
|
|
|
secret = insert_secret(name: "PERSONAL_EDIT_SECRET", value: "GetTheBonk")
|
|
|
|
|
2023-05-27 02:40:45 +08:00
|
|
|
{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}")
|
|
|
|
|
2023-03-09 23:04:47 +08:00
|
|
|
attrs = %{
|
|
|
|
secret: %{
|
|
|
|
name: secret.name,
|
|
|
|
value: secret.value,
|
|
|
|
hub_id: secret.hub_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_value = "new_value"
|
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#hub-secret-#{secret.name}-edit")
|
|
|
|
|> render_click(%{"secret_name" => secret.name})
|
|
|
|
|
|
|
|
assert_patch(view, ~p"/hub/#{hub.id}/secrets/edit/#{secret.name}")
|
|
|
|
assert render(view) =~ "Edit secret"
|
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#secrets-form")
|
|
|
|
|> render_change(attrs)
|
|
|
|
|
|
|
|
refute view
|
|
|
|
|> element("#secrets-form button[disabled]")
|
|
|
|
|> has_element?()
|
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#secrets-form")
|
|
|
|
|> render_submit(put_in(attrs.secret.value, new_value))
|
|
|
|
|
|
|
|
updated_secret = %{secret | value: new_value}
|
|
|
|
|
|
|
|
assert_receive {:secret_updated, ^updated_secret}
|
2023-06-16 04:33:22 +08:00
|
|
|
%{"success" => "Secret updated successfully"} = assert_redirect(view, "/hub/#{hub.id}")
|
|
|
|
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}")
|
2023-05-27 02:40:45 +08:00
|
|
|
assert render(element(view, "#hub-secrets-list")) =~ secret.name
|
2023-03-09 23:04:47 +08:00
|
|
|
assert updated_secret in Livebook.Hubs.get_secrets(hub)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes secret", %{conn: conn, hub: hub} do
|
|
|
|
secret = insert_secret(name: "PERSONAL_DELETE_SECRET", value: "GetTheBonk")
|
|
|
|
|
2023-05-27 02:40:45 +08:00
|
|
|
{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}")
|
|
|
|
|
2023-03-09 23:04:47 +08:00
|
|
|
refute view
|
|
|
|
|> element("#secrets-form button[disabled]")
|
|
|
|
|> has_element?()
|
|
|
|
|
|
|
|
view
|
2023-06-22 02:37:28 +08:00
|
|
|
|> element("#hub-secret-#{secret.name}-delete", "Delete")
|
2023-05-11 00:23:08 +08:00
|
|
|
|> render_click()
|
|
|
|
|
|
|
|
render_confirm(view)
|
2023-03-09 23:04:47 +08:00
|
|
|
|
|
|
|
assert_receive {:secret_deleted, ^secret}
|
2023-06-22 02:37:28 +08:00
|
|
|
%{"success" => "Secret deleted successfully"} = assert_redirect(view, "/hub/#{hub.id}")
|
|
|
|
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}")
|
2023-05-11 00:23:08 +08:00
|
|
|
refute render(element(view, "#hub-secrets-list")) =~ secret.name
|
2023-03-09 23:04:47 +08:00
|
|
|
refute secret in Livebook.Hubs.get_secrets(hub)
|
|
|
|
end
|
|
|
|
end
|
2022-08-30 22:32:48 +08:00
|
|
|
end
|