]> git.openstreetmap.org Git - rails.git/blob - test/helpers/svg_helper_test.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / test / helpers / svg_helper_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class SvgHelperTest < ActionView::TestCase
6   def test_legend_fill
7     svg = legend_svg_tag("width" => 60, "height" => 40, "fill" => "green")
8     expected = <<~HTML.gsub(/\n\s*/, "")
9       <svg width="60" height="40">
10         <rect width="100%" height="100%" fill="green" />
11       </svg>
12     HTML
13     assert_dom_equal expected, svg
14   end
15
16   def test_legend_border
17     svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red")
18     expected = <<~HTML.gsub(/\n\s*/, "")
19       <svg width="60" height="40">
20         <rect x="0.5" y="0.5" width="59" height="39" fill="none" stroke="red" />
21       </svg>
22     HTML
23     assert_dom_equal expected, svg
24   end
25
26   def test_legend_border_width
27     svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 3)
28     expected = <<~HTML.gsub(/\n\s*/, "")
29       <svg width="60" height="40">
30         <rect x="1.5" y="1.5" width="57" height="37" fill="none" stroke="red" stroke-width="3" />
31       </svg>
32     HTML
33     assert_dom_equal expected, svg
34   end
35
36   def test_legend_border_with_integer_coords
37     svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 2)
38     expected = <<~HTML.gsub(/\n\s*/, "")
39       <svg width="60" height="40">
40         <rect x="1" y="1" width="58" height="38" fill="none" stroke="red" stroke-width="2" />
41       </svg>
42     HTML
43     assert_dom_equal expected, svg
44   end
45
46   def test_legend_border_fractional_width
47     svg = legend_svg_tag("width" => 60, "height" => 40, "border" => "red", "border-width" => 1.5)
48     expected = <<~HTML.gsub(/\n\s*/, "")
49       <svg width="60" height="40">
50         <rect x="0.75" y="0.75" width="58.5" height="38.5" fill="none" stroke="red" stroke-width="1.5" />
51       </svg>
52     HTML
53     assert_dom_equal expected, svg
54   end
55
56   def test_legend_line
57     svg = legend_svg_tag("width" => 80, "height" => 15, "line" => "blue")
58     expected = <<~HTML.gsub(/\n\s*/, "")
59       <svg width="80" height="15">
60         <path d="M0,7.5 H80" stroke="blue" />
61       </svg>
62     HTML
63     assert_dom_equal expected, svg
64   end
65
66   def test_legend_line_width
67     svg = legend_svg_tag("width" => 80, "height" => 15, "line" => "blue", "line-width" => 3)
68     expected = <<~HTML.gsub(/\n\s*/, "")
69       <svg width="80" height="15">
70         <path d="M0,7.5 H80" stroke="blue" stroke-width="3" />
71       </svg>
72     HTML
73     assert_dom_equal expected, svg
74   end
75
76   def test_legend_line_with_integer_coords
77     svg = legend_svg_tag("width" => 80, "height" => 20, "line" => "blue")
78     expected = <<~HTML.gsub(/\n\s*/, "")
79       <svg width="80" height="20">
80         <path d="M0,10 H80" stroke="blue" />
81       </svg>
82     HTML
83     assert_dom_equal expected, svg
84   end
85
86   def test_legend_casing
87     svg = legend_svg_tag("width" => 80, "height" => 20, "casing" => "yellow")
88     expected = <<~HTML.gsub(/\n\s*/, "")
89       <svg width="80" height="20">
90         <path d="M0,0.5 H80 M0,19.5 H80" stroke="yellow" />
91       </svg>
92     HTML
93     assert_dom_equal expected, svg
94   end
95
96   def test_legend_casing_width
97     svg = legend_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 5)
98     expected = <<~HTML.gsub(/\n\s*/, "")
99       <svg width="80" height="20">
100         <path d="M0,2.5 H80 M0,17.5 H80" stroke="yellow" stroke-width="5" />
101       </svg>
102     HTML
103     assert_dom_equal expected, svg
104   end
105
106   def test_legend_casing_with_integer_coords
107     svg = legend_svg_tag("width" => 80, "height" => 20, "casing" => "yellow", "casing-width" => 2)
108     expected = <<~HTML.gsub(/\n\s*/, "")
109       <svg width="80" height="20">
110         <path d="M0,1 H80 M0,19 H80" stroke="yellow" stroke-width="2" />
111       </svg>
112     HTML
113     assert_dom_equal expected, svg
114   end
115 end