add Site context with social links editor and site-wide settings
Some checks failed
deploy / deploy (push) Has been cancelled
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>
This commit is contained in:
@@ -4,7 +4,7 @@ defmodule BerrypodWeb.Shop.NavigationTest do
|
||||
import Phoenix.LiveViewTest
|
||||
import Berrypod.AccountsFixtures
|
||||
|
||||
alias Berrypod.{Pages, Settings}
|
||||
alias Berrypod.{Pages, Settings, Site}
|
||||
alias Berrypod.Pages.PageCache
|
||||
|
||||
setup do
|
||||
@@ -16,6 +16,9 @@ defmodule BerrypodWeb.Shop.NavigationTest do
|
||||
|
||||
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"
|
||||
@@ -24,15 +27,15 @@ defmodule BerrypodWeb.Shop.NavigationTest do
|
||||
assert html =~ "Contact"
|
||||
end
|
||||
|
||||
test "renders from saved settings", %{conn: conn} do
|
||||
Settings.put_setting(
|
||||
"header_nav",
|
||||
[
|
||||
%{"label" => "Blog", "href" => "/blog", "slug" => "blog"},
|
||||
%{"label" => "FAQ", "href" => "/faq", "slug" => "faq"}
|
||||
],
|
||||
"json"
|
||||
)
|
||||
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"/")
|
||||
|
||||
@@ -44,6 +47,8 @@ defmodule BerrypodWeb.Shop.NavigationTest do
|
||||
|
||||
describe "footer navigation" do
|
||||
test "renders default items", %{conn: conn} do
|
||||
Site.seed_defaults()
|
||||
|
||||
{:ok, _view, html} = live(conn, ~p"/")
|
||||
|
||||
assert html =~ "Delivery & returns"
|
||||
@@ -51,15 +56,25 @@ defmodule BerrypodWeb.Shop.NavigationTest do
|
||||
assert html =~ "Terms of service"
|
||||
end
|
||||
|
||||
test "renders from saved settings", %{conn: conn} do
|
||||
Settings.put_setting(
|
||||
"footer_nav",
|
||||
[
|
||||
%{"label" => "Returns", "href" => "/returns", "slug" => "returns"},
|
||||
%{"label" => "Shipping", "href" => "/shipping", "slug" => "shipping"}
|
||||
],
|
||||
"json"
|
||||
)
|
||||
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"/")
|
||||
|
||||
@@ -71,16 +86,21 @@ defmodule BerrypodWeb.Shop.NavigationTest do
|
||||
|
||||
describe "custom page in navigation" do
|
||||
test "renders when added to header nav", %{conn: conn} do
|
||||
{:ok, _} = Pages.create_custom_page(%{slug: "faq", title: "FAQ"})
|
||||
{:ok, page} = Pages.create_custom_page(%{slug: "faq", title: "FAQ"})
|
||||
|
||||
Settings.put_setting(
|
||||
"header_nav",
|
||||
[
|
||||
%{"label" => "Home", "href" => "/", "slug" => "home"},
|
||||
%{"label" => "FAQ", "href" => "/faq", "slug" => "faq"}
|
||||
],
|
||||
"json"
|
||||
)
|
||||
# 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"/")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user