1 # -*- coding: utf-8 -*-
5 class BrowseHelperTest < ActionView::TestCase
7 include ApplicationHelper
19 def test_printable_name
20 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
21 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
22 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
23 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
24 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
25 assert_dom_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
29 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
30 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
31 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
32 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
33 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
34 assert_dom_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
38 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
39 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
40 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
41 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
42 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
43 assert_dom_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
47 assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
48 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
49 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
50 assert_dom_equal "18", printable_name(nodes(:node_with_name_redacted_version))
51 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18, v2</bdi>)", printable_name(nodes(:node_with_name_current_version), true)
52 assert_dom_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_dom_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_dom_equal "unknown", html
82 html = format_value("highway", "primary")
83 assert_dom_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_dom_equal "unknown", html
88 html = format_value("unknown", "unknown")
89 assert_dom_equal "unknown", html
91 html = format_value("phone", "+1234567890")
92 assert_dom_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
94 html = format_value("wikipedia", "Test")
95 assert_dom_equal "<a title=\"The Test article on Wikipedia\" href=\"http://en.wikipedia.org/wiki/Test?uselang=en\">Test</a>", html
97 html = format_value("wikidata", "Q42")
98 assert_dom_equal "<a title=\"The Q42 item on Wikidata\" href=\"//www.wikidata.org/wiki/Q42?uselang=en\">Q42</a>", html
102 tags = icon_tags(current_nodes(:node_with_name))
103 assert_equal 3, tags.count
104 assert tags.include?(%w(building yes))
105 assert tags.include?(%w(tourism museum))
106 assert tags.include?(%w(shop gift))
108 tags = icon_tags(nodes(:node_with_name_current_version))
109 assert_equal 3, tags.count
110 assert tags.include?(%w(building yes))
111 assert tags.include?(%w(tourism museum))
112 assert tags.include?(%w(shop gift))
114 tags = icon_tags(nodes(:node_with_name_redacted_version))
115 assert_equal 3, tags.count
116 assert tags.include?(%w(building yes))
117 assert tags.include?(%w(tourism museum))
118 assert tags.include?(%w(shop gift))
122 link = wiki_link("key", "highway")
123 assert_equal "http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en", link
125 link = wiki_link("tag", "highway=primary")
126 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
130 link = wiki_link("key", "highway")
131 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
133 link = wiki_link("tag", "highway=primary")
134 assert_equal "http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
138 link = wiki_link("key", "highway")
139 assert_equal "http://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link
141 link = wiki_link("tag", "highway=primary")
142 assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
145 def test_wikidata_link
146 link = wikidata_link("foo", "Test")
149 link = wikidata_link("wikidata", "http://www.wikidata.org/wiki/Q1")
152 link = wikidata_link("wikidata", "en:Q1")
155 link = wikidata_link("wikidata", "1")
158 link = wikidata_link("wikidata", "Q0123")
161 link = wikidata_link("wikidata", "Q42")
162 assert_equal "//www.wikidata.org/wiki/Q42?uselang=en", link[:url]
163 assert_equal "Q42", link[:title]
165 I18n.locale = "zh-CN"
167 link = wikidata_link("wikidata", "Q1234")
168 assert_equal "//www.wikidata.org/wiki/Q1234?uselang=zh-CN", link[:url]
169 assert_equal "Q1234", link[:title]
172 def test_wikipedia_link
173 link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
176 link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
179 link = wikipedia_link("wikipedia", "Test")
180 assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
181 assert_equal "Test", link[:title]
183 link = wikipedia_link("wikipedia", "de:Test")
184 assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
185 assert_equal "de:Test", link[:title]
187 link = wikipedia_link("wikipedia:fr", "de:Test")
188 assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
189 assert_equal "de:Test", link[:title]
191 link = wikipedia_link("wikipedia", "de:Englischer Garten (München)#Japanisches Teehaus")
192 assert_equal "http://de.wikipedia.org/wiki/de:Englischer Garten (München)?uselang=en#Japanisches_Teehaus", link[:url]
193 assert_equal "de:Englischer Garten (München)#Japanisches Teehaus", link[:title]
195 link = wikipedia_link("wikipedia", "de:Alte Brücke (Heidelberg)#Brückenaffe")
196 assert_equal "http://de.wikipedia.org/wiki/de:Alte Brücke (Heidelberg)?uselang=en#Br.C3.BCckenaffe", link[:url]
197 assert_equal "de:Alte Brücke (Heidelberg)#Brückenaffe", link[:title]
199 link = wikipedia_link("wikipedia", "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus")
200 assert_equal "http://de.wikipedia.org/wiki/de:Liste der Baudenkmäler in Eichstätt?uselang=en#Br.C3.BCckenstra.C3.9Fe_1.2C_Ehemaliges_Bauernhaus", link[:url]
201 assert_equal "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus", link[:title]
203 I18n.locale = "pt-BR"
205 link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
206 assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
207 assert_equal "zh-classical:Test#Section", link[:title]
209 link = wikipedia_link("foo", "Test")
213 def test_telephone_link
214 link = telephone_link("foo", "Test")
217 link = telephone_link("phone", "+123")
220 link = telephone_link("phone", "123")
223 link = telephone_link("phone", "123 abcdefg")
226 link = telephone_link("phone", "+1234567890 abc")
229 link = telephone_link("phone", "+1234567890; +22334455667788")
232 link = telephone_link("phone", "1234567890")
235 link = telephone_link("phone", "+1234567890")
236 assert_equal "tel:+1234567890", link
238 link = telephone_link("phone", "+1234-567-890")
239 assert_equal "tel:+1234-567-890", link
241 link = telephone_link("phone", "+1234/567/890")
242 assert_equal "tel:+1234/567/890", link
244 link = telephone_link("phone", "+1234.567.890")
245 assert_equal "tel:+1234.567.890", link
247 link = telephone_link("phone", " +1234 567-890 ")
248 assert_equal "tel:+1234567-890", link
250 link = telephone_link("phone", "+1 234-567-890")
251 assert_equal "tel:+1234-567-890", link
253 link = telephone_link("phone", "+1 (234) 567-890")
254 assert_equal "tel:+1(234)567-890", link