feat: preview working and template delete is in, too
This commit is contained in:
@@ -727,6 +727,44 @@ defmodule BDS.Desktop.ShellLiveTest do
|
||||
refute html =~ ~s(phx-value-mode="visual")
|
||||
end
|
||||
|
||||
test "template sidebar exposes old-app style delete control and removes template rows", %{project: project} do
|
||||
assert {:ok, template} =
|
||||
BDS.Templates.create_template(%{
|
||||
project_id: project.id,
|
||||
title: "Sidebar Template",
|
||||
kind: :post,
|
||||
content: "<article>{{ post.content }}</article>"
|
||||
})
|
||||
|
||||
{:ok, view, _html} = live_isolated(build_conn(), BDS.Desktop.ShellLive)
|
||||
|
||||
html =
|
||||
view
|
||||
|> element("[data-testid='activity-button'][data-view='templates']")
|
||||
|> render_click()
|
||||
|
||||
assert html =~ "Sidebar Template"
|
||||
assert html =~ ~s(data-testid="sidebar-delete-template")
|
||||
|
||||
html =
|
||||
view
|
||||
|> element("[data-testid='sidebar-open-item'][data-item-id='#{template.id}']")
|
||||
|> render_click()
|
||||
|
||||
assert html =~ ~s(data-tab-type="templates")
|
||||
assert html =~ ~s(data-tab-id="#{template.id}")
|
||||
|
||||
html =
|
||||
view
|
||||
|> element("[data-testid='sidebar-delete-template'][data-item-id='#{template.id}']")
|
||||
|> render_click()
|
||||
|
||||
assert BDS.Repo.get(BDS.Templates.Template, template.id) == nil
|
||||
refute html =~ "Sidebar Template"
|
||||
refute html =~ ~s(data-tab-type="templates")
|
||||
refute html =~ ~s(data-tab-id="#{template.id}")
|
||||
end
|
||||
|
||||
defp seed_sidebar_posts(project_id) do
|
||||
now = Persistence.now_ms()
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ defmodule BDS.GenerationTest do
|
||||
Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Rendered Post",
|
||||
content: "Rendered body",
|
||||
content: "**Rendered** body",
|
||||
language: "en",
|
||||
template_slug: published_post_template.slug
|
||||
})
|
||||
@@ -280,7 +280,8 @@ defmodule BDS.GenerationTest do
|
||||
|
||||
post_html = File.read!(Path.join([temp_dir, "html", post_path]))
|
||||
assert post_html =~ "post-template"
|
||||
assert post_html =~ "Rendered body"
|
||||
assert post_html =~ ~s(<strong>Rendered</strong> body)
|
||||
refute post_html =~ "**Rendered** body"
|
||||
|
||||
assert "pagefind/index.json" in relative_paths
|
||||
assert "pagefind/pagefind-ui.js" in relative_paths
|
||||
|
||||
@@ -134,7 +134,7 @@ defmodule BDS.PreviewTest do
|
||||
Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Draft Post",
|
||||
content: "Draft preview body",
|
||||
content: "**Draft** preview body",
|
||||
language: "en",
|
||||
template_slug: published_template.slug
|
||||
})
|
||||
@@ -146,7 +146,29 @@ defmodule BDS.PreviewTest do
|
||||
|
||||
assert draft_html =~ "preview-template"
|
||||
assert draft_html =~ "Draft Post"
|
||||
assert draft_html =~ "Draft preview body"
|
||||
assert draft_html =~ ~s(<strong>Draft</strong> preview body)
|
||||
refute draft_html =~ "**Draft** preview body"
|
||||
|
||||
assert {:ok, published_post} = Posts.publish_post(post.id)
|
||||
|
||||
published_datetime = DateTime.from_unix!(published_post.created_at, :millisecond)
|
||||
published_path =
|
||||
"/#{published_datetime.year}/#{String.pad_leading(Integer.to_string(published_datetime.month), 2, "0")}/#{String.pad_leading(Integer.to_string(published_datetime.day), 2, "0")}/#{published_post.slug}"
|
||||
|
||||
:inets.start()
|
||||
|
||||
assert {:ok, server} = BDS.Preview.start_preview(project.id)
|
||||
|
||||
assert {:ok, {{_version, 200, _reason}, _headers, published_html}} =
|
||||
:httpc.request(
|
||||
:get,
|
||||
{to_charlist("http://#{server.host}:#{server.port}#{published_path}?draft=true&post_id=#{published_post.id}"), []},
|
||||
[],
|
||||
body_format: :binary
|
||||
)
|
||||
|
||||
assert published_html =~ ~s(<strong>Draft</strong> preview body)
|
||||
refute published_html =~ "**Draft** preview body"
|
||||
|
||||
assert :ok = BDS.Preview.stop_preview(project.id)
|
||||
end
|
||||
|
||||
@@ -311,6 +311,59 @@ defmodule BDS.RenderingTest do
|
||||
assert rendered =~ "range=1711843200-1711929600"
|
||||
end
|
||||
|
||||
test "render_post_page falls back to bundled starter template when the published default template file is missing", %{
|
||||
project: project
|
||||
} do
|
||||
assert {:ok, _metadata} =
|
||||
BDS.Metadata.update_project_metadata(project.id, %{
|
||||
public_url: "https://example.com/blog",
|
||||
main_language: "en",
|
||||
blog_languages: ["en"]
|
||||
})
|
||||
|
||||
assert {:ok, template} =
|
||||
BDS.Templates.create_template(%{
|
||||
project_id: project.id,
|
||||
title: "Broken Default Post Template",
|
||||
kind: :post,
|
||||
content: "this custom template should not be used"
|
||||
})
|
||||
|
||||
assert {:ok, published_template} = BDS.Templates.publish_template(template.id)
|
||||
|
||||
BDS.Repo.update_all(
|
||||
from(template in BDS.Templates.Template,
|
||||
where: template.id == ^published_template.id
|
||||
),
|
||||
set: [slug: "single-post", file_path: "templates/single-post.liquid", content: nil]
|
||||
)
|
||||
|
||||
assert {:ok, post} =
|
||||
BDS.Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Fallback Body",
|
||||
content: "**Rendered** body",
|
||||
language: "en"
|
||||
})
|
||||
|
||||
assert {:ok, published_post} = BDS.Posts.publish_post(post.id)
|
||||
|
||||
assert {:ok, rendered} =
|
||||
Rendering.render_post_page(project.id, nil, %{
|
||||
id: published_post.id,
|
||||
title: published_post.title,
|
||||
content: BDS.Posts.editor_body(published_post),
|
||||
slug: published_post.slug,
|
||||
language: published_post.language,
|
||||
excerpt: published_post.excerpt,
|
||||
template_slug: published_post.template_slug
|
||||
})
|
||||
|
||||
assert rendered =~ ~s(data-template="single-post")
|
||||
assert rendered =~ ~s(<strong>Rendered</strong> body)
|
||||
refute rendered =~ "this custom template should not be used"
|
||||
end
|
||||
|
||||
defp canonical_post_href(post) do
|
||||
datetime = DateTime.from_unix!(post.created_at, :millisecond)
|
||||
|
||||
|
||||
@@ -263,4 +263,32 @@ defmodule BDS.TemplatesTest do
|
||||
assert template.created_at == 101
|
||||
assert template.updated_at == 202
|
||||
end
|
||||
|
||||
test "rebuild_templates_from_files removes stale published default templates when no local template files exist", %{
|
||||
project: project
|
||||
} do
|
||||
now = BDS.Persistence.now_ms()
|
||||
|
||||
stale_template =
|
||||
%BDS.Templates.Template{}
|
||||
|> BDS.Templates.Template.changeset(%{
|
||||
id: Ecto.UUID.generate(),
|
||||
project_id: project.id,
|
||||
slug: "single-post",
|
||||
title: "Single Post",
|
||||
kind: :post,
|
||||
enabled: true,
|
||||
version: 1,
|
||||
file_path: "templates/single-post.liquid",
|
||||
status: :published,
|
||||
content: nil,
|
||||
created_at: now,
|
||||
updated_at: now
|
||||
})
|
||||
|> Repo.insert!()
|
||||
|
||||
assert {:ok, templates} = BDS.Templates.rebuild_templates_from_files(project.id)
|
||||
assert templates == []
|
||||
assert Repo.get(BDS.Templates.Template, stale_template.id) == nil
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user