mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
404 and 500 drafts
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -263,4 +263,17 @@ defmodule ChesstrainerWeb.PageControllerTest do
|
||||
"/endgames"
|
||||
]
|
||||
end
|
||||
|
||||
test "unknown routes render the branded 404 page", %{conn: conn} do
|
||||
html = conn |> get("/this-page-does-not-exist") |> html_response(404)
|
||||
document = LazyHTML.from_document(html)
|
||||
|
||||
assert LazyHTML.text(LazyHTML.query(document, "title")) == Branding.title("Page not found")
|
||||
assert LazyHTML.text(LazyHTML.query(document, ".error-code")) == "404"
|
||||
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"
|
||||
assert html =~ ~s(name="robots")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user