2022-09-12 22:34:39 +08:00
|
|
|
defmodule LivebookWeb.SettingsLiveTest do
|
|
|
|
use LivebookWeb.ConnCase, async: true
|
|
|
|
@moduletag :tmp_dir
|
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
|
|
|
|
alias Livebook.Settings
|
|
|
|
|
|
|
|
describe "environment variables configuration" do
|
|
|
|
test "list persisted environment variables", %{conn: conn} do
|
2022-09-17 07:37:01 +08:00
|
|
|
insert_env_var(:env_var, name: "MY_ENVIRONMENT_VAR")
|
2023-02-23 02:34:54 +08:00
|
|
|
{:ok, _view, html} = live(conn, ~p"/settings")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
|
|
|
assert html =~ "MY_ENVIRONMENT_VAR"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "adds an environment variable", %{conn: conn} do
|
2022-09-17 07:37:01 +08:00
|
|
|
attrs = params_for(:env_var, name: "JAKE_PERALTA_ENV_VAR")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2023-02-23 02:34:54 +08:00
|
|
|
{:ok, view, html} = live(conn, ~p"/settings/env-var/new")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
|
|
|
assert html =~ "Add environment variable"
|
2022-09-17 07:37:01 +08:00
|
|
|
refute html =~ attrs.name
|
2022-09-12 22:34:39 +08:00
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#env-var-form")
|
|
|
|
|> render_change(%{"env_var" => attrs})
|
|
|
|
|
|
|
|
refute view
|
|
|
|
|> element("#env-var-form .invalid-feedback")
|
|
|
|
|> has_element?()
|
|
|
|
|
|
|
|
view
|
|
|
|
|> element("#env-var-form")
|
|
|
|
|> render_submit(%{"env_var" => attrs})
|
|
|
|
|
2023-02-23 02:34:54 +08:00
|
|
|
assert_patch(view, ~p"/settings")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
assert render(view) =~ attrs.name
|
2022-09-12 22:34:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates an environment variable", %{conn: conn} do
|
2022-09-17 07:37:01 +08:00
|
|
|
env_var = insert_env_var(:env_var, name: "UPDATE_ME")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2023-02-23 02:34:54 +08:00
|
|
|
{:ok, view, html} = live(conn, ~p"/settings")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
assert html =~ env_var.name
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
render_click(view, "edit_env_var", %{"env_var" => env_var.name})
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2023-02-23 02:34:54 +08:00
|
|
|
assert_patch(view, ~p"/settings/env-var/edit/#{env_var.name}")
|
2022-09-12 22:34:39 +08:00
|
|
|
assert render(view) =~ "Edit environment variable"
|
|
|
|
|
|
|
|
form = element(view, "#env-var-form")
|
|
|
|
assert render(form) =~ env_var.value
|
|
|
|
|
|
|
|
render_change(form, %{"env_var" => %{"value" => "123456"}})
|
|
|
|
|
|
|
|
refute view
|
|
|
|
|> element(".invalid-feedback")
|
|
|
|
|> has_element?()
|
|
|
|
|
|
|
|
render_submit(form, %{"env_var" => %{"value" => "123456"}})
|
2023-02-23 02:34:54 +08:00
|
|
|
assert_patch(view, ~p"/settings")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
updated_env_var = Settings.fetch_env_var!(env_var.name)
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
assert updated_env_var.name == env_var.name
|
2022-09-12 22:34:39 +08:00
|
|
|
refute updated_env_var.value == env_var.value
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes an environment variable", %{conn: conn} do
|
|
|
|
env_var = insert_env_var(:env_var)
|
2023-02-23 02:34:54 +08:00
|
|
|
{:ok, view, html} = live(conn, ~p"/settings")
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
assert html =~ env_var.name
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
render_click(view, "delete_env_var", %{"env_var" => env_var.name})
|
2022-09-12 22:34:39 +08:00
|
|
|
|
2022-09-17 07:37:01 +08:00
|
|
|
refute render(view) =~ env_var.name
|
2022-09-12 22:34:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|