X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/8d76be71bbb8a799cbf0627dee170f26ade5a11f..HEAD:/test/helpers/browse_tags_helper_test.rb diff --git a/test/helpers/browse_tags_helper_test.rb b/test/helpers/browse_tags_helper_test.rb index 3aa851ef9..9bd11f052 100644 --- a/test/helpers/browse_tags_helper_test.rb +++ b/test/helpers/browse_tags_helper_test.rb @@ -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'Amigo", html + html = format_value("phone", "+1234567890") assert_dom_equal "+1234567890", html @@ -45,7 +54,18 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_dom_equal "File:Test.jpg", html html = format_value("colour", "#f00") - assert_dom_equal %(#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("email", "foo@example.com") + assert_dom_equal "foo@example.com", html + + html = format_value("source", "https://example.com") + assert_dom_equal "https://example.com", html + + html = format_value("source", "https://example.com;hello;https://example.net") + assert_dom_equal "https://example.com;hello;https://example.net", html end def test_wiki_link @@ -120,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") @@ -157,31 +186,43 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_equal "Test", link[:title] link = wikipedia_link("wikipedia", "de:Test") - assert_equal "https://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url] + assert_equal "https://de.wikipedia.org/wiki/Test?uselang=en", link[:url] assert_equal "de:Test", link[:title] + link = wikipedia_link("wikipedia:fr", "Portsea") + assert_equal "https://fr.wikipedia.org/wiki/Portsea?uselang=en", link[:url] + assert_equal "Portsea", link[:title] + link = wikipedia_link("wikipedia:fr", "de:Test") - assert_equal "https://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url] + assert_equal "https://de.wikipedia.org/wiki/Test?uselang=en", link[:url] assert_equal "de:Test", link[:title] link = wikipedia_link("wikipedia", "de:Englischer Garten (München)#Japanisches Teehaus") - assert_equal "https://de.wikipedia.org/wiki/de:Englischer Garten (München)?uselang=en#Japanisches_Teehaus", link[:url] + assert_equal "https://de.wikipedia.org/wiki/Englischer_Garten_%28M%C3%BCnchen%29?uselang=en#Japanisches_Teehaus", link[:url] assert_equal "de:Englischer Garten (München)#Japanisches Teehaus", link[:title] link = wikipedia_link("wikipedia", "de:Alte Brücke (Heidelberg)#Brückenaffe") - assert_equal "https://de.wikipedia.org/wiki/de:Alte Brücke (Heidelberg)?uselang=en#Br.C3.BCckenaffe", link[:url] + assert_equal "https://de.wikipedia.org/wiki/Alte_Br%C3%BCcke_%28Heidelberg%29?uselang=en#Br%C3%BCckenaffe", link[:url] assert_equal "de:Alte Brücke (Heidelberg)#Brückenaffe", link[:title] link = wikipedia_link("wikipedia", "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus") - assert_equal "https://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] + assert_equal "https://de.wikipedia.org/wiki/Liste_der_Baudenkm%C3%A4ler_in_Eichst%C3%A4tt?uselang=en#Br%C3%BCckenstra%C3%9Fe_1%2C_Ehemaliges_Bauernhaus", link[:url] assert_equal "de:Liste der Baudenkmäler in Eichstätt#Brückenstraße 1, Ehemaliges Bauernhaus", link[:title] + link = wikipedia_link("wikipedia", "en:Are Years What? (for Marianne Moore)") + assert_equal "https://en.wikipedia.org/wiki/Are_Years_What%3F_%28for_Marianne_Moore%29?uselang=en", link[:url] + assert_equal "en:Are Years What? (for Marianne Moore)", link[:title] + I18n.with_locale "pt-BR" do link = wikipedia_link("wikipedia", "zh-classical:Test#Section") - assert_equal "https://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url] + assert_equal "https://zh-classical.wikipedia.org/wiki/Test?uselang=pt-BR#Section", link[:url] assert_equal "zh-classical:Test#Section", link[:title] end + link = wikipedia_link("subject:wikipedia", "en:Catherine McAuley") + assert_equal "https://en.wikipedia.org/wiki/Catherine_McAuley?uselang=en", link[:url] + assert_equal "en:Catherine McAuley", link[:title] + link = wikipedia_link("foo", "Test") assert_nil link end @@ -240,29 +281,29 @@ class BrowseTagsHelperTest < ActionView::TestCase assert_nil email email = email_link("email", "x@example.com") - assert_equal "x@example.com", email[:email] - assert_equal "mailto:x@example.com", email[:url] + assert_equal "x@example.com", email email = email_link("email", "other.email-with-hyphen@example.com") - assert_equal "other.email-with-hyphen@example.com", email[:email] - assert_equal "mailto:other.email-with-hyphen@example.com", email[:url] + assert_equal "other.email-with-hyphen@example.com", email email = email_link("email", "user.name+tag+sorting@example.com") - assert_equal "user.name+tag+sorting@example.com", email[:email] - assert_equal "mailto:user.name+tag+sorting@example.com", email[:url] + assert_equal "user.name+tag+sorting@example.com", email email = email_link("email", "dash-in@both-parts.com") - assert_equal "dash-in@both-parts.com", email[:email] - assert_equal "mailto:dash-in@both-parts.com", email[:url] + assert_equal "dash-in@both-parts.com", email email = email_link("email", "example@s.example") - assert_equal "example@s.example", email[:email] - assert_equal "mailto:example@s.example", email[:url] + assert_equal "example@s.example", email # Strips whitespace at ends email = email_link("email", " test@email.com ") - assert_equal "test@email.com", email[:email] - assert_equal "mailto:test@email.com", email[:url] + 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