3 class BrowseHelperTest < ActionView::TestCase
5 include ApplicationHelper
7 def test_printable_name
8 node = create(:node, :with_history, :version => 2)
9 node_v1 = node.old_nodes.find_by(:version => 1)
10 node_v2 = node.old_nodes.find_by(:version => 2)
11 node_v1.redact!(create(:redaction))
13 add_tags_selection(node)
14 add_old_tags_selection(node_v2)
15 add_old_tags_selection(node_v1)
17 node_with_ref_without_name = create(:node)
18 create(:node_tag, :node => node_with_ref_without_name, :k => "ref", :v => "3.1415926")
20 deleted_node = create(:node, :deleted)
22 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
23 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
24 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
25 assert_dom_equal node.id.to_s, printable_name(node_v1)
26 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
27 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
28 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
30 I18n.with_locale "pt" do
31 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
32 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
33 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
34 assert_dom_equal node.id.to_s, printable_name(node_v1)
35 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
36 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
37 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
40 I18n.with_locale "pt-BR" do
41 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
42 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
43 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
44 assert_dom_equal node.id.to_s, printable_name(node_v1)
45 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
46 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
47 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
50 I18n.with_locale "de" do
51 assert_dom_equal deleted_node.id.to_s, printable_name(deleted_node)
52 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node)
53 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_name(node_v2)
54 assert_dom_equal node.id.to_s, printable_name(node_v1)
55 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}, v2</bdi>)", printable_name(node_v2, :version => true)
56 assert_dom_equal "#{node.id}, v1", printable_name(node_v1, :version => true)
57 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_name(node_with_ref_without_name)
61 def test_element_class
62 node = create(:node, :with_history, :version => 2)
63 node_v1 = node.old_nodes.find_by(:version => 1)
64 node_v2 = node.old_nodes.find_by(:version => 2)
65 node_v1.redact!(create(:redaction))
67 add_tags_selection(node)
68 add_old_tags_selection(node_v2)
69 add_old_tags_selection(node_v1)
71 assert_equal "node", element_class("node", create(:node))
72 assert_equal "node deleted", element_class("node", create(:node, :deleted))
74 assert_equal "node building yes shop gift tourism museum", element_class("node", node)
75 assert_equal "node building yes shop gift tourism museum", element_class("node", node_v2)
76 assert_equal "node deleted", element_class("node", node_v1)
80 node = create(:node, :with_history, :version => 2)
81 node_v1 = node.old_nodes.find_by(:version => 1)
82 node_v2 = node.old_nodes.find_by(:version => 2)
83 node_v1.redact!(create(:redaction))
85 add_tags_selection(node)
86 add_old_tags_selection(node_v2)
87 add_old_tags_selection(node_v1)
89 assert_equal "", link_title(create(:node))
90 assert_equal "", link_title(create(:node, :deleted))
92 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(node)
93 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(node_v2)
94 assert_equal "", link_title(node_v1)
98 node = create(:node, :with_history, :version => 2)
99 node_v1 = node.old_nodes.find_by(:version => 1)
100 node_v2 = node.old_nodes.find_by(:version => 2)
101 node_v1.redact!(create(:redaction))
103 add_tags_selection(node)
105 tags = icon_tags(node)
106 assert_equal 3, tags.count
107 assert_includes tags, %w[building yes]
108 assert_includes tags, %w[tourism museum]
109 assert_includes tags, %w[shop gift]
111 add_old_tags_selection(node_v2)
112 add_old_tags_selection(node_v1)
114 tags = icon_tags(node_v2)
115 assert_equal 3, tags.count
116 assert_includes tags, %w[building yes]
117 assert_includes tags, %w[tourism museum]
118 assert_includes tags, %w[shop gift]
120 tags = icon_tags(node_v1)
121 assert_equal 3, tags.count
122 assert_includes tags, %w[building yes]
123 assert_includes tags, %w[tourism museum]
124 assert_includes tags, %w[shop gift]
129 def add_old_tags_selection(old_node)
130 { "building" => "yes",
132 "tourism" => "museum",
133 "name" => "Test Node",
134 "name:pt" => "Nó teste" }.each do |key, value|
135 create(:old_node_tag, :old_node => old_node, :k => key, :v => value)
139 def add_tags_selection(node)
140 { "building" => "yes",
142 "tourism" => "museum",
143 "name" => "Test Node",
144 "name:pt" => "Nó teste" }.each do |key, value|
145 create(:node_tag, :node => node, :k => key, :v => value)
149 def preferred_languages
150 Locale.list(I18n.locale)