Some checks failed
deploy / deploy (push) Has been cancelled
- Add Site context for managing site-wide content (social links, nav items, announcement bar, footer content) - Add SocialLink schema with URL normalization and platform auto-detection supporting 40+ platforms via host and 25+ via URI scheme - Add NavItem schema for header/footer navigation (editor UI coming next) - Add SiteEditor component with collapsible sections for each content type - Wire social links card block and footer to use database data - Filter empty URLs from display in shop components - Add DetailsPreserver hook to preserve collapsible section state - Add comprehensive tests for Site context and SocialLink functions - Remove unused helper functions from onboarding to fix compiler warnings - Move sync_edit_url_param helper to group handle_editor_event clauses Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
112 lines
2.9 KiB
Elixir
112 lines
2.9 KiB
Elixir
defmodule BerrypodWeb.Shop.NavigationTest do
|
|
use BerrypodWeb.ConnCase, async: false
|
|
|
|
import Phoenix.LiveViewTest
|
|
import Berrypod.AccountsFixtures
|
|
|
|
alias Berrypod.{Pages, Settings, Site}
|
|
alias Berrypod.Pages.PageCache
|
|
|
|
setup do
|
|
PageCache.invalidate_all()
|
|
user_fixture()
|
|
{:ok, _} = Settings.set_site_live(true)
|
|
:ok
|
|
end
|
|
|
|
describe "header navigation" do
|
|
test "renders default items", %{conn: conn} do
|
|
# Seed defaults if not already present
|
|
Site.seed_defaults()
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/")
|
|
|
|
assert html =~ "Home"
|
|
assert html =~ "Shop"
|
|
assert html =~ "About"
|
|
assert html =~ "Contact"
|
|
end
|
|
|
|
test "renders from database nav items", %{conn: conn} do
|
|
# Clear existing and add custom items
|
|
for item <- Site.list_nav_items("header"), do: Site.delete_nav_item(item)
|
|
|
|
{:ok, _} =
|
|
Site.create_nav_item(%{location: "header", label: "Blog", url: "/blog", position: 0})
|
|
|
|
{:ok, _} =
|
|
Site.create_nav_item(%{location: "header", label: "FAQ", url: "/faq", position: 1})
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/")
|
|
|
|
assert html =~ "Blog"
|
|
assert html =~ "FAQ"
|
|
refute html =~ ~s(>Shop</a>)
|
|
end
|
|
end
|
|
|
|
describe "footer navigation" do
|
|
test "renders default items", %{conn: conn} do
|
|
Site.seed_defaults()
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/")
|
|
|
|
assert html =~ "Delivery & returns"
|
|
assert html =~ "Privacy policy"
|
|
assert html =~ "Terms of service"
|
|
end
|
|
|
|
test "renders from database nav items", %{conn: conn} do
|
|
# Clear existing and add custom items
|
|
for item <- Site.list_nav_items("footer"), do: Site.delete_nav_item(item)
|
|
|
|
{:ok, _} =
|
|
Site.create_nav_item(%{
|
|
location: "footer",
|
|
label: "Returns",
|
|
url: "/returns",
|
|
position: 0
|
|
})
|
|
|
|
{:ok, _} =
|
|
Site.create_nav_item(%{
|
|
location: "footer",
|
|
label: "Shipping",
|
|
url: "/shipping",
|
|
position: 1
|
|
})
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/")
|
|
|
|
assert html =~ "Returns"
|
|
assert html =~ "Shipping"
|
|
refute html =~ "Privacy policy"
|
|
end
|
|
end
|
|
|
|
describe "custom page in navigation" do
|
|
test "renders when added to header nav", %{conn: conn} do
|
|
{:ok, page} = Pages.create_custom_page(%{slug: "faq", title: "FAQ"})
|
|
|
|
# Clear existing header nav and add custom items
|
|
for item <- Site.list_nav_items("header"), do: Site.delete_nav_item(item)
|
|
|
|
{:ok, _} = Site.create_nav_item(%{location: "header", label: "Home", url: "/", position: 0})
|
|
|
|
{:ok, _} =
|
|
Site.create_nav_item(%{
|
|
location: "header",
|
|
label: "FAQ",
|
|
url: "/faq",
|
|
page_id: page.id,
|
|
position: 1
|
|
})
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/")
|
|
|
|
assert html =~ ~s(href="/faq")
|
|
assert html =~ "FAQ"
|
|
end
|
|
end
|
|
end
|