]> git.openstreetmap.org Git - rails.git/blobdiff - test/helpers/browse_tags_helper_test.rb
Merge remote-tracking branch 'upstream/pull/4832'
[rails.git] / test / helpers / browse_tags_helper_test.rb
index 3f36b921092618a45e1ea2625c33d025d4dba46c..f47c215c0e48dc14b2041ebe406d721901f0a0be 100644 (file)
@@ -22,6 +22,15 @@ class BrowseTagsHelperTest < ActionView::TestCase
     html = format_value("unknown", "unknown")
     assert_dom_equal "unknown", html
 
+    html = format_value("unknown", "abc;def")
+    assert_dom_equal "abc;def", html
+
+    html = format_value("unknown", "foo;")
+    assert_dom_equal "foo;", html
+
+    html = format_value("addr:street", "Rue de l'Amigo")
+    assert_dom_equal "Rue de l&#39;Amigo", html
+
     html = format_value("phone", "+1234567890")
     assert_dom_equal "<a href=\"tel:+1234567890\" title=\"Call +1234567890\">+1234567890</a>", html
 
@@ -45,10 +54,18 @@ class BrowseTagsHelperTest < ActionView::TestCase
     assert_dom_equal "<a title=\"The File:Test.jpg item on Wikimedia Commons\" href=\"//commons.wikimedia.org/wiki/File:Test.jpg?uselang=en\">File:Test.jpg</a>", html
 
     html = format_value("colour", "#f00")
-    assert_dom_equal %(<span class="colour-preview-box" data-colour="#f00" title="Colour #f00 preview"></span>#f00), html
+    dom = Rails::Dom::Testing.html_document_fragment.parse html
+    assert_select dom, "svg>rect>@fill", "#f00"
+    assert_match(/#f00$/, html)
 
-    html = format_value("contact", "foo@example.com")
+    html = format_value("email", "foo@example.com")
     assert_dom_equal "<a title=\"Email foo@example.com\" href=\"mailto:foo@example.com\">foo@example.com</a>", html
+
+    html = format_value("source", "https://example.com")
+    assert_dom_equal "<a href=\"https://example.com\" rel=\"nofollow\">https://example.com</a>", html
+
+    html = format_value("source", "https://example.com;hello;https://example.net")
+    assert_dom_equal "<a href=\"https://example.com\" rel=\"nofollow\">https://example.com</a>;hello;<a href=\"https://example.net\" rel=\"nofollow\">https://example.net</a>", html
   end
 
   def test_wiki_link
@@ -123,6 +140,15 @@ class BrowseTagsHelperTest < ActionView::TestCase
     assert_equal "//www.wikidata.org/entity/Q24?uselang=en", links[0][:url]
     assert_equal "Q24", links[0][:title]
 
+    # This verified buried is working
+    links = wikidata_links("buried:wikidata", "Q24")
+    assert_equal "//www.wikidata.org/entity/Q24?uselang=en", links[0][:url]
+    assert_equal "Q24", links[0][:title]
+
+    links = wikidata_links("species:wikidata", "Q26899")
+    assert_equal "//www.wikidata.org/entity/Q26899?uselang=en", links[0][:url]
+    assert_equal "Q26899", links[0][:title]
+
     # Another allowed key, this time with multiple values and I18n
     I18n.with_locale "dsb" do
       links = wikidata_links("brand:wikidata", "Q936;Q2013;Q1568346")
@@ -185,6 +211,10 @@ class BrowseTagsHelperTest < ActionView::TestCase
       assert_equal "zh-classical:Test#Section", link[:title]
     end
 
+    link = wikipedia_link("subject:wikipedia", "en:Catherine McAuley")
+    assert_equal "https://en.wikipedia.org/wiki/en:Catherine McAuley?uselang=en", link[:url]
+    assert_equal "en:Catherine McAuley", link[:title]
+
     link = wikipedia_link("foo", "Test")
     assert_nil link
   end
@@ -260,6 +290,12 @@ class BrowseTagsHelperTest < ActionView::TestCase
     # Strips whitespace at ends
     email = email_link("email", " test@email.com ")
     assert_equal "test@email.com", email
+
+    email = email_link("contact:email", "example@example.com")
+    assert_equal "example@example.com", email
+
+    email = email_link("maxweight:conditional", "none@agricultural")
+    assert_nil email
   end
 
   def test_telephone_links