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
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 icon = element_icon("node", create(:node))
80 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
81 assert_dom icon_dom, "img:root", :count => 1 do
82 assert_dom "> @title", 0
85 icon = element_icon("node", create(:node, :deleted))
86 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
87 assert_dom icon_dom, "img:root", :count => 1 do
88 assert_dom "> @title", 0
91 icon = element_icon("node", node)
92 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
93 assert_dom icon_dom, "img:root", :count => 1 do
94 assert_dom "> @title", "building=yes, shop=gift, and tourism=museum"
97 icon = element_icon("node", node_v2)
98 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
99 assert_dom icon_dom, "img:root", :count => 1 do
100 assert_dom "> @title", "building=yes, shop=gift, and tourism=museum"
103 icon = element_icon("node", node_v1)
104 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
105 assert_dom icon_dom, "img:root", :count => 1 do
106 assert_dom "> @title", 0
112 def add_old_tags_selection(old_node)
113 { "building" => "yes",
115 "tourism" => "museum",
116 "name" => "Test Node",
117 "name:pt" => "Nó teste" }.each do |key, value|
118 create(:old_node_tag, :old_node => old_node, :k => key, :v => value)
122 def add_tags_selection(node)
123 { "building" => "yes",
125 "tourism" => "museum",
126 "name" => "Test Node",
127 "name:pt" => "Nó teste" }.each do |key, value|
128 create(:node_tag, :node => node, :k => key, :v => value)
132 def preferred_languages
133 Locale.list(I18n.locale)