feat: PLAN step 3 done

This commit is contained in:
2026-04-25 22:22:27 +02:00
parent 2b1aca4143
commit fac55bfb3b
7 changed files with 154 additions and 17 deletions

View File

@@ -104,6 +104,35 @@ defmodule BDS.PostsTest do
assert reopened.updated_at >= published.updated_at
end
test "update_post keeps published posts published and rewrites the file when only template_slug changes",
%{project: project, temp_dir: temp_dir} do
assert {:ok, post} =
BDS.Posts.create_post(%{
project_id: project.id,
title: "Template Rewrite",
content: "Body",
template_slug: "article"
})
assert {:ok, published} = BDS.Posts.publish_post(post.id)
full_path = Path.join(temp_dir, published.file_path)
original_contents = File.read!(full_path)
assert original_contents =~ "templateSlug: article\n"
assert {:ok, updated} =
BDS.Posts.update_post(post.id, %{template_slug: "landing-page"})
assert updated.status == :published
assert updated.template_slug == "landing-page"
assert updated.file_path == published.file_path
rewritten_contents = File.read!(full_path)
assert rewritten_contents =~ "templateSlug: landing-page\n"
refute rewritten_contents =~ "templateSlug: article\n"
end
test "publish_post writes frontmatter to the project data directory and clears draft content" do
temp_dir =
Path.join(System.tmp_dir!(), "bds-post-publish-#{System.unique_integer([:positive])}")

View File

@@ -351,8 +351,11 @@ defmodule BDS.UI.ShellTest do
assert js =~ "case \"1\""
assert js =~ "case \"2\""
assert js =~ "case \"\\\\\""
assert js =~ "case \"view_posts\""
assert js =~ "case \"view_media\""
assert js =~ "function isSidebarViewCommand(action)"
assert js =~ "function isSingletonEditorCommand(action)"
assert js =~ "action.startsWith(\"view_\")"
assert js =~ "action.startsWith(\"open_\")"
assert js =~ "openSingletonTab(action.slice(5));"
assert js =~ "executeBackendShellCommand(action)"
assert js =~ "case \"metadata_diff\""
assert js =~ "case \"regenerate_calendar\""

View File

@@ -1,6 +1,7 @@
defmodule BDS.UI.WorkbenchTest do
use ExUnit.Case, async: true
alias BDS.UI.Registry
alias BDS.UI.MenuBar
alias BDS.UI.Workbench
@@ -187,4 +188,39 @@ defmodule BDS.UI.WorkbenchTest do
assert state.panel.visible == true
assert state.active_view == :media
end
test "shared menu command routing covers every sidebar view and singleton editor route" do
sidebar_views = Registry.sidebar_views()
state =
Enum.reduce(sidebar_views, Workbench.new(sidebar_visible: false), fn view, acc ->
command = String.to_atom("view_#{view.id}")
next = MenuBar.execute(acc, command)
assert next.active_view == view.id
assert next.sidebar_visible == true
%{next | sidebar_visible: false}
end)
singleton_routes =
Registry.editor_routes()
|> Enum.filter(& &1.singleton)
|> Enum.reject(&(&1.id == :dashboard))
final_state =
Enum.reduce(singleton_routes, state, fn route, acc ->
command = String.to_atom("open_#{route.id}")
next = MenuBar.execute(acc, command)
assert next.active_tab == {route.id, Atom.to_string(route.id)}
assert next.editor_route == route.id
next
end)
assert Enum.any?(final_state.tabs, &(&1.type == :settings and &1.id == "settings"))
assert Enum.any?(final_state.tabs, &(&1.type == :menu_editor and &1.id == "menu_editor"))
assert Enum.any?(final_state.tabs, &(&1.type == :find_duplicates and &1.id == "find_duplicates"))
end
end