2026-02-18 21:23:15 +00:00
|
|
|
defmodule BerrypodWeb.Admin.DashboardTest do
|
|
|
|
|
use BerrypodWeb.ConnCase, async: false
|
2026-02-12 14:17:38 +00:00
|
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
2026-02-18 21:23:15 +00:00
|
|
|
import Berrypod.AccountsFixtures
|
|
|
|
|
import Berrypod.OrdersFixtures
|
2026-02-12 14:17:38 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
describe "launch checklist" do
|
2026-02-12 14:17:38 +00:00
|
|
|
setup %{conn: conn, user: user} do
|
|
|
|
|
%{conn: log_in_user(conn, user)}
|
|
|
|
|
end
|
|
|
|
|
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
test "shows checklist when site not live", %{conn: conn} do
|
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/admin")
|
|
|
|
|
|
|
|
|
|
assert html =~ "Launch checklist"
|
2026-03-03 14:52:31 +00:00
|
|
|
assert html =~ "Connect a print provider"
|
|
|
|
|
assert html =~ "Connect Stripe"
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
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
|
|
|
|
|
|
2026-03-03 14:52:31 +00:00
|
|
|
test "collapse and expand checklist", %{conn: conn} do
|
|
|
|
|
{:ok, view, html} = live(conn, ~p"/admin")
|
|
|
|
|
assert html =~ "Sync your products"
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
|
2026-03-03 14:52:31 +00:00
|
|
|
# Collapse
|
|
|
|
|
html = render_click(view, "toggle_checklist")
|
|
|
|
|
refute html =~ "Sync your products"
|
|
|
|
|
assert html =~ "Launch checklist"
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
|
2026-03-03 14:52:31 +00:00
|
|
|
# Expand
|
|
|
|
|
html = render_click(view, "toggle_checklist")
|
|
|
|
|
assert html =~ "Sync your products"
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "go live button works", %{conn: conn} do
|
2026-03-03 14:52:31 +00:00
|
|
|
# Need provider + products + stripe + shipping for go live
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
{: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")
|
|
|
|
|
|
2026-03-03 14:52:31 +00:00
|
|
|
Berrypod.Shipping.upsert_rates(conn_record.id, [
|
|
|
|
|
%{
|
|
|
|
|
blueprint_id: 1,
|
|
|
|
|
print_provider_id: 1,
|
|
|
|
|
country_code: "GB",
|
|
|
|
|
first_item_cost: 350,
|
|
|
|
|
additional_item_cost: 200,
|
|
|
|
|
currency: "GBP"
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
|
add setup onboarding page, dashboard launch checklist, provider registry
- 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>
2026-02-20 00:34:06 +00:00
|
|
|
{:ok, view, _html} = live(conn, ~p"/admin")
|
|
|
|
|
|
|
|
|
|
html = render_click(view, "go_live")
|
|
|
|
|
|
|
|
|
|
assert html =~ "Your shop is live"
|
|
|
|
|
assert Berrypod.Settings.site_live?()
|
2026-02-12 14:17:38 +00:00
|
|
|
end
|
2026-03-03 14:52:31 +00:00
|
|
|
|
|
|
|
|
test "shows test order guidance", %{conn: conn} do
|
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/admin")
|
|
|
|
|
|
|
|
|
|
assert html =~ "4242 4242 4242 4242"
|
|
|
|
|
end
|
|
|
|
|
|
2026-03-03 17:41:08 +00:00
|
|
|
test "shows email setup item", %{conn: conn} do
|
2026-03-03 14:52:31 +00:00
|
|
|
{:ok, _view, html} = live(conn, ~p"/admin")
|
|
|
|
|
|
|
|
|
|
assert html =~ "Set up email"
|
|
|
|
|
end
|
2026-02-12 14:17:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "stats" do
|
|
|
|
|
setup %{conn: conn, user: user} do
|
2026-02-18 23:55:42 +00:00
|
|
|
{:ok, _} = Berrypod.Settings.set_site_live(true)
|
2026-02-12 14:17:38 +00:00
|
|
|
%{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")
|
2026-02-16 08:48:51 +00:00
|
|
|
assert has_element?(view, "a[href='/admin/products']", "Products")
|
2026-02-12 14:17:38 +00:00
|
|
|
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
|