fix: more work on site validation
This commit is contained in:
@@ -94,6 +94,8 @@ defmodule BDS.Desktop.ShellCommandsTest do
|
||||
completed = wait_for_task(result.task_id, &(&1.status == :completed and is_map(&1.result)))
|
||||
|
||||
assert completed.group_name == "Validation"
|
||||
assert is_binary(completed.message)
|
||||
assert String.starts_with?(completed.message, "Validation complete (")
|
||||
assert completed.result.kind == "open_editor"
|
||||
assert completed.result.route == "site_validation"
|
||||
assert is_map(completed.result.payload.summary)
|
||||
|
||||
@@ -89,7 +89,7 @@ defmodule BDS.DesktopTest do
|
||||
assert menu_item(groups, :toggle_assistant_sidebar).native_label == "Toggle Assistant Sidebar\tCTRL+\\"
|
||||
assert menu_item(groups, :publish_selected).native_label == "Publish Selected\tCTRL+SHIFT+P"
|
||||
assert menu_item(groups, :preview_post).native_label == "Preview Post\tCTRL+SHIFT+V"
|
||||
assert menu_item(groups, :generate_sitemap).native_label == "Generate Sitemap\tCTRL+R"
|
||||
assert menu_item(groups, :generate_sitemap).native_label == "Generate Site\tCTRL+R"
|
||||
assert menu_item(groups, :validate_site).native_label == "Validate Site\tCTRL+SHIFT+L"
|
||||
assert menu_item(groups, :upload_site).native_label == "Upload Site\tCTRL+SHIFT+U"
|
||||
assert menu_item(groups, :metadata_diff).shortcut == nil
|
||||
|
||||
@@ -2,6 +2,7 @@ defmodule BDS.GenerationTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
import Ecto.Query
|
||||
import ExUnit.CaptureIO
|
||||
|
||||
alias BDS.Media
|
||||
alias BDS.Metadata
|
||||
@@ -352,6 +353,116 @@ defmodule BDS.GenerationTest do
|
||||
assert post_html =~ "Language"
|
||||
end
|
||||
|
||||
test "validate_site does not crash on unknown macros with quoted params", %{
|
||||
project: project
|
||||
} do
|
||||
assert {:ok, _metadata} =
|
||||
Metadata.update_project_metadata(project.id, %{
|
||||
public_url: "https://example.com/blog",
|
||||
main_language: "en",
|
||||
blog_languages: ["en"]
|
||||
})
|
||||
|
||||
assert {:ok, post} =
|
||||
Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Gallery Macro Post",
|
||||
content: "[[gallery link=\"file\"]]",
|
||||
language: "en"
|
||||
})
|
||||
|
||||
assert {:ok, _published_post} = Posts.publish_post(post.id)
|
||||
assert {:ok, _result} = BDS.Generation.generate_site(project.id, [:core, :single])
|
||||
|
||||
assert {:ok, report} = BDS.Generation.validate_site(project.id, [:core, :single])
|
||||
assert report.missing_url_paths == []
|
||||
assert report.extra_url_paths == []
|
||||
end
|
||||
|
||||
test "validate_site reports old-app phase progress", %{project: project} do
|
||||
assert {:ok, _metadata} =
|
||||
Metadata.update_project_metadata(project.id, %{
|
||||
public_url: "https://example.com/blog",
|
||||
main_language: "en",
|
||||
blog_languages: ["en"]
|
||||
})
|
||||
|
||||
assert {:ok, post} =
|
||||
Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Progress Post",
|
||||
content: "Progress body",
|
||||
language: "en"
|
||||
})
|
||||
|
||||
assert {:ok, _published_post} = Posts.publish_post(post.id)
|
||||
|
||||
parent = self()
|
||||
|
||||
on_progress = fn value, message ->
|
||||
send(parent, {:validate_progress, value, message})
|
||||
end
|
||||
|
||||
assert {:ok, _report} =
|
||||
BDS.Generation.validate_site(project.id, [:core, :single], on_progress: on_progress)
|
||||
|
||||
events = collect_validate_progress_events()
|
||||
|
||||
assert {0.0, "Collecting sitemap URLs..."} in events
|
||||
assert Enum.any?(events, fn
|
||||
{value, message}
|
||||
when is_number(value) and value > 0.0 and value < 0.5 and
|
||||
is_binary(message) ->
|
||||
String.starts_with?(message, "Collecting sitemap URLs")
|
||||
|
||||
_other ->
|
||||
false
|
||||
end)
|
||||
|
||||
assert {0.5, "Comparing sitemap to html pages..."} in events
|
||||
assert Enum.any?(events, fn
|
||||
{value, message}
|
||||
when is_number(value) and value > 0.5 and value < 1.0 and is_binary(message) ->
|
||||
String.starts_with?(message, "Comparing sitemap to html pages")
|
||||
|
||||
_other ->
|
||||
false
|
||||
end)
|
||||
|
||||
assert Enum.any?(events, fn
|
||||
{1.0, message} -> String.starts_with?(message, "Validation complete (")
|
||||
_other -> false
|
||||
end)
|
||||
end
|
||||
|
||||
test "validate_site does not emit markdown parser warnings for unclosed fenced blocks", %{
|
||||
project: project
|
||||
} do
|
||||
assert {:ok, _metadata} =
|
||||
Metadata.update_project_metadata(project.id, %{
|
||||
public_url: "https://example.com/blog",
|
||||
main_language: "en",
|
||||
blog_languages: ["en"]
|
||||
})
|
||||
|
||||
assert {:ok, post} =
|
||||
Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Malformed Markdown",
|
||||
content: "```elixir\nIO.puts(:broken)",
|
||||
language: "en"
|
||||
})
|
||||
|
||||
assert {:ok, _published_post} = Posts.publish_post(post.id)
|
||||
|
||||
stderr =
|
||||
capture_io(:stderr, fn ->
|
||||
assert {:ok, _report} = BDS.Generation.validate_site(project.id, [:core, :single])
|
||||
end)
|
||||
|
||||
assert stderr == ""
|
||||
end
|
||||
|
||||
test "generation falls back to bundled default templates when the project has no template files or template rows",
|
||||
%{project: project, temp_dir: temp_dir} do
|
||||
File.rm_rf!(Path.join(temp_dir, "templates"))
|
||||
@@ -891,4 +1002,13 @@ defmodule BDS.GenerationTest do
|
||||
"/" <> cleaned
|
||||
end
|
||||
end
|
||||
|
||||
defp collect_validate_progress_events(acc \\ []) do
|
||||
receive do
|
||||
{:validate_progress, value, message} ->
|
||||
collect_validate_progress_events([{value, message} | acc])
|
||||
after
|
||||
0 -> Enum.reverse(acc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user