3 class BrowseHelperTest < ActionView::TestCase
5 include ApplicationHelper
7 def test_printable_element_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_element_name(deleted_node)
23 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node)
24 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node_v2)
25 assert_dom_equal node.id.to_s, printable_element_name(node_v1)
26 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_element_name(node_with_ref_without_name)
28 I18n.with_locale "pt" do
29 assert_dom_equal deleted_node.id.to_s, printable_element_name(deleted_node)
30 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node)
31 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node_v2)
32 assert_dom_equal node.id.to_s, printable_element_name(node_v1)
33 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_element_name(node_with_ref_without_name)
36 I18n.with_locale "pt-BR" do
37 assert_dom_equal deleted_node.id.to_s, printable_element_name(deleted_node)
38 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node)
39 assert_dom_equal "<bdi>Nó teste</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node_v2)
40 assert_dom_equal node.id.to_s, printable_element_name(node_v1)
41 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_element_name(node_with_ref_without_name)
44 I18n.with_locale "de" do
45 assert_dom_equal deleted_node.id.to_s, printable_element_name(deleted_node)
46 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node)
47 assert_dom_equal "<bdi>Test Node</bdi> (<bdi>#{node.id}</bdi>)", printable_element_name(node_v2)
48 assert_dom_equal node.id.to_s, printable_element_name(node_v1)
49 assert_dom_equal "<bdi>3.1415926</bdi> (<bdi>#{node_with_ref_without_name.id}</bdi>)", printable_element_name(node_with_ref_without_name)
53 def test_element_strikethrough
54 node = create(:node, :with_history, :version => 2)
55 node_v1 = node.old_nodes.find_by(:version => 1)
56 node_v2 = node.old_nodes.find_by(:version => 2)
57 node_v1.redact!(create(:redaction))
59 normal_output = element_strikethrough(node_v2) { "test" }
60 assert_equal "test", normal_output
62 redacted_output = element_strikethrough(node_v1) { "test" }
63 assert_equal "<s>test</s>", redacted_output
65 deleted_output = element_strikethrough(create(:node, :deleted)) { "test" }
66 assert_equal "<s>test</s>", deleted_output
69 def test_element_class
70 node = create(:node, :with_history, :version => 2)
71 node_v1 = node.old_nodes.find_by(:version => 1)
72 node_v2 = node.old_nodes.find_by(:version => 2)
73 node_v1.redact!(create(:redaction))
75 add_tags_selection(node)
76 add_old_tags_selection(node_v2)
77 add_old_tags_selection(node_v1)
79 assert_equal "node", element_class("node", create(:node))
80 assert_equal "node", element_class("node", create(:node, :deleted))
82 assert_equal "node building yes shop gift tourism museum", element_class("node", node)
83 assert_equal "node building yes shop gift tourism museum", element_class("node", node_v2)
84 assert_equal "node", element_class("node", node_v1)
87 def test_element_title
88 node = create(:node, :with_history, :version => 2)
89 node_v1 = node.old_nodes.find_by(:version => 1)
90 node_v2 = node.old_nodes.find_by(:version => 2)
91 node_v1.redact!(create(:redaction))
93 add_tags_selection(node)
94 add_old_tags_selection(node_v2)
95 add_old_tags_selection(node_v1)
97 assert_equal "", element_title(create(:node))
98 assert_equal "", element_title(create(:node, :deleted))
100 assert_equal "building=yes, shop=gift, and tourism=museum", element_title(node)
101 assert_equal "building=yes, shop=gift, and tourism=museum", element_title(node_v2)
102 assert_equal "", element_title(node_v1)
106 node = create(:node, :with_history, :version => 2)
107 node_v1 = node.old_nodes.find_by(:version => 1)
108 node_v2 = node.old_nodes.find_by(:version => 2)
109 node_v1.redact!(create(:redaction))
111 add_tags_selection(node)
113 tags = icon_tags(node)
114 assert_equal 3, tags.count
115 assert_includes tags, %w[building yes]
116 assert_includes tags, %w[tourism museum]
117 assert_includes tags, %w[shop gift]
119 add_old_tags_selection(node_v2)
120 add_old_tags_selection(node_v1)
122 tags = icon_tags(node_v2)
123 assert_equal 3, tags.count
124 assert_includes tags, %w[building yes]
125 assert_includes tags, %w[tourism museum]
126 assert_includes tags, %w[shop gift]
128 tags = icon_tags(node_v1)
129 assert_equal 3, tags.count
130 assert_includes tags, %w[building yes]
131 assert_includes tags, %w[tourism museum]
132 assert_includes tags, %w[shop gift]
137 def add_old_tags_selection(old_node)
138 { "building" => "yes",
140 "tourism" => "museum",
141 "name" => "Test Node",
142 "name:pt" => "Nó teste" }.each do |key, value|
143 create(:old_node_tag, :old_node => old_node, :k => key, :v => value)
147 def add_tags_selection(node)
148 { "building" => "yes",
150 "tourism" => "museum",
151 "name" => "Test Node",
152 "name:pt" => "Nó teste" }.each do |key, value|
153 create(:node_tag, :node => node, :k => key, :v => value)
157 def preferred_languages
158 Locale.list(I18n.locale)