livebook/test/livebook_web/live/apps_live_test.exs

82 lines
2.3 KiB
Elixir
Raw Normal View History

2023-02-28 22:08:49 +08:00
defmodule LivebookWeb.AppsLiveTest do
use LivebookWeb.ConnCase, async: true
import Phoenix.LiveViewTest
import Livebook.TestHelpers
2023-02-28 22:08:49 +08:00
alias Livebook.{App, Apps, Notebook, Utils}
2023-02-28 22:08:49 +08:00
test "updates UI when app is deployed and terminated", %{conn: conn} do
slug = Utils.random_short_id()
app_settings = %{Notebook.AppSettings.new() | slug: slug}
notebook = %{Notebook.new() | app_settings: app_settings, name: "My app #{slug}"}
2023-02-28 22:08:49 +08:00
2023-03-01 00:28:10 +08:00
{:ok, view, _} = live(conn, ~p"/apps")
2023-02-28 22:08:49 +08:00
refute render(view) =~ slug
Apps.subscribe()
{:ok, app_pid} = Apps.deploy(notebook)
2023-02-28 22:08:49 +08:00
assert_receive {:app_created, %{pid: ^app_pid}}
2023-02-28 22:08:49 +08:00
assert render(view) =~ "My app #{slug}"
App.close(app_pid)
2023-02-28 22:08:49 +08:00
assert_receive {:app_closed, %{pid: ^app_pid}}
2023-02-28 22:08:49 +08:00
refute render(view) =~ slug
end
test "terminating an app", %{conn: conn} do
slug = Utils.random_short_id()
app_settings = %{Notebook.AppSettings.new() | slug: slug}
notebook = %{Notebook.new() | app_settings: app_settings, name: "My app #{slug}"}
{:ok, view, _} = live(conn, ~p"/apps")
Apps.subscribe()
{:ok, app_pid} = Apps.deploy(notebook)
assert_receive {:app_created, %{pid: ^app_pid}}
view
|> element(~s/[data-app-slug="#{slug}"] button[aria-label="terminate app"]/)
|> render_click()
2023-02-28 22:08:49 +08:00
render_confirm(view)
assert_receive {:app_closed, %{pid: ^app_pid}}
end
2023-02-28 22:08:49 +08:00
test "deactivating and terminating an app session", %{conn: conn} do
slug = Utils.random_short_id()
app_settings = %{Notebook.AppSettings.new() | slug: slug}
notebook = %{Notebook.new() | app_settings: app_settings, name: "My app #{slug}"}
2023-02-28 22:08:49 +08:00
2023-03-01 00:28:10 +08:00
{:ok, view, _} = live(conn, ~p"/apps")
Apps.subscribe()
{:ok, app_pid} = Apps.deploy(notebook)
2023-02-28 22:08:49 +08:00
assert_receive {:app_created, %{pid: ^app_pid}}
assert_receive {:app_updated,
%{pid: ^app_pid, sessions: [%{app_status: %{execution: :executed}}]}}
2023-02-28 22:08:49 +08:00
view
|> element(~s/[data-app-slug="#{slug}"] button[aria-label="deactivate app session"]/)
2023-02-28 22:08:49 +08:00
|> render_click()
assert_receive {:app_updated,
%{pid: ^app_pid, sessions: [%{app_status: %{lifecycle: :deactivated}}]}}
2023-02-28 22:08:49 +08:00
view
|> element(~s/[data-app-slug="#{slug}"] button[aria-label="terminate app session"]/)
2023-02-28 22:08:49 +08:00
|> render_click()
assert_receive {:app_updated, %{pid: ^app_pid, sessions: []}}
2023-02-28 22:08:49 +08:00
App.close(app_pid)
2023-02-28 22:08:49 +08:00
end
end