defmodule ToweropsWeb.ErrorHTMLTest do
use ToweropsWeb.ConnCase, async: true
# Bring render_to_string/4 for testing custom views
import Phoenix.Template, only: [render_to_string: 4]
test "renders 404.html" do
html = render_to_string(ToweropsWeb.ErrorHTML, "404", "html", [])
assert html =~ "404"
assert html =~ "Oops, a squirrel must have eaten that wire!"
assert html =~ "/images/squirrel.jpg"
end
test "renders 500.html" do
html = render_to_string(ToweropsWeb.ErrorHTML, "500", "html", [])
assert html =~ "500"
assert html =~ "Something went wrong"
end
test "renders fallback status message for unknown templates" do
# Test the fallback render/2 function for error codes without custom templates
result = ToweropsWeb.ErrorHTML.render("503.html", %{})
assert result == "Service Unavailable"
result = ToweropsWeb.ErrorHTML.render("401.html", %{})
assert result == "Unauthorized"
result = ToweropsWeb.ErrorHTML.render("403.html", %{})
assert result == "Forbidden"
end
end