extract setup wizard to dedicated /admin/setup page

Move the setup stepper out of the dashboard into its own LiveView.
Dashboard now redirects to setup when site isn't live, and shows
stats-only view once live. Also cleans up button component variant
handling, fixes alert CSS, and removes stale demo.html.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-18 23:55:42 +00:00
parent 34aa8190d6
commit 559798206f
23 changed files with 835 additions and 7013 deletions

View File

@@ -18,7 +18,7 @@ defmodule BerrypodWeb.UserSessionControllerTest do
})
assert get_session(conn, :user_token)
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
# Now do a logged in request and assert on the page content
conn = get(conn, ~p"/admin/settings")
@@ -39,7 +39,7 @@ defmodule BerrypodWeb.UserSessionControllerTest do
})
assert conn.resp_cookies["_berrypod_web_user_remember_me"]
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
end
test "logs the user in with return to", %{conn: conn, user: user} do
@@ -80,7 +80,7 @@ defmodule BerrypodWeb.UserSessionControllerTest do
})
assert get_session(conn, :user_token)
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
# Now do a logged in request and assert on the page content
conn = get(conn, ~p"/admin/settings")
@@ -99,7 +99,7 @@ defmodule BerrypodWeb.UserSessionControllerTest do
})
assert get_session(conn, :user_token)
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "User confirmed successfully."
assert Accounts.get_user!(user.id).confirmed_at

View File

@@ -4,7 +4,6 @@ defmodule BerrypodWeb.Admin.DashboardTest do
import Phoenix.LiveViewTest
import Berrypod.AccountsFixtures
import Berrypod.OrdersFixtures
import Berrypod.ProductsFixtures
setup do
user = user_fixture()
@@ -19,77 +18,20 @@ defmodule BerrypodWeb.Admin.DashboardTest do
end
end
describe "setup stepper" do
describe "redirects to setup when not live" do
setup %{conn: conn, user: user} do
%{conn: log_in_user(conn, user)}
end
test "shows stepper with printify form when nothing connected", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/admin")
assert html =~ "Setup steps"
assert html =~ "Connect to Printify"
assert html =~ "Printify API token"
assert html =~ "Connect Stripe"
assert html =~ "Go live"
end
test "shows stripe form when printify is done", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, view, _html} = live(conn, ~p"/admin")
# Printify step should be completed
assert has_element?(view, "li:first-child [class*='bg-green-500']")
# Stripe step should be active with form
assert has_element?(view, "label", "Secret key")
end
test "shows go live button when all services connected", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, _} = Berrypod.Settings.put_secret("stripe_api_key", "sk_test_123")
{:ok, view, _html} = live(conn, ~p"/admin")
assert has_element?(view, "button", "Go live")
end
test "go live shows celebration", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, _} = Berrypod.Settings.put_secret("stripe_api_key", "sk_test_123")
{:ok, view, _html} = live(conn, ~p"/admin")
html = view |> element("button", "Go live") |> render_click()
assert html =~ "Your shop is live!"
assert html =~ "View your shop"
assert html =~ "Customise theme"
end
test "hides stepper when shop is live", %{conn: conn} do
{:ok, _} = Berrypod.Settings.set_site_live(true)
{:ok, _view, html} = live(conn, ~p"/admin")
refute html =~ "Setup steps"
refute html =~ "Printify API token"
end
test "completed steps show summary and are collapsible", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, _view, html} = live(conn, ~p"/admin")
assert html =~ "products synced"
test "redirects to /admin/setup when site not live", %{conn: conn} do
{:error, redirect} = live(conn, ~p"/admin")
assert {:live_redirect, %{to: "/admin/setup"}} = redirect
end
end
describe "stats" do
setup %{conn: conn, user: user} do
{:ok, _} = Berrypod.Settings.set_site_live(true)
%{conn: log_in_user(conn, user)}
end

View File

@@ -30,10 +30,10 @@ defmodule BerrypodWeb.Admin.LayoutTest do
refute has_element?(view, ~s(a.active[href="/admin/settings"]))
end
test "highlights dashboard on dashboard page", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin")
test "highlights setup on setup page", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/setup")
assert has_element?(view, ~s(a.active[href="/admin"]))
assert has_element?(view, ~s(a.active[href="/admin/setup"]))
refute has_element?(view, ~s(a.active[href="/admin/orders"]))
end

