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_wikidata_link
140 link = wikidata_link("foo", "Test")
143 link = wikidata_link("wikidata", "http://www.wikidata.org/wiki/Q1")
146 link = wikidata_link("wikidata", "en:Q1")
149 link = wikidata_link("wikidata", "1")
152 link = wikidata_link("wikidata", "Q0123")
155 link = wikidata_link("wikidata", "Q42")
156 assert_equal "//www.wikidata.org/wiki/Q42?uselang=en", link[:url]
157 assert_equal "Q42", link[:title]
159 I18n.locale = "zh-CN"
161 link = wikidata_link("wikidata", "Q1234")
162 assert_equal "//www.wikidata.org/wiki/Q1234?uselang=zh-CN", link[:url]
163 assert_equal "Q1234", link[:title]
166 def test_wikipedia_link
167 link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
170 link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
173 link = wikipedia_link("wikipedia", "Test")
174 assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
175 assert_equal "Test", link[:title]
177 link = wikipedia_link("wikipedia", "de:Test")
178 assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
179 assert_equal "de:Test", link[:title]
181 link = wikipedia_link("wikipedia:fr", "de:Test")
182 assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
183 assert_equal "de:Test", link[:title]
185 I18n.locale = "pt-BR"
187 link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
188 assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
189 assert_equal "zh-classical:Test#Section", link[:title]
191 link = wikipedia_link("foo", "Test")
195 def test_telephone_link
196 link = telephone_link("foo", "Test")
199 link = telephone_link("phone", "+123")
202 link = telephone_link("phone", "123")
205 link = telephone_link("phone", "123 abcdefg")
208 link = telephone_link("phone", "+1234567890 abc")
211 link = telephone_link("phone", "+1234567890; +22334455667788")
214 link = telephone_link("phone", "1234567890")
217 link = telephone_link("phone", "+1234567890")
218 assert_equal "tel:+1234567890", link
220 link = telephone_link("phone", "+1234-567-890")
221 assert_equal "tel:+1234-567-890", link
223 link = telephone_link("phone", "+1234/567/890")
224 assert_equal "tel:+1234/567/890", link
226 link = telephone_link("phone", "+1234.567.890")
227 assert_equal "tel:+1234.567.890", link
229 link = telephone_link("phone", " +1234 567-890 ")
230 assert_equal "tel:+1234567-890", link
232 link = telephone_link("phone", "+1 234-567-890")
233 assert_equal "tel:+1234-567-890", link
235 link = telephone_link("phone", "+1 (234) 567-890")
236 assert_equal "tel:+1(234)567-890", link