1 # -*- coding: utf-8 -*-
5 class BrowseHelperTest < ActionView::TestCase
7 include ApplicationHelper
19 def test_printable_name
20 assert_equal "17", printable_name(current_nodes(:redacted_node))
21 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
22 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
23 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
24 assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
25 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
29 assert_equal "17", printable_name(current_nodes(:redacted_node))
30 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
31 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
32 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
33 assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
34 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
38 assert_equal "17", printable_name(current_nodes(:redacted_node))
39 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
40 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
41 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
42 assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
43 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
47 assert_equal "17", printable_name(current_nodes(:redacted_node))
48 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
49 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
50 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
51 assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
52 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
56 assert_equal "node", link_class("node", current_nodes(:visible_node))
57 assert_equal "node deleted", link_class("node", current_nodes(:invisible_node))
58 assert_equal "node deleted", link_class("node", current_nodes(:redacted_node))
59 assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name))
60 assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version))
61 assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version))
65 assert_equal "", link_title(current_nodes(:visible_node))
66 assert_equal "", link_title(current_nodes(:invisible_node))
67 assert_equal "", link_title(current_nodes(:redacted_node))
68 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name))
69 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version))
70 assert_equal "", link_title(nodes(:node_with_name_redacted_version))
74 html = format_key("highway")
75 assert_equal "<a href=\"http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en\" title=\"The wiki description page for the highway tag\">highway</a>", html
77 html = format_key("unknown")
78 assert_equal "unknown", html
82 html = format_value("highway", "primary")
83 assert_equal "<a href=\"http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en\" title=\"The wiki description page for the highway=primary tag\">primary</a>", html
85 html = format_value("highway", "unknown")
86 assert_equal "unknown", html
88 html = format_value("unknown", "unknown")
89 assert_equal "unknown", html
91 html = format_value("phone", "+1234567890")
92 assert_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
96 tags = icon_tags(current_nodes(:node_with_name))
97 assert_equal 3, tags.count
98 assert tags.include?(["building", "yes"])
99 assert tags.include?(["tourism", "museum"])
100 assert tags.include?(["shop", "gift"])
102 tags = icon_tags(nodes(:node_with_name_current_version))
103 assert_equal 3, tags.count
104 assert tags.include?(["building", "yes"])
105 assert tags.include?(["tourism", "museum"])
106 assert tags.include?(["shop", "gift"])
108 tags = icon_tags(nodes(:node_with_name_redacted_version))
109 assert_equal 3, tags.count
110 assert tags.include?(["building", "yes"])
111 assert tags.include?(["tourism", "museum"])
112 assert tags.include?(["shop", "gift"])
116 link = wiki_link("key", "highway")
117 assert_equal "http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en", link
119 link = wiki_link("tag", "highway=primary")
120 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
124 link = wiki_link("key", "highway")
125 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
127 link = wiki_link("tag", "highway=primary")
128 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
132 link = wiki_link("key", "highway")
133 assert_equal "http://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link
135 link = wiki_link("tag", "highway=primary")
136 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
139 def test_wikipedia_link
140 link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
143 link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
146 link = wikipedia_link("wikipedia", "Test")
147 assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
148 assert_equal "Test", link[:title]
150 link = wikipedia_link("wikipedia", "de:Test")
151 assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
152 assert_equal "de:Test", link[:title]
154 link = wikipedia_link("wikipedia:fr", "de:Test")
155 assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
156 assert_equal "de:Test", link[:title]
158 I18n.locale = "pt-BR"
160 link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
161 assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
162 assert_equal "zh-classical:Test#Section", link[:title]
164 link = wikipedia_link("foo", "Test")
168 def test_telephone_link
169 link = telephone_link("foo", "Test")
172 link = telephone_link("phone", "+123")
175 link = telephone_link("phone", "123")
178 link = telephone_link("phone", "123 abcdefg")
181 link = telephone_link("phone", "+1234567890 abc")
184 link = telephone_link("phone", "+1234567890; +22334455667788")
187 link = telephone_link("phone", "1234567890")
190 link = telephone_link("phone", "+1234567890")
191 assert_equal "tel:+1234567890", link
193 link = telephone_link("phone", "+1234-567-890")
194 assert_equal "tel:+1234-567-890", link
196 link = telephone_link("phone", "+1234/567/890")
197 assert_equal "tel:+1234/567/890", link
199 link = telephone_link("phone", "+1234.567.890")
200 assert_equal "tel:+1234.567.890", link
202 link = telephone_link("phone", " +1234 567-890 ")
203 assert_equal "tel:+1234567-890", link
205 link = telephone_link("phone", "+1 234-567-890")
206 assert_equal "tel:+1234-567-890", link
208 link = telephone_link("phone", "+1 (234) 567-890")
209 assert_equal "tel:+1(234)567-890", link