1 # -*- coding: utf-8 -*-
5 class BrowseHelperTest < ActionView::TestCase
7 include ApplicationHelper
15 def test_printable_name
16 assert_equal "17", printable_name(current_nodes(:redacted_node))
17 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
18 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
19 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
20 assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
21 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
25 assert_equal "17", printable_name(current_nodes(:redacted_node))
26 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
27 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
28 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
29 assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
30 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
34 assert_equal "17", printable_name(current_nodes(:redacted_node))
35 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
36 assert_equal "<bdi>проверки узла</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
37 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
38 assert_equal "<bdi>проверки узла</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
39 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
43 assert_equal "17", printable_name(current_nodes(:redacted_node))
44 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
45 assert_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
46 assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
47 assert_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
48 assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
52 assert_equal "node", link_class("node", current_nodes(:visible_node))
53 assert_equal "node deleted", link_class("node", current_nodes(:invisible_node))
54 assert_equal "node deleted", link_class("node", current_nodes(:redacted_node))
55 assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name))
56 assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version))
57 assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version))
61 assert_equal "", link_title(current_nodes(:visible_node))
62 assert_equal "", link_title(current_nodes(:invisible_node))
63 assert_equal "", link_title(current_nodes(:redacted_node))
64 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name))
65 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version))
66 assert_equal "", link_title(nodes(:node_with_name_redacted_version))
70 html = format_key("highway")
71 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
73 html = format_key("unknown")
74 assert_equal "unknown", html
78 html = format_value("highway", "primary")
79 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
81 html = format_value("highway", "unknown")
82 assert_equal "unknown", html
84 html = format_value("unknown", "unknown")
85 assert_equal "unknown", html
87 html = format_value("phone", "+1234567890")
88 assert_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
92 tags = icon_tags(current_nodes(:node_with_name))
93 assert_equal 3, tags.count
94 assert tags.include?(["building", "yes"])
95 assert tags.include?(["tourism", "museum"])
96 assert tags.include?(["shop", "gift"])
98 tags = icon_tags(nodes(:node_with_name_current_version))
99 assert_equal 3, tags.count
100 assert tags.include?(["building", "yes"])
101 assert tags.include?(["tourism", "museum"])
102 assert tags.include?(["shop", "gift"])
104 tags = icon_tags(nodes(:node_with_name_redacted_version))
105 assert_equal 3, tags.count
106 assert tags.include?(["building", "yes"])
107 assert tags.include?(["tourism", "museum"])
108 assert tags.include?(["shop", "gift"])
112 link = wiki_link("key", "highway")
113 assert_equal "http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en", link
115 link = wiki_link("tag", "highway=primary")
116 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
120 link = wiki_link("key", "highway")
121 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
123 link = wiki_link("tag", "highway=primary")
124 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
128 link = wiki_link("key", "highway")
129 assert_equal "http://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link
131 link = wiki_link("tag", "highway=primary")
132 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
135 def test_wikidata_link
136 link = wikidata_link("foo", "Test")
139 link = wikidata_link("wikidata", "http://www.wikidata.org/wiki/Q1")
142 link = wikidata_link("wikidata", "en:Q1")
145 link = wikidata_link("wikidata", "1")
148 link = wikidata_link("wikidata", "Q0123")
151 link = wikidata_link("wikidata", "Q42")
152 assert_equal "//www.wikidata.org/wiki/Q42?uselang=en", link[:url]
153 assert_equal "Q42", link[:title]
155 I18n.locale = "zh-CN"
157 link = wikidata_link("wikidata", "Q1234")
158 assert_equal "//www.wikidata.org/wiki/Q1234?uselang=zh-CN", link[:url]
159 assert_equal "Q1234", link[:title]
162 def test_wikipedia_link
163 link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
166 link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
169 link = wikipedia_link("wikipedia", "Test")
170 assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
171 assert_equal "Test", link[:title]
173 link = wikipedia_link("wikipedia", "de:Test")
174 assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
175 assert_equal "de:Test", link[:title]
177 link = wikipedia_link("wikipedia:fr", "de:Test")
178 assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
179 assert_equal "de:Test", link[:title]
181 I18n.locale = "pt-BR"
183 link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
184 assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
185 assert_equal "zh-classical:Test#Section", link[:title]
187 link = wikipedia_link("foo", "Test")
191 def test_telephone_link
192 link = telephone_link("foo", "Test")
195 link = telephone_link("phone", "+123")
198 link = telephone_link("phone", "123")
201 link = telephone_link("phone", "123 abcdefg")
204 link = telephone_link("phone", "+1234567890 abc")
207 link = telephone_link("phone", "+1234567890; +22334455667788")
210 link = telephone_link("phone", "1234567890")
213 link = telephone_link("phone", "+1234567890")
214 assert_equal "tel:+1234567890", link
216 link = telephone_link("phone", "+1234-567-890")
217 assert_equal "tel:+1234-567-890", link
219 link = telephone_link("phone", "+1234/567/890")
220 assert_equal "tel:+1234/567/890", link
222 link = telephone_link("phone", "+1234.567.890")
223 assert_equal "tel:+1234.567.890", link
225 link = telephone_link("phone", " +1234 567-890 ")
226 assert_equal "tel:+1234567-890", link
228 link = telephone_link("phone", "+1 234-567-890")
229 assert_equal "tel:+1234-567-890", link
231 link = telephone_link("phone", "+1 (234) 567-890")
232 assert_equal "tel:+1(234)567-890", link