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" => 15, "line" => "blue")
56 expected = <<~HTML.gsub(/\n\s*/, "")
57 <svg width="80" height="15">
58 <path d="M0,7.5 H80" stroke="blue" />
61 assert_dom_equal expected, svg
64 def test_key_line_width
65 svg = key_svg_tag("width" => 80, "height" => 15, "line" => "blue", "line-width" => 3)
66 expected = <<~HTML.gsub(/\n\s*/, "")
67 <svg width="80" height="15">
68 <path d="M0,7.5 H80" stroke="blue" stroke-width="3" />
71 assert_dom_equal expected, svg
74 def test_key_line_with_integer_coords
75 svg = key_svg_tag("width" => 80, "height" => 20, "line" => "blue")
76 expected = <<~HTML.gsub(/\n\s*/, "")
77 <svg width="80" height="20">
78 <path d="M0,10 H80" stroke="blue" />
81 assert_dom_equal expected, svg
85 svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow")
86 expected = <<~HTML.gsub(/\n\s*/, "")
87 <svg width="80" height="20">
88 <path d="M0,0.5 H80 M0,19.5 H80" stroke="yellow" />
91 assert_dom_equal expected, svg
94 def test_key_casing_width
95 svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 5)
96 expected = <<~HTML.gsub(/\n\s*/, "")
97 <svg width="80" height="20">
98 <path d="M0,2.5 H80 M0,17.5 H80" stroke="yellow" stroke-width="5" />
101 assert_dom_equal expected, svg
104 def test_key_casing_with_integer_coords
105 svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 2)
106 expected = <<~HTML.gsub(/\n\s*/, "")
107 <svg width="80" height="20">
108 <path d="M0,1 H80 M0,19 H80" stroke="yellow" stroke-width="2" />
111 assert_dom_equal expected, svg