From a395a5b710673a53ace7d5dc0bf0d7b06ca88da8 Mon Sep 17 00:00:00 2001 From: stephann <3025661+stephannv@users.noreply.github.com> Date: Mon, 14 Jul 2025 20:41:48 -0300 Subject: [PATCH] Improve tests --- .../html/attributes_handling_spec.cr | 12 +++++++++++ ...ration_spec.cr => custom_elements_spec.cr} | 21 +++++++++++++++++-- spec/blueprint/html/svg_spec.cr | 8 +++++-- src/blueprint/html/svg.cr | 2 +- 4 files changed, 38 insertions(+), 5 deletions(-) rename spec/blueprint/html/{custom_elements_registration_spec.cr => custom_elements_spec.cr} (67%) diff --git a/spec/blueprint/html/attributes_handling_spec.cr b/spec/blueprint/html/attributes_handling_spec.cr index 6c0e00a..eab94d2 100644 --- a/spec/blueprint/html/attributes_handling_spec.cr +++ b/spec/blueprint/html/attributes_handling_spec.cr @@ -55,6 +55,18 @@ describe "attributes handling" do actual_html.should eq expected_html end + it "doesn't render nil attributes" do + actual_html = Blueprint::HTML.build do + div class: nil, data: {id: nil} + end + + expected_html = normalize_html <<-HTML +
+ HTML + + actual_html.should eq expected_html + end + it "expands NamedTuple attributes" do actual_html = Blueprint::HTML.build do nav aria: {target: "#home", selected: "false", enabled: true, hidden: false} do diff --git a/spec/blueprint/html/custom_elements_registration_spec.cr b/spec/blueprint/html/custom_elements_spec.cr similarity index 67% rename from spec/blueprint/html/custom_elements_registration_spec.cr rename to spec/blueprint/html/custom_elements_spec.cr index 067e884..2fbe53f 100644 --- a/spec/blueprint/html/custom_elements_registration_spec.cr +++ b/spec/blueprint/html/custom_elements_spec.cr @@ -11,8 +11,25 @@ private class Example end end -describe "custom elements registration" do - it "allows custom elements definition" do +describe "custom elements" do + it "allows custom elements rendering" do + actual_html = Blueprint::HTML.build do + element :foo, class: "bar", data: {tmp: true} do + "Hello" + end + + void_element :portal, class: "my-portal" + end + + expected_html = normalize_html <<-HTML + Hello + + HTML + + actual_html.should eq expected_html + end + + it "allows custom elements registration" do actual_html = Example.new.to_s do |example| example.v_btn(href: "#home", data: {id: 12, visible: true, disabled: false}) { "Home" } end diff --git a/spec/blueprint/html/svg_spec.cr b/spec/blueprint/html/svg_spec.cr index 0f8126c..8be3412 100644 --- a/spec/blueprint/html/svg_spec.cr +++ b/spec/blueprint/html/svg_spec.cr @@ -33,7 +33,9 @@ describe "SVG" do it "defines all SVG element helper methods" do actual_html = Blueprint::HTML.build do - svg do + svg + + svg viewBox: "0 0 100 100" do {% for element in ELEMENTS %} {{element.id}} {{element.id}}(attribute: "test") @@ -44,7 +46,9 @@ describe "SVG" do end expected_html = String.build do |io| - io << "" + io << "" + + io << %() ELEMENTS.each do |tag| io << "<" << tag << ">" << "" io << "<" << tag << " attribute=\"test\">" << "" diff --git a/src/blueprint/html/svg.cr b/src/blueprint/html/svg.cr index d0acc7e..ed80691 100644 --- a/src/blueprint/html/svg.cr +++ b/src/blueprint/html/svg.cr @@ -13,7 +13,7 @@ struct Blueprint::HTML::SVG(T) end private def blueprint(&) : Nil - element :svg, **@attributes do + svg **@attributes do yield end end