From 0de7fdb4dfb3d70de5ad1fdff3578456ed94944b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 1 Mar 2014 16:02:06 +0000 Subject: [PATCH] Add more tests for BrowseHelper --- app/helpers/browse_helper.rb | 9 ++- test/fixtures/current_node_tags.yml | 24 ++++++ test/fixtures/current_nodes.yml | 9 +++ test/fixtures/node_tags.yml | 59 ++++++++++++++ test/fixtures/nodes.yml | 21 +++++ test/helpers/browse_helper_test.rb | 120 ++++++++++++++++++++++++++++ test/models/node_tag_test.rb | 2 +- test/models/node_test.rb | 2 +- test/models/old_node_tag_test.rb | 2 +- test/models/old_node_test.rb | 2 +- 10 files changed, 244 insertions(+), 6 deletions(-) diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 70f724cca..b192a63d5 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -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) diff --git a/test/fixtures/current_node_tags.yml b/test/fixtures/current_node_tags.yml index 5087310e7..9c41a375e 100644 --- a/test/fixtures/current_node_tags.yml +++ b/test/fixtures/current_node_tags.yml @@ -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' diff --git a/test/fixtures/current_nodes.yml b/test/fixtures/current_nodes.yml index 3f34ddabe..af6ea01d5 100644 --- a/test/fixtures/current_nodes.yml +++ b/test/fixtures/current_nodes.yml @@ -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 diff --git a/test/fixtures/node_tags.yml b/test/fixtures/node_tags.yml index 6b908aa54..21a63f5b1 100644 --- a/test/fixtures/node_tags.yml +++ b/test/fixtures/node_tags.yml @@ -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 diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index 5de3d94af..7841c6e0e 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml @@ -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 diff --git a/test/helpers/browse_helper_test.rb b/test/helpers/browse_helper_test.rb index 0e734a756..a48ac4df8 100644 --- a/test/helpers/browse_helper_test.rb +++ b/test/helpers/browse_helper_test.rb @@ -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 "highway", html + + html = format_key("unknown") + assert_equal "unknown", html + end + + def test_format_value + html = format_value("highway", "primary") + assert_equal "primary", 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] diff --git a/test/models/node_tag_test.rb b/test/models/node_tag_test.rb index 61a61896e..aa50b2f39 100644 --- a/test/models/node_tag_test.rb +++ b/test/models/node_tag_test.rb @@ -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) diff --git a/test/models/node_test.rb b/test/models/node_test.rb index 5137cd9ef..f6f5be296 100644 --- a/test/models/node_test.rb +++ b/test/models/node_test.rb @@ -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 diff --git a/test/models/old_node_tag_test.rb b/test/models/old_node_tag_test.rb index 4984ea0cc..249b810a9 100644 --- a/test/models/old_node_tag_test.rb +++ b/test/models/old_node_tag_test.rb @@ -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 diff --git a/test/models/old_node_test.rb b/test/models/old_node_test.rb index 698e8cd7b..2ccf6d18c 100644 --- a/test/models/old_node_test.rb +++ b/test/models/old_node_test.rb @@ -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 -- 2.43.2