feat: some refactoring to make shell_live smaller

This commit is contained in:
2026-04-26 15:39:04 +02:00
parent 92fde24aa1
commit 5aefa7ae41
10 changed files with 1727 additions and 570 deletions

View File

@@ -560,6 +560,99 @@ defmodule BDS.Desktop.ShellLiveTest do
assert html =~ ~s(class="task-list") or html =~ "No background tasks running"
end
test "post tabs render a real editor and drive save publish discard flows", %{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"
})
assert html =~ ~s(data-testid="post-editor")
assert html =~ ~s(data-testid="post-editor-form")
assert html =~ ~s(name="post_editor[title]")
assert html =~ ~s(name="post_editor[content]")
assert html =~ ~s(name="post_editor[excerpt]")
assert html =~ ~s(data-testid="post-publish-button")
assert html =~ ~s(data-testid="post-discard-button")
refute html =~ "Desktop workbench content routed through the Elixir shell."
html =
view
|> form("[data-testid='post-editor-form']", %{
post_editor: %{
title: "Updated Shell Post",
content: "Updated body",
excerpt: "Updated excerpt",
tags: "alpha, beta",
categories: "notes, guides",
author: "Ada Lovelace",
language: "de",
do_not_translate: "false",
template_slug: ""
}
})
|> render_change()
assert html =~ ~s(class="tab active dirty")
assert html =~ "Updated Shell Post"
_html = render_click(view, "save_post_editor", %{"id" => post.id})
saved_post = Posts.get_post!(post.id)
assert saved_post.title == "Updated Shell Post"
assert saved_post.content == "Updated body"
assert saved_post.excerpt == "Updated excerpt"
assert saved_post.tags == ["alpha", "beta"]
assert saved_post.categories == ["notes", "guides"]
assert saved_post.author == "Ada Lovelace"
assert saved_post.language == "de"
html = render_click(view, "publish_post_editor", %{"id" => post.id})
assert html =~ ~s(data-testid="post-status-badge")
assert Posts.get_post!(post.id).status == :published
_html =
view
|> form("[data-testid='post-editor-form']", %{
post_editor: %{
title: "Published Shell Post",
content: "Draft changes after publish",
excerpt: "Changed after publish",
tags: "alpha, beta",
categories: "notes, guides",
author: "Ada Lovelace",
language: "de",
do_not_translate: "false",
template_slug: ""
}
})
|> render_change()
_html = render_click(view, "save_post_editor", %{"id" => post.id})
assert Posts.get_post!(post.id).status == :draft
html = render_click(view, "discard_post_editor", %{"id" => post.id})
discarded_post = Posts.get_post!(post.id)
assert html =~ "Updated Shell Post"
assert discarded_post.status == :published
assert discarded_post.content == nil
assert discarded_post.title == "Updated Shell Post"
end
defp seed_sidebar_posts(project_id) do
now = Persistence.now_ms()

View File

@@ -274,19 +274,22 @@ defmodule BDS.UI.ShellTest do
css = File.read!("/Users/gb/Projects/bDS2/priv/ui/app.css")
live_ex = File.read!("/Users/gb/Projects/bDS2/lib/bds/desktop/shell_live.ex")
template = File.read!("/Users/gb/Projects/bDS2/lib/bds/desktop/shell_live/index.html.heex")
overlay_ex = File.read!("/Users/gb/Projects/bDS2/lib/bds/desktop/shell_live/overlay_components.ex")
overlay_template = File.read!("/Users/gb/Projects/bDS2/lib/bds/desktop/shell_live/overlay_html/shell_overlay.html.heex")
assert template =~ "render_editor_toolbar(assigns)"
assert template =~ "render_shell_overlay(assigns)"
assert template =~ "<ShellOverlayComponents.shell_overlay"
assert live_ex =~ ~s(def handle_event("open_overlay")
assert live_ex =~ ~s(def handle_event("close_overlay")
assert live_ex =~ ~s(def handle_event("overlay_keydown")
assert live_ex =~ "ai-suggestions-modal"
assert live_ex =~ "confirm-delete-modal"
assert live_ex =~ "insert-modal"
assert live_ex =~ "language-picker-modal"
assert live_ex =~ "gallery-overlay"
assert live_ex =~ "lightbox-overlay"
assert overlay_ex =~ "def context(assigns, tab_title, tab_subtitle)"
assert overlay_template =~ "ai-suggestions-modal"
assert overlay_template =~ "confirm-delete-modal"
assert overlay_template =~ "insert-modal"
assert overlay_template =~ "language-picker-modal"
assert overlay_template =~ "gallery-overlay"
assert overlay_template =~ "lightbox-overlay"
assert css =~ ".shell-overlay-backdrop"
assert css =~ ".ai-suggestions-modal-backdrop"