]> git.openstreetmap.org Git - rails.git/blob - test/system/element_current_version_test.rb
Move node ui tests to system tests
[rails.git] / test / system / element_current_version_test.rb
1 require "application_system_test_case"
2
3 class ElementCurrentVersionTest < ApplicationSystemTestCase
4   test "shows a node with one version" do
5     node = create(:node, :lat => 60, :lon => 30)
6
7     visit node_path(node)
8
9     within_sidebar do
10       assert_css "h2", :text => "Node: #{node.id}"
11       within "h4", :text => "Version #1" do
12         assert_link "1", :href => old_node_path(node, 1)
13       end
14       assert_text(/Location: 60\.\d+, 30\.\d+/)
15       assert_no_text "Deleted"
16
17       assert_link "Download XML", :href => api_node_path(node)
18       assert_link "View History", :href => node_history_path(node)
19       assert_no_link "View Unredacted History"
20     end
21   end
22
23   test "shows a node with two versions" do
24     node = create(:node, :with_history, :lat => 60, :lon => 30, :version => 2)
25
26     visit node_path(node)
27
28     within_sidebar do
29       assert_css "h2", :text => "Node: #{node.id}"
30       within "h4", :text => "Version #2" do
31         assert_link "2", :href => old_node_path(node, 2)
32       end
33       assert_text(/Location: 60\.\d+, 30\.\d+/)
34       assert_no_text "Deleted"
35
36       assert_link "Download XML", :href => api_node_path(node)
37       assert_link "View History", :href => node_history_path(node)
38       assert_no_link "View Unredacted History"
39       assert_link "Version #1", :href => old_node_path(node, 1)
40       assert_link "Version #2", :href => old_node_path(node, 2)
41     end
42   end
43
44   test "shows a deleted node" do
45     node = create(:node, :with_history, :lat => 60, :lon => 30, :visible => false, :version => 2)
46
47     visit node_path(node)
48
49     within_sidebar do
50       assert_css "h2", :text => "Node: #{node.id}"
51       within "h4", :text => "Version #2" do
52         assert_link "2", :href => old_node_path(node, 2)
53       end
54       assert_no_text "Location"
55       assert_text "Deleted"
56
57       assert_no_link "Download XML"
58       assert_link "View History", :href => node_history_path(node)
59       assert_no_link "View Unredacted History"
60     end
61   end
62
63   test "shows node navigation to regular users" do
64     node = create(:node, :with_history)
65
66     sign_in_as(create(:user))
67     visit node_path(node)
68
69     within_sidebar do
70       assert_link "View History", :href => node_history_path(node)
71       assert_no_link "View Unredacted History"
72     end
73   end
74
75   test "shows node navigation to moderators" do
76     node = create(:node, :with_history)
77
78     sign_in_as(create(:moderator_user))
79     visit node_path(node)
80
81     within_sidebar do
82       assert_link "View History", :href => node_history_path(node)
83       assert_link "View Unredacted History", :href => node_history_path(node, :show_redactions => true)
84     end
85   end
86
87   test "shows a link to containing relation of a node" do
88     node = create(:node)
89     containing_relation = create(:relation)
90     create(:relation_member, :relation => containing_relation, :member => node)
91
92     visit node_path(node)
93
94     within_sidebar do
95       assert_link :href => relation_path(containing_relation)
96     end
97   end
98
99   test "relation member nodes should be visible on the map when viewing relations" do
100     relation = create(:relation)
101     node = create(:node)
102     create(:relation_member, :relation => relation, :member => node)
103
104     visit relation_path(relation)
105
106     assert_selector "#map .leaflet-overlay-pane path"
107   end
108
109   test "map should center on a viewed node" do
110     node = create(:node, :lat => 59.55555, :lon => 29.55555)
111
112     visit node_path(node)
113
114     within "#map" do
115       click_on "Share"
116     end
117
118     share_url = find_by_id("long_input").value
119     assert_match %r{map=\d+/59\.\d+/29\.\d+}, share_url
120   end
121 end