Add more tests for BrowseHelper
authorTom Hughes <tom@compton.nu>
Sat, 1 Mar 2014 16:02:06 +0000 (16:02 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 1 Mar 2014 16:02:06 +0000 (16:02 +0000)
app/helpers/browse_helper.rb
test/fixtures/current_node_tags.yml
test/fixtures/current_nodes.yml
test/fixtures/node_tags.yml
test/fixtures/nodes.yml
test/helpers/browse_helper_test.rb
test/models/node_tag_test.rb
test/models/node_test.rb
test/models/old_node_tag_test.rb
test/models/old_node_test.rb

index 70f724cca5bd63abe1e6fab4546ddd830108f8f8..b192a63d558ee4c4ba8bd7e06dc815536168a1fa 100644 (file)
@@ -24,11 +24,16 @@ module BrowseHelper
   end
 
   def link_class(type, object)
+    classes = [ type ]
+
     if object.redacted?
-      type + " deleted"
+      classes << "deleted"
     else
-      type + " " + h(icon_tags(object).join(' ')) + (object.visible == false ? ' deleted' : '')
+      classes += icon_tags(object).flatten.map { |t| h(t) }
+      classes << "deleted" unless object.visible?
     end
+
+    classes.join(" ")
   end
 
   def link_title(object)
index 5087310e7dbd0953d21dc4d01e74282ab965ed10..9c41a375e4423d3673f0142bcf18e797ce2a9237 100644 (file)
@@ -33,3 +33,27 @@ public_v_t1:
   k: 'testvisible'
   v: 'yes'
 
+nwn_name:
+  node_id: 18
+  k: 'name'
+  v: 'Test Node'
+
+nwn_name_ru:
+  node_id: 18
+  k: 'name:ru'
+  v: 'проверки узла'
+
+nwn_building:
+  node_id: 18
+  k: 'building'
+  v: 'yes'
+
+nwn_tourism:
+  node_id: 18
+  k: 'tourism'
+  v: 'museum'
+
+nwn_shop:
+  node_id: 18
+  k: 'shop'
+  v: 'gift'
index 3f34ddabefac20d98112e619f1e5c58d86da7680..af6ea01d51384fa643b4fe2a3aa7d1eba5fc5c4a 100644 (file)
@@ -171,3 +171,12 @@ redacted_node:
   tile: <%= QuadTile.tile_for_point(1,1) %>
   timestamp: 2007-01-01 00:00:00
 
+node_with_name:
+  id: 18
+  latitude: <%= 1*SCALE %>
+  longitude: <%= 1*SCALE %>
+  changeset_id: 2
+  visible: true
+  version: 2
+  tile: <%= QuadTile.tile_for_point(1,1) %>
+  timestamp: 2007-01-01 00:00:00
index 6b908aa54c724c81717d8e7bdf34369f6a193bbf..21a63f5b12d061efa8613f20eef976ab3533ce82 100644 (file)
@@ -52,3 +52,62 @@ public_v_t1:
   v: 'yes'
   version: 1
 
+nwnv1_name:
+  node_id: 18
+  k: 'name'
+  v: 'Test Node'
+  version: 1
+
+nwnv1_name_ru:
+  node_id: 18
+  k: 'name:ru'
+  v: 'проверки узла'
+  version: 1
+
+nwnv1_building:
+  node_id: 18
+  k: 'building'
+  v: 'yes'
+  version: 1
+
+nwnv1_tourism:
+  node_id: 18
+  k: 'tourism'
+  v: 'museum'
+  version: 1
+
+nwnv1_shop:
+  node_id: 18
+  k: 'shop'
+  v: 'gift'
+  version: 1
+
+nwnv2_name:
+  node_id: 18
+  k: 'name'
+  v: 'Test Node'
+  version: 2
+
+nwnv2_name_ru:
+  node_id: 18
+  k: 'name:ru'
+  v: 'проверки узла'
+  version: 2
+
+nwnv2_building:
+  node_id: 18
+  k: 'building'
+  v: 'yes'
+  version: 2
+
+nwnv2_tourism:
+  node_id: 18
+  k: 'tourism'
+  v: 'museum'
+  version: 2
+
+nwnv2_shop:
+  node_id: 18
+  k: 'shop'
+  v: 'gift'
+  version: 2
index 5de3d94af0115072107ff0e333c6945109ff013b..7841c6e0eb6ac800230957f1e72e0ffbcbabcca2 100644 (file)
@@ -211,3 +211,24 @@ redacted_node_current_version:
   version: 2
   tile: <%= QuadTile.tile_for_point(1,1) %>
   timestamp: 2007-01-01 00:00:00
+
+node_with_name_redacted_version:
+  node_id: 18
+  latitude: <%= 1*SCALE %>
+  longitude: <%= 1*SCALE %>
+  changeset_id: 2
+  visible: true
+  version: 1
+  tile: <%= QuadTile.tile_for_point(1,1) %>
+  timestamp: 2007-01-01 00:00:00
+  redaction_id: 1
+
+node_with_name_current_version:
+  node_id: 18
+  latitude: <%= 1*SCALE %>
+  longitude: <%= 1*SCALE %>
+  changeset_id: 2
+  visible: true
+  version: 2
+  tile: <%= QuadTile.tile_for_point(1,1) %>
+  timestamp: 2007-01-01 00:00:00
index 0e734a756bc1e2c5dc7e6382d386b4d12cb14ea4..a48ac4df886504137f563e125df355c9a7118cec 100644 (file)
@@ -1,6 +1,125 @@
+# -*- coding: utf-8 -*-
+
 require 'test_helper'
 
 class BrowseHelperTest < ActionView::TestCase
+  include ERB::Util
+  include ApplicationHelper
+
+  api_fixtures
+
+  def setup
+    I18n.locale = "en"
+  end
+
+  def test_printable_name
+    assert_equal "17", printable_name(current_nodes(:redacted_node))
+    assert_equal "Test Node (18)", printable_name(current_nodes(:node_with_name))
+    assert_equal "Test Node (18)", printable_name(nodes(:node_with_name_current_version))
+    assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
+    assert_equal "Test Node (18, v2)", printable_name(nodes(:node_with_name_current_version), true)
+    assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
+
+    I18n.locale = "ru"
+
+    assert_equal "17", printable_name(current_nodes(:redacted_node))
+    assert_equal "проверки узла (18)", printable_name(current_nodes(:node_with_name))
+    assert_equal "проверки узла (18)", printable_name(nodes(:node_with_name_current_version))
+    assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
+    assert_equal "проверки узла (18, v2)", printable_name(nodes(:node_with_name_current_version), true)
+    assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
+
+    I18n.locale = "de"
+
+    assert_equal "17", printable_name(current_nodes(:redacted_node))
+    assert_equal "Test Node (18)", printable_name(current_nodes(:node_with_name))
+    assert_equal "Test Node (18)", printable_name(nodes(:node_with_name_current_version))
+    assert_equal "18", printable_name(nodes(:node_with_name_redacted_version))
+    assert_equal "Test Node (18, v2)", printable_name(nodes(:node_with_name_current_version), true)
+    assert_equal "18, v1", printable_name(nodes(:node_with_name_redacted_version), true)
+  end
+
+  def test_link_class
+    assert_equal "node", link_class("node", current_nodes(:visible_node))
+    assert_equal "node deleted", link_class("node", current_nodes(:invisible_node))
+    assert_equal "node deleted", link_class("node", current_nodes(:redacted_node))
+    assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name))
+    assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version))
+    assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version))
+  end
+
+  def test_link_title
+    assert_equal "", link_title(current_nodes(:visible_node))
+    assert_equal "", link_title(current_nodes(:invisible_node))
+    assert_equal "", link_title(current_nodes(:redacted_node))
+    assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name))
+    assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version))
+    assert_equal "", link_title(nodes(:node_with_name_redacted_version))
+  end
+
+  def test_format_key
+    html = format_key("highway")
+    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
+
+    html = format_key("unknown")
+    assert_equal "unknown", html
+  end
+
+  def test_format_value
+    html = format_value("highway", "primary")
+    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
+
+    html = format_value("highway", "unknown")
+    assert_equal "unknown", html
+
+    html = format_value("unknown", "unknown")
+    assert_equal "unknown", html
+  end
+
+  def test_icon_tags
+    tags = icon_tags(current_nodes(:node_with_name))
+    assert_equal 3, tags.count
+    assert tags.include?(["building", "yes"])
+    assert tags.include?(["tourism", "museum"])
+    assert tags.include?(["shop", "gift"])
+
+    tags = icon_tags(nodes(:node_with_name_current_version))
+    assert_equal 3, tags.count
+    assert tags.include?(["building", "yes"])
+    assert tags.include?(["tourism", "museum"])
+    assert tags.include?(["shop", "gift"])
+
+    tags = icon_tags(nodes(:node_with_name_redacted_version))
+    assert_equal 3, tags.count
+    assert tags.include?(["building", "yes"])
+    assert tags.include?(["tourism", "museum"])
+    assert tags.include?(["shop", "gift"])
+  end
+
+  def test_wiki_link
+    link = wiki_link("key", "highway")
+    assert_equal "http://wiki.openstreetmap.org/wiki/Key:highway?uselang=en", link
+
+    link = wiki_link("tag", "highway=primary")
+    assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=en", link
+
+    I18n.locale = "de"
+
+    link = wiki_link("key", "highway")
+    assert_equal "http://wiki.openstreetmap.org/wiki/DE:Key:highway?uselang=de", link
+
+    link = wiki_link("tag", "highway=primary")
+    assert_equal "http://wiki.openstreetmap.org/wiki/DE:Tag:highway=primary?uselang=de", link
+
+    I18n.locale = "tr"
+
+    link = wiki_link("key", "highway")
+    assert_equal "http://wiki.openstreetmap.org/wiki/Tr:Key:highway?uselang=tr", link
+
+    link = wiki_link("tag", "highway=primary")
+    assert_equal "http://wiki.openstreetmap.org/wiki/Tag:highway=primary?uselang=tr", link
+  end
+
   def test_wikipedia_link
     link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
     assert_nil link
