]> git.openstreetmap.org Git - rails.git/blob - test/system/changeset_elements_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / system / changeset_elements_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
5 class ChangesetElementsTest < ApplicationSystemTestCase
6   test "can navigate between element subpages without losing comment input" do
7     element_page_size = 20
8     changeset = create(:changeset, :closed, :num_changes => 2 * (element_page_size + 1))
9     ways = create_list(:way, element_page_size + 1, :with_history, :changeset => changeset)
10     way_paths = ways.map { |way| way_path(way) }
11     nodes = create_list(:node, element_page_size + 1, :with_history, :changeset => changeset)
12     node_paths = nodes.map { |node| node_path(node) }
13
14     sign_in_as(create(:user))
15     visit changeset_path(changeset)
16
17     within_sidebar do
18       next_page_way_path = assert_one_missing_link way_paths
19       assert_equal "page", find_link("Ways (1-20 of 21)")["aria-current"]
20       assert_nil find_link("Ways (21-21 of 21)")["aria-current"]
21
22       assert_one_missing_link node_paths
23       assert_equal "page", find_link("Nodes (1-20 of 21)")["aria-current"]
24       assert_nil find_link("Nodes (21-21 of 21)")["aria-current"]
25
26       fill_in "text", :with => "Comment text we don't want to lose"
27
28       click_on "Ways (21-21 of 21)"
29
30       assert_one_present_link way_paths, next_page_way_path
31       assert_nil find_link("Ways (1-20 of 21)")["aria-current"]
32       assert_equal "page", find_link("Ways (21-21 of 21)")["aria-current"]
33
34       next_page_node_path = assert_one_missing_link node_paths
35       assert_equal "page", find_link("Nodes (1-20 of 21)")["aria-current"]
36       assert_nil find_link("Nodes (21-21 of 21)")["aria-current"]
37
38       assert_field "text", :with => "Comment text we don't want to lose"
39
40       click_on "Nodes (21-21 of 21)"
41
42       assert_one_present_link way_paths, next_page_way_path
43       assert_nil find_link("Ways (1-20 of 21)")["aria-current"]
44       assert_equal "page", find_link("Ways (21-21 of 21)")["aria-current"]
45
46       assert_one_present_link node_paths, next_page_node_path
47       assert_nil find_link("Nodes (1-20 of 21)")["aria-current"]
48       assert_equal "page", find_link("Nodes (21-21 of 21)")["aria-current"]
49
50       assert_field "text", :with => "Comment text we don't want to lose"
51     end
52   end
53
54   private
55
56   def assert_one_missing_link(hrefs)
57     missing_href = nil
58     hrefs.each do |href|
59       missing = true
60       assert_link :href => href, :minimum => 0, :maximum => 1 do
61         missing = false
62       end
63       if missing
64         assert_nil missing_href, "unexpected extra missing link '#{href}'"
65         missing_href = href
66       end
67     end
68     assert_not_nil missing_href, "expected one link missing but all are present"
69     missing_href
70   end
71
72   def assert_one_present_link(hrefs, present_href)
73     hrefs.each do |href|
74       assert_link :href => href, :count => (href == present_href ? 1 : 0)
75     end
76   end
77 end