]> git.openstreetmap.org Git - rails.git/blob - test/helpers/svg_helper_test.rb
14c08539ca1f3d22a1728ecffbbe3b2cf42ed1da
[rails.git] / test / helpers / svg_helper_test.rb
1 require "test_helper"
2
3 class SvgHelperTest < ActionView::TestCase
4   def test_key_fill
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" />
9       </svg>
10     HTML
11     assert_dom_equal expected, svg
12   end
13
14   def test_key_border
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" />
19       </svg>
20     HTML
21     assert_dom_equal expected, svg
22   end
23
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" />
29       </svg>
30     HTML
31     assert_dom_equal expected, svg
32   end
33
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" />
39       </svg>
40     HTML
41     assert_dom_equal expected, svg
42   end
43
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" />
49       </svg>
50     HTML
51     assert_dom_equal expected, svg
52   end
53
54   def test_key_line
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" />
59       </svg>
60     HTML
61     assert_dom_equal expected, svg
62   end
63
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" />
69       </svg>
70     HTML
71     assert_dom_equal expected, svg
72   end
73
74   def test_key_casing
75     svg = key_svg_tag("width" => 80, "height" => 20, "casing" => "yellow")
76     expected = <<~HTML.gsub(/\n\s*/, "")
77       <svg width="80" height="20">
78         <g stroke="yellow">
79           <line x2="100%" y1="0.5" y2="0.5" />
80           <line x2="100%" y1="19.5" y2="19.5" />
81         </g>
82       </svg>
83     HTML
84     assert_dom_equal expected, svg
85   end
86
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" />
94         </g>
95       </svg>
96     HTML
97     assert_dom_equal expected, svg
98   end
99 end