]> git.openstreetmap.org Git - rails.git/blob - test/helpers/svg_helper_test.rb
Localisation updates from https://translatewiki.net.
[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" => 15, "line" => "blue")
56     expected = <<~HTML.gsub(/\n\s*/, "")
57       <svg width="80" height="15">
58         <path d="M0,7.5 H80" 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" => 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" />
69       </svg>
70     HTML
71     assert_dom_equal expected, svg
72   end
73
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" />
79       </svg>
80     HTML
81     assert_dom_equal expected, svg
82   end
83
84   def test_key_casing
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" />
89       </svg>
90     HTML
91     assert_dom_equal expected, svg
92   end
93
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" />
99       </svg>
100     HTML
101     assert_dom_equal expected, svg
102   end
103
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" />
109       </svg>
110     HTML
111     assert_dom_equal expected, svg
112   end
113 end