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_strikethrough
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 normal_output = element_strikethrough(node_v2) { "test" }
68 assert_equal "test", normal_output
70 redacted_output = element_strikethrough(node_v1) { "test" }
71 assert_equal "<s>test</s>", redacted_output
73 deleted_output = element_strikethrough(create(:node, :deleted)) { "test" }
74 assert_equal "<s>test</s>", deleted_output
77 def test_element_class
78 node = create(:node, :with_history, :version => 2)
79 node_v1 = node.old_nodes.find_by(:version => 1)
80 node_v2 = node.old_nodes.find_by(:version => 2)
81 node_v1.redact!(create(:redaction))
83 add_tags_selection(node)
84 add_old_tags_selection(node_v2)
85 add_old_tags_selection(node_v1)
87 assert_equal "node", element_class("node", create(:node))
88 assert_equal "node", element_class("node", create(:node, :deleted))
90 assert_equal "node building yes shop gift tourism museum", element_class("node", node)
91 assert_equal "node building yes shop gift tourism museum", element_class("node", node_v2)
92 assert_equal "node", element_class("node", node_v1)
96 node = create(:node, :with_history, :version => 2)
97 node_v1 = node.old_nodes.find_by(:version => 1)
98 node_v2 = node.old_nodes.find_by(:version => 2)
99 node_v1.redact!(create(:redaction))
101 add_tags_selection(node)
102 add_old_tags_selection(node_v2)
103 add_old_tags_selection(node_v1)
105 assert_equal "", link_title(create(:node))
106 assert_equal "", link_title(create(:node, :deleted))
108 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(node)
109 assert_equal "building=yes, shop=gift, and tourism=museum", link_title(node_v2)
110 assert_equal "", link_title(node_v1)
114 node = create(:node, :with_history, :version => 2)
115 node_v1 = node.old_nodes.find_by(:version => 1)
116 node_v2 = node.old_nodes.find_by(:version => 2)
117 node_v1.redact!(create(:redaction))
119 add_tags_selection(node)
121 tags = icon_tags(node)
122 assert_equal 3, tags.count
123 assert_includes tags, %w[building yes]
124 assert_includes tags, %w[tourism museum]
125 assert_includes tags, %w[shop gift]
127 add_old_tags_selection(node_v2)
128 add_old_tags_selection(node_v1)
130 tags = icon_tags(node_v2)
131 assert_equal 3, tags.count
132 assert_includes tags, %w[building yes]
133 assert_includes tags, %w[tourism museum]
134 assert_includes tags, %w[shop gift]
136 tags = icon_tags(node_v1)
137 assert_equal 3, tags.count
138 assert_includes tags, %w[building yes]
139 assert_includes tags, %w[tourism museum]
140 assert_includes tags, %w[shop gift]
145 def add_old_tags_selection(old_node)
146 { "building" => "yes",
148 "tourism" => "museum",
149 "name" => "Test Node",
150 "name:pt" => "Nó teste" }.each do |key, value|
151 create(:old_node_tag, :old_node => old_node, :k => key, :v => value)
155 def add_tags_selection(node)
156 { "building" => "yes",
158 "tourism" => "museum",
159 "name" => "Test Node",
160 "name:pt" => "Nó teste" }.each do |key, value|
161 create(:node_tag, :node => node, :k => key, :v => value)
165 def preferred_languages
166 Locale.list(I18n.locale)