View File

@@ -0,0 +1,88 @@
defmodule BerrypodWeb.Admin.SetupTest do
use BerrypodWeb.ConnCase, async: false
import Phoenix.LiveViewTest
import Berrypod.AccountsFixtures
import Berrypod.ProductsFixtures
setup do
user = user_fixture()
%{user: user}
end
describe "unauthenticated" do
test "redirects to login", %{conn: conn} do
{:error, redirect} = live(conn, ~p"/admin/setup")
assert {:redirect, %{to: path}} = redirect
assert path == ~p"/users/log-in"
end
end
describe "setup stepper" do
setup %{conn: conn, user: user} do
%{conn: log_in_user(conn, user)}
end
test "shows stepper with printify form when nothing connected", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/admin/setup")
assert html =~ "Setup steps"
assert html =~ "Connect to Printify"
assert html =~ "Printify API token"
assert html =~ "Connect Stripe"
assert html =~ "Go live"
end
test "shows stripe form when printify is done", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, view, _html} = live(conn, ~p"/admin/setup")
# Printify step should be completed
assert has_element?(view, "li:first-child [class*='bg-green-500']")
# Stripe step should be active with form
assert has_element?(view, "label", "Secret key")
end
test "shows go live button when all services connected", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, _} = Berrypod.Settings.put_secret("stripe_api_key", "sk_test_123")
{:ok, view, _html} = live(conn, ~p"/admin/setup")
assert has_element?(view, "button", "Go live")
end
test "go live shows celebration", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, _} = Berrypod.Settings.put_secret("stripe_api_key", "sk_test_123")
{:ok, view, _html} = live(conn, ~p"/admin/setup")
html = view |> element("button", "Go live") |> render_click()
assert html =~ "Your shop is live!"
assert html =~ "Go to dashboard"
assert html =~ "View your shop"
assert html =~ "Customise theme"
end
test "redirects to /admin when site is live", %{conn: conn} do
{:ok, _} = Berrypod.Settings.set_site_live(true)
{:error, redirect} = live(conn, ~p"/admin/setup")
assert {:live_redirect, %{to: "/admin"}} = redirect
end
test "completed steps show summary and are collapsible", %{conn: conn} do
conn_fixture = provider_connection_fixture(%{provider_type: "printify"})
_product = product_fixture(%{provider_connection: conn_fixture})
{:ok, _view, html} = live(conn, ~p"/admin/setup")
assert html =~ "products synced"
end
end
end

View File

@@ -64,7 +64,7 @@ defmodule BerrypodWeb.Auth.ConfirmationTest do
assert Accounts.get_user!(user.id).confirmed_at
# we are logged in now
assert get_session(conn, :user_token)
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
# log out, new conn
conn = build_conn()

View File

@@ -56,7 +56,7 @@ defmodule BerrypodWeb.Auth.LoginTest do
conn = submit_form(form, conn)
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
end
test "redirects to login page with a flash error if credentials are invalid", %{

View File

@@ -25,7 +25,7 @@ defmodule BerrypodWeb.Auth.RegistrationTest do
conn
|> log_in_user(user_fixture())
|> live(~p"/users/register")
|> follow_redirect(conn, ~p"/admin")
|> follow_redirect(conn, ~p"/admin/setup")
assert {:ok, _conn} = result
end

View File

@@ -25,7 +25,7 @@ defmodule BerrypodWeb.UserAuthTest do
conn = UserAuth.log_in_user(conn, user)
assert token = get_session(conn, :user_token)
assert get_session(conn, :live_socket_id) == "users_sessions:#{Base.url_encode64(token)}"
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
assert Accounts.get_user_by_session_token(token)
end
@@ -80,7 +80,7 @@ defmodule BerrypodWeb.UserAuthTest do
|> assign(:current_scope, Scope.for_user(user))
|> UserAuth.log_in_user(user)
assert redirected_to(conn) == ~p"/admin"
assert redirected_to(conn) == ~p"/admin/setup"
end
test "writes a cookie if remember_me was set in previous session", %{conn: conn, user: user} do