404 and 500 drafts

This commit is contained in:
2026-11-06 15:42:52 +01:00
parent b17f346b25
commit 785e403370
14 changed files with 335 additions and 95 deletions
@@ -1,15 +1,37 @@
defmodule ChesstrainerWeb.ErrorHTMLTest do
use ChesstrainerWeb.ConnCase, async: true
use ExUnit.Case, async: true
# Bring render_to_string/4 for testing custom views
import Phoenix.Template, only: [render_to_string: 4]
alias Chesstrainer.Branding
alias ChesstrainerWeb.ErrorHTML
test "renders 404.html" do
assert render_to_string(ChesstrainerWeb.ErrorHTML, "404", "html", []) == "Not Found"
defp render(template) do
Phoenix.Template.render_to_string(ErrorHTML, template, "html", %{current_scope: nil})
end
test "renders 500.html" do
assert render_to_string(ChesstrainerWeb.ErrorHTML, "500", "html", []) ==
"Internal Server Error"
test "404 renders a complete document with the site chrome" do
html = render("404")
assert html =~ "<!DOCTYPE html>"
assert html =~ "<title>#{Branding.title("Page not found")}</title>"
assert html =~ ~s(class="error-code">404</span>)
assert html =~ "The page you were looking for moved"
assert html =~ "Browse puzzles"
assert html =~ ~s(class="site-footer")
assert html =~ "/assets/js/marketing.js"
refute html =~ ~s(name="csrf-token")
end
test "500 renders a complete document and the support address" do
html = render("500")
assert html =~ "<title>#{Branding.title("Something went wrong")}</title>"
assert html =~ ~s(class="error-code">500</span>)
assert html =~ "An unexpected error stopped this page"
assert html =~ Branding.support_email()
assert html =~ ~s(class="site-footer")
end
test "unknown statuses fall back to the plain status message" do
assert ErrorHTML.render("503.html", %{}) == "Service Unavailable"
end
end