@@ -21,6 +140,7 @@ class BrowseHelperTest < ActionView::TestCase
     assert_equal "de:Test", link[:title]
 
     I18n.locale = "pt-BR"
+
     link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
     assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
     assert_equal "zh-classical:Test#Section", link[:title]
index 61a61896ebe558856e57095f33a234e36f272fd6..aa50b2f39a5af83641a3c6fe398efa712a01fa66 100644 (file)
@@ -4,7 +4,7 @@ class NodeTagTest < ActiveSupport::TestCase
   api_fixtures
   
   def test_tag_count
-    assert_equal 7, NodeTag.count
+    assert_equal 12, NodeTag.count
     node_tag_count(:visible_node, 1)
     node_tag_count(:invisible_node, 1)
     node_tag_count(:used_node_1, 1)
index 5137cd9ef2695de57460a55415d546e4b64d08bd..f6f5be2966cd3d0f84f3846a08b9de1204b2e565 100644 (file)
@@ -4,7 +4,7 @@ class NodeTest < ActiveSupport::TestCase
   api_fixtures
   
   def test_node_count
-    assert_equal 17, Node.count
+    assert_equal 18, Node.count
   end
 
   def test_node_too_far_north
index 4984ea0cc2f59484aac65ebae0fa8532a7df044b..249b810a9fee0e3488a859ed53644b01960fb474 100644 (file)
@@ -4,7 +4,7 @@ class OldNodeTagTest < ActiveSupport::TestCase
   api_fixtures
 
   def test_old_node_tag_count
-    assert_equal 9, OldNodeTag.count, "Unexpected number of fixtures loaded."
+    assert_equal 19, OldNodeTag.count, "Unexpected number of fixtures loaded."
   end
   
   def test_length_key_valid
index 698e8cd7bfaacc94297404bdf9baf4256eca04e9..2ccf6d18c5dc6939c5de62a4dd203756aea3ea10 100644 (file)
@@ -4,7 +4,7 @@ class OldNodeTest < ActiveSupport::TestCase
   api_fixtures
   
   def test_node_count
-    assert_equal 21, OldNode.count
+    assert_equal 23, OldNode.count
   end
 
   def test_node_too_far_north