Skip to content

Commit

Permalink
Create SVG standard elements test
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Sep 18, 2024
1 parent 7334470 commit 646757e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions quickdraw/svg/standard_elements.test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

Phlex::SVG::StandardElements.__registered_elements__.each do |method_name, tag|
test "<#{tag}> called with an underscore prefix while overridden" do
example = Class.new(Phlex::SVG) do
define_method :view_template do
__send__("_#{method_name}")
end

define_method method_name do
super(class: "overridden")
end
end

expect(example.call) == %(<#{tag}></#{tag}>)
end

test "<#{tag}> with block text content and attributes" do
example = Class.new(Phlex::SVG) do
define_method :view_template do
__send__(method_name, class: "class", id: "id", disabled: true, selected: false) { "content" }
end
end

expect(example.call) == %(<#{tag} class="class" id="id" disabled>content</#{tag}>)
end

test "<#{tag}> with string attribute keys" do
example = Class.new(Phlex::SVG) do
define_method :view_template do
__send__(method_name, "attribute_with_underscore" => true) { "content" }
end
end

expect(example.call) == %(<#{tag} attribute_with_underscore>content</#{tag}>)
end

test "<#{tag}> with hash attribute values" do
example = Class.new(Phlex::SVG) do
define_method :view_template do
__send__(method_name, aria: { hidden: true }, data_turbo: { frame: "_top" }) { "content" }
end
end

expect(example.call) == %(<#{tag} aria-hidden data-turbo-frame="_top">content</#{tag}>)
end
end

0 comments on commit 646757e

Please sign in to comment.