mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-29 09:35:54 +00:00
66 lines
1.7 KiB
Ruby
66 lines
1.7 KiB
Ruby
require "test_helper"
|
|
|
|
class Pressa::Views::LayoutTest < Minitest::Test
|
|
def content_view
|
|
Class.new(Phlex::HTML) do
|
|
def view_template
|
|
article do
|
|
h1 { "Hello" }
|
|
end
|
|
end
|
|
end.new
|
|
end
|
|
|
|
def site
|
|
@site ||= Pressa::Site.new(
|
|
author: "Sami Samhuri",
|
|
email: "sami@samhuri.net",
|
|
title: "samhuri.net",
|
|
description: "blog",
|
|
url: "https://samhuri.net"
|
|
)
|
|
end
|
|
|
|
def test_rendering_child_components_as_html_instead_of_escaped_text
|
|
html = Pressa::Views::Layout.new(
|
|
site:,
|
|
canonical_url: "https://samhuri.net/posts/",
|
|
content: content_view
|
|
).call
|
|
|
|
assert_includes(html, "<article>")
|
|
assert_includes(html, "<h1>Hello</h1>")
|
|
refute_includes(html, "<article>")
|
|
end
|
|
|
|
def test_keeps_escaping_enabled_for_untrusted_string_fields
|
|
subtitle = "<img src=x onerror=alert(1)>"
|
|
html = Pressa::Views::Layout.new(
|
|
site:,
|
|
canonical_url: "https://samhuri.net/posts/",
|
|
page_subtitle: subtitle,
|
|
content: content_view
|
|
).call
|
|
|
|
assert_includes(html, "<title>samhuri.net: <img src=x onerror=alert(1)></title>")
|
|
end
|
|
|
|
def test_preserves_absolute_stylesheet_urls
|
|
cdn_site = Pressa::Site.new(
|
|
author: "Sami Samhuri",
|
|
email: "sami@samhuri.net",
|
|
title: "samhuri.net",
|
|
description: "blog",
|
|
url: "https://samhuri.net",
|
|
styles: [Pressa::Stylesheet.new(href: "https://cdn.example.com/site.css")]
|
|
)
|
|
|
|
html = Pressa::Views::Layout.new(
|
|
site: cdn_site,
|
|
canonical_url: "https://samhuri.net/posts/",
|
|
content: content_view
|
|
).call
|
|
|
|
assert_includes(html, %(<link rel="stylesheet" type="text/css" href="https://cdn.example.com/site.css">))
|
|
end
|
|
end
|