diff --git a/test/polar_web/live/dashboard/credential/new_live_test.exs b/test/polar_web/live/dashboard/credential/new_live_test.exs index e69de29..c7265f6 100644 --- a/test/polar_web/live/dashboard/credential/new_live_test.exs +++ b/test/polar_web/live/dashboard/credential/new_live_test.exs @@ -0,0 +1,36 @@ +defmodule PolarWeb.Dashboard.Credential.NewLiveTest do + use PolarWeb.ConnCase, async: true + + import Phoenix.LiveViewTest + import Polar.AccountsFixtures + + alias Polar.Repo + alias Polar.Accounts + alias Polar.Accounts.Space + + setup %{conn: conn} do + user = user_fixture() + + conn = log_in_user(conn, user) + + {:ok, space} = Accounts.create_space(user, %{name: "test-space-456"}) + + %{conn: conn, space: space} + end + + describe "New credential creation" do + test "create credential", %{conn: conn, space: space} do + {:ok, lv, _html} = live(conn, ~p"/dashboard/spaces/#{space.id}/credentials/new") + + lv + |> form("#new-credential-form", %{ + "credential" => %{"name" => "new-cred-test", "type" => "lxd", "expires_in" => "2592000"} + }) + |> render_submit() + + credential = Repo.get_by!(Space.Credential, name: "new-cred-test") + + assert_redirect(lv, ~p"/dashboard/spaces/#{space.id}/credentials/#{credential.id}") + end + end +end diff --git a/test/polar_web/live/dashboard/credential_live_test.exs b/test/polar_web/live/dashboard/credential_live_test.exs new file mode 100644 index 0000000..6862c00 --- /dev/null +++ b/test/polar_web/live/dashboard/credential_live_test.exs @@ -0,0 +1,34 @@ +defmodule PolarWeb.Dashboard.CredentialLiveTest do + use PolarWeb.ConnCase, async: true + + import Phoenix.LiveViewTest + import Polar.AccountsFixtures + + alias Polar.Accounts + + setup %{conn: conn} do + user = user_fixture() + + {:ok, space} = Accounts.create_space(user, %{name: "test-space-123"}) + + {:ok, credential} = + Accounts.create_space_credential(space, user, %{ + expires_in: 1_296_000, + name: "test-cred", + type: "lxd" + }) + + conn = log_in_user(conn, user) + + %{conn: conn, user: user, space: space, credential: credential} + end + + describe "credential detail" do + test "can see detail of credential", %{conn: conn, space: space, credential: credential} do + {:ok, _lv, html} = + live(conn, ~p"/dashboard/spaces/#{space.id}/credentials/#{credential.id}") + + assert html =~ "lxc remote add opsmaru" + end + end +end