3 class SvgHelperTest < ActionView::TestCase
5 svg = key_svg_tag("width" => 60, "height" => 40, "fill" => "green")
6 expected = <<~HTML.gsub(/\n\s*/, "")
7 <svg width="60" height="40">
8 <rect width="100%" height="100%" fill="green" />
11 assert_dom_equal expected, svg
15 svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red")
16 expected = <<~HTML.gsub(/\n\s*/, "")
17 <svg width="60" height="40">
18 <rect x="0.5" y="0.5" width="59" height="39" fill="none" stroke="red" />
21 assert_dom_equal expected, svg
24 def test_key_border_width
25 svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 3)
26 expected = <<~HTML.gsub(/\n\s*/, "")
27 <svg width="60" height="40">
28 <rect x="1.5" y="1.5" width="57" height="37" fill="none" stroke="red" stroke-width="3" />
31 assert_dom_equal expected, svg
34 def test_key_border_with_integer_coords
35 svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 2)
36 expected = <<~HTML.gsub(/\n\s*/, "")
37 <svg width="60" height="40">
38 <rect x="1" y="1" width="58" height="38" fill="none" stroke="red" stroke-width="2" />
41 assert_dom_equal expected, svg
44 def test_key_border_fractional_width
45 svg = key_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 1.5)
46 expected = <<~HTML.gsub(/\n\s*/, "")
47 <svg width="60" height="40">
48 <rect x="0.75" y="0.75" width="58.5" height="38.5" fill="none" stroke="red" stroke-width="1.5" />
51 assert_dom_equal expected, svg
55 svg = key_svg_tag("width" => 80, "height" => 20, "line" => "blue")
56 expected = <<~HTML.gsub(/\n\s*/, "")
57 <svg width="80" height="20">
58 <line x2="100%" y1="50%" y2="50%" stroke="blue" />
61 assert_dom_equal expected, svg
64 def test_key_line_width
65 svg = key_svg_tag("width" => 80, "height" => 20, "line" => "blue", "line-width" => 3)
66 expected = <<~HTML.gsub(/\n\s*/, "")
67 <svg width="80" height="20">
68 <line x2="100%" y1="50%" y2="50%" stroke="blue" stroke-width="3" />
71 assert_dom_equal expected, svg
75 svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow")
76 expected = <<~HTML.gsub(/\n\s*/, "")
77 <svg width="80" height="20">
79 <line x2="100%" y1="0.5" y2="0.5" />
80 <line x2="100%" y1="19.5" y2="19.5" />
84 assert_dom_equal expected, svg
87 def test_key_casing_width
88 svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 5)
89 expected = <<~HTML.gsub(/\n\s*/, "")
90 <svg width="80" height="20">
91 <g stroke="yellow" stroke-width="5">
92 <line x2="100%" y1="2.5" y2="2.5" />
93 <line x2="100%" y1="17.5" y2="17.5" />
97 assert_dom_equal expected, svg