- new /setup page with three-section onboarding (account, provider, payments) - dashboard launch checklist with progress bar, go-live, dismiss - provider registry on Provider module (single source of truth for metadata) - payments registry for Stripe - setup context made provider-agnostic (provider_connected, theme_customised, etc.) - admin provider pages now fully registry-driven (no hardcoded provider names) - auth flow: fresh installs redirect to /setup, signed_in_path respects setup state - removed old /admin/setup wizard - 840 tests, 0 failures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
2.9 KiB
Elixir
107 lines
2.9 KiB
Elixir
defmodule BerrypodWeb.Admin.DashboardTest do
|
|
use BerrypodWeb.ConnCase, async: false
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Berrypod.AccountsFixtures
|
|
import Berrypod.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 "launch checklist" do
|
|
setup %{conn: conn, user: user} do
|
|
%{conn: log_in_user(conn, user)}
|
|
end
|
|
|
|
test "shows checklist when site not live", %{conn: conn} do
|
|
{:ok, _view, html} = live(conn, ~p"/admin")
|
|
|
|
assert html =~ "Launch checklist"
|
|
assert html =~ "Sync your products"
|
|
assert html =~ "Customise your theme"
|
|
assert html =~ "Go live"
|
|
end
|
|
|
|
test "hides checklist when site is live", %{conn: conn} do
|
|
{:ok, _} = Berrypod.Settings.set_site_live(true)
|
|
{:ok, _view, html} = live(conn, ~p"/admin")
|
|
|
|
refute html =~ "Launch checklist"
|
|
end
|
|
|
|
test "dismiss checklist hides it", %{conn: conn} do
|
|
{:ok, view, _html} = live(conn, ~p"/admin")
|
|
assert has_element?(view, "button", "Dismiss")
|
|
|
|
html = render_click(view, "dismiss_checklist")
|
|
|
|
refute html =~ "Launch checklist"
|
|
end
|
|
|
|
test "go live button works", %{conn: conn} do
|
|
# Need provider + products + stripe for go live to be enabled
|
|
{:ok, conn_record} =
|
|
Berrypod.Products.create_provider_connection(%{
|
|
name: "Test",
|
|
provider_type: "printify",
|
|
api_key: "test_key"
|
|
})
|
|
|
|
{:ok, _} =
|
|
Berrypod.Products.create_product(%{
|
|
title: "Test product",
|
|
provider_product_id: "ext-1",
|
|
provider_connection_id: conn_record.id,
|
|
status: "active"
|
|
})
|
|
|
|
{:ok, _} = Berrypod.Settings.put_secret("stripe_api_key", "sk_test_123")
|
|
|
|
{:ok, view, _html} = live(conn, ~p"/admin")
|
|
|
|
html = render_click(view, "go_live")
|
|
|
|
assert html =~ "Your shop is live"
|
|
assert Berrypod.Settings.site_live?()
|
|
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
|
|
|
|
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/products']", "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
|