fix: made menus more stable and verified and hooke up stuff that got lost

This commit is contained in:
2026-05-02 09:37:24 +02:00
parent 07fab7d1ab
commit 24f114c24e
8 changed files with 394 additions and 11 deletions

View File

@@ -19,6 +19,25 @@ defmodule BDS.BoundedAtomsTest do
assert BoundedAtoms.shell_command("toggle_panel") == :toggle_panel
end
test "accepts implemented blog menu shell commands" do
commands = [
{"preview_post", :preview_post},
{"rebuild_database", :rebuild_database},
{"reindex_text", :reindex_text},
{"rebuild_embedding_index", :rebuild_embedding_index},
{"metadata_diff", :metadata_diff},
{"validate_translations", :validate_translations},
{"find_duplicates", :find_duplicates},
{"generate_sitemap", :generate_sitemap},
{"validate_site", :validate_site},
{"upload_site", :upload_site}
]
for {value, expected} <- commands do
assert BoundedAtoms.shell_command(value) == expected
end
end
test "falls back without creating atoms for unknown strings" do
assert BoundedAtoms.sidebar_view("unknown", :posts) == :posts
assert BoundedAtoms.editor_route("unknown", :dashboard) == :dashboard

View File

@@ -733,6 +733,71 @@ defmodule BDS.Desktop.ShellLiveTest do
refute html =~ "Desktop workbench content routed through the Elixir shell."
end
test "native metadata diff action queues the maintenance task" do
:ok = BDS.Tasks.clear_finished()
{:ok, view, _html} = live_isolated(build_conn(), BDS.Desktop.ShellLive)
existing_ids = MapSet.new(Enum.map(BDS.Tasks.list_tasks(), & &1.id))
_html = render_hook(view, "native_menu_action", %{"action" => "metadata_diff"})
assert %{} = new_task!(existing_ids, "Metadata Diff")
end
test "native new post action reuses the sidebar create flow" do
count_before = Repo.aggregate(Post, :count, :id)
{:ok, view, _html} = live_isolated(build_conn(), BDS.Desktop.ShellLive)
_html = render_hook(view, "native_menu_action", %{"action" => "new_post"})
assert Repo.aggregate(Post, :count, :id) == count_before + 1
end
test "native save action persists the active post editor", %{project: project} do
{:ok, post} =
Posts.create_post(%{
project_id: project.id,
title: "Draft Shell Post",
content: "Initial body",
excerpt: "Initial excerpt"
})
{:ok, view, _html} = live_isolated(build_conn(), BDS.Desktop.ShellLive)
_html =
render_click(view, "pin_sidebar_item", %{
"route" => "post",
"id" => post.id,
"title" => post.title,
"subtitle" => "draft"
})
_html =
view
|> form("[data-testid='post-editor-form']", %{
post_editor: %{
title: "Saved Through Menu",
content: "Saved body",
excerpt: "Saved excerpt",
tags: "",
categories: "",
author: "",
language: "en",
do_not_translate: "false"
}
})
|> render_change()
_html = render_hook(view, "native_menu_action", %{"action" => "save"})
saved_post = Posts.get_post!(post.id)
assert saved_post.title == "Saved Through Menu"
assert saved_post.content == "Saved body"
assert saved_post.excerpt == "Saved excerpt"
end
test "menu editor adds a submenu, nests an entry, and saves the opml", %{
project: project,
temp_dir: temp_dir

View File

@@ -131,6 +131,24 @@ defmodule BDS.DesktopTest do
assert menu_item(groups, :metadata_diff).shortcut == nil
end
test "prod forwarded menu surface is covered by the shell dispatcher except unresolved filler action" do
forwarded_actions =
BDS.Desktop.MenuBar.groups(dev_mode?: false)
|> Enum.flat_map(fn group ->
group.items
|> Enum.reject(&Map.get(&1, :separator, false))
|> Enum.map(& &1.id)
end)
|> MapSet.new()
unsupported_actions =
forwarded_actions
|> MapSet.difference(BDS.Desktop.ShellLive.supported_menu_actions())
|> Enum.sort()
assert unsupported_actions == [:fill_missing_translations]
end
test "native menu quit requests app-owned shutdown" do
previous_module = Application.get_env(:bds, :desktop_shutdown_module)
previous_pid = Application.get_env(:bds, :desktop_shutdown_test_pid)