add admin dashboard with setup checklist and stats

Dashboard at /admin shows setup progress (when not live), stat cards
(orders, revenue, products), and recent paid orders table. Replaces
the old AdminController redirect. Add Dashboard to sidebar nav as
first item, update admin bar and theme editor links to /admin.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-12 14:17:38 +00:00
parent 4514608c07
commit 0dac93ec0b
10 changed files with 321 additions and 21 deletions

View File

@@ -0,0 +1,70 @@
defmodule SimpleshopThemeWeb.Admin.DashboardTest do
use SimpleshopThemeWeb.ConnCase, async: false
import Phoenix.LiveViewTest
import SimpleshopTheme.AccountsFixtures
import SimpleshopTheme.OrdersFixtures
setup do
user = user_fixture()
%{user: user}
end
describe "unauthenticated" do
test "redirects to login", %{conn: conn} do
{:error, redirect} = live(conn, ~p"/admin")
assert {:redirect, %{to: path}} = redirect
assert path == ~p"/users/log-in"
end
end
describe "setup checklist" do
setup %{conn: conn, user: user} do
%{conn: log_in_user(conn, user)}
end
test "shows setup progress when shop is offline", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/admin")
assert html =~ "Setup progress"
assert html =~ "Create admin account"
assert html =~ "Connect to Printify"
assert html =~ "Connect Stripe"
assert html =~ "Go live"
end
test "hides setup checklist when shop is live", %{conn: conn} do
{:ok, _} = SimpleshopTheme.Settings.set_site_live(true)
{:ok, _view, html} = live(conn, ~p"/admin")
refute html =~ "Setup progress"
end
end
describe "stats" do
setup %{conn: conn, user: user} do
%{conn: log_in_user(conn, user)}
end
test "shows stats cards", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin")
assert has_element?(view, "a[href='/admin/orders']", "Orders")
assert has_element?(view, "a[href='/admin/settings']", "Products")
end
test "shows zero state for orders", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/admin")
assert html =~ "No orders yet"
end
test "shows recent orders when they exist", %{conn: conn} do
order = order_fixture(%{payment_status: "paid"})
{:ok, _view, html} = live(conn, ~p"/admin")
assert html =~ order.order_number
assert html =~ "Recent orders"
end
end
end

View File

@@ -17,6 +17,7 @@ defmodule SimpleshopThemeWeb.Admin.LayoutTest do
test "renders sidebar nav links on admin pages", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/orders")
assert has_element?(view, ~s(a[href="/admin"]), "Dashboard")
assert has_element?(view, ~s(a[href="/admin/orders"]), "Orders")
assert has_element?(view, ~s(a[href="/admin/theme"]), "Theme")
assert has_element?(view, ~s(a[href="/admin/settings"]), "Settings")
@@ -29,6 +30,13 @@ defmodule SimpleshopThemeWeb.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")
assert has_element?(view, ~s(a.active[href="/admin"]))
refute has_element?(view, ~s(a.active[href="/admin/orders"]))
end
test "highlights correct link on different pages", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/settings")
@@ -64,7 +72,7 @@ defmodule SimpleshopThemeWeb.Admin.LayoutTest do
test "shows back link to admin", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/admin/theme")
assert has_element?(view, ~s(a[href="/admin/orders"]), "Admin")
assert has_element?(view, ~s(a[href="/admin"]), "Admin")
end
end
@@ -78,13 +86,13 @@ defmodule SimpleshopThemeWeb.Admin.LayoutTest do
conn = log_in_user(conn, user)
{:ok, _view, html} = live(conn, ~p"/")
assert html =~ ~s(href="/admin/orders")
assert html =~ ~s(href="/admin")
end
test "does not show admin link when logged out", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/")
refute html =~ ~s(href="/admin/orders")
refute html =~ ~s(href="/admin")
end
end
end