Add more tests for BrowseHelper
This commit is contained in:
parent
733108588c
commit
0de7fdb4df
10 changed files with 244 additions and 6 deletions
|
@ -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)
|
||||
|
|
24
test/fixtures/current_node_tags.yml
vendored
24
test/fixtures/current_node_tags.yml
vendored
|
@ -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'
|
||||
|
|
9
test/fixtures/current_nodes.yml
vendored
9
test/fixtures/current_nodes.yml
vendored
|
@ -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
|
||||
|
|
59
test/fixtures/node_tags.yml
vendored
59
test/fixtures/node_tags.yml
vendored
|
@ -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
|
||||
|
|
21
test/fixtures/nodes.yml
vendored
21
test/fixtures/nodes.yml
vendored
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue