add page builder polish: utility blocks, templates, duplicate
All checks were successful
deploy / deploy (push) Successful in 1m24s
All checks were successful
deploy / deploy (push) Successful in 1m24s
New block types: spacer, divider, button/CTA, video embed (YouTube, Vimeo with privacy-enhanced embeds, fallback for unknown URLs). Page templates (blank, content, landing) shown when creating custom pages. Duplicate page action on admin index with slug deduplication. Fix block picker on shop edit sidebar being cut off on mobile by accounting for bottom nav and making the grid scrollable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -564,4 +564,73 @@ defmodule Berrypod.PagesTest do
|
||||
refute Page.reserved_path?("faq")
|
||||
end
|
||||
end
|
||||
|
||||
describe "templates" do
|
||||
test "templates/0 returns available templates" do
|
||||
templates = Defaults.templates()
|
||||
|
||||
assert length(templates) == 3
|
||||
keys = Enum.map(templates, & &1.key)
|
||||
assert "blank" in keys
|
||||
assert "content" in keys
|
||||
assert "landing" in keys
|
||||
end
|
||||
|
||||
test "template_blocks/1 returns blocks for content template" do
|
||||
blocks = Defaults.template_blocks("content")
|
||||
|
||||
types = Enum.map(blocks, & &1["type"])
|
||||
assert types == ["hero", "content_body"]
|
||||
end
|
||||
|
||||
test "template_blocks/1 returns blocks for landing template" do
|
||||
blocks = Defaults.template_blocks("landing")
|
||||
|
||||
types = Enum.map(blocks, & &1["type"])
|
||||
assert "hero" in types
|
||||
assert "featured_products" in types
|
||||
assert "button" in types
|
||||
end
|
||||
|
||||
test "template_blocks/1 returns empty list for blank" do
|
||||
assert Defaults.template_blocks("blank") == []
|
||||
end
|
||||
|
||||
test "template blocks have unique IDs" do
|
||||
for tmpl <- Defaults.templates() do
|
||||
blocks = Defaults.template_blocks(tmpl.key)
|
||||
ids = Enum.map(blocks, & &1["id"])
|
||||
assert ids == Enum.uniq(ids), "duplicate IDs in #{tmpl.key} template"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "duplicate_custom_page/1" do
|
||||
test "creates a draft copy with -copy slug" do
|
||||
{:ok, original} =
|
||||
Pages.create_custom_page(%{
|
||||
"slug" => "test-original",
|
||||
"title" => "Test Page",
|
||||
"blocks" => [%{"id" => "blk_1", "type" => "hero", "settings" => %{"title" => "Hello"}}]
|
||||
})
|
||||
|
||||
{:ok, copy} = Pages.duplicate_custom_page(original)
|
||||
|
||||
assert copy.slug == "test-original-copy"
|
||||
assert copy.title == "Test Page (copy)"
|
||||
assert copy.published == false
|
||||
assert length(copy.blocks) == 1
|
||||
assert hd(copy.blocks)["type"] == "hero"
|
||||
end
|
||||
|
||||
test "deduplicates slug when copy already exists" do
|
||||
{:ok, original} =
|
||||
Pages.create_custom_page(%{"slug" => "dup-test", "title" => "Dup Test"})
|
||||
|
||||
{:ok, _first_copy} = Pages.duplicate_custom_page(original)
|
||||
{:ok, second_copy} = Pages.duplicate_custom_page(original)
|
||||
|
||||
assert second_copy.slug == "dup-test-copy-2"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user