1 require "application_system_test_case"
 
   3 class ChangesetElementsTest < ApplicationSystemTestCase
 
   4   test "can navigate between element subpages without losing comment input" do
 
   6     changeset = create(:changeset, :closed)
 
   7     ways = create_list(:way, element_page_size + 1, :with_history, :changeset => changeset)
 
   8     way_paths = ways.map { |way| way_path(way) }
 
   9     nodes = create_list(:node, element_page_size + 1, :with_history, :changeset => changeset)
 
  10     node_paths = nodes.map { |node| node_path(node) }
 
  12     sign_in_as(create(:user))
 
  13     visit changeset_path(changeset)
 
  16       next_page_way_path = assert_one_missing_link way_paths
 
  17       assert_no_link "Ways (1-20 of 21)"
 
  18       assert_link "Ways (21-21 of 21)"
 
  20       assert_one_missing_link node_paths
 
  21       assert_no_link "Nodes (1-20 of 21)"
 
  22       assert_link "Nodes (21-21 of 21)"
 
  24       fill_in "text", :with => "Comment text we don't want to lose"
 
  26       click_on "Ways (21-21 of 21)"
 
  28       assert_one_present_link way_paths, next_page_way_path
 
  29       assert_link "Ways (1-20 of 21)"
 
  30       assert_no_link "Ways (21-21 of 21)"
 
  32       next_page_node_path = assert_one_missing_link node_paths
 
  33       assert_no_link "Nodes (1-20 of 21)"
 
  34       assert_link "Nodes (21-21 of 21)"
 
  36       assert_field "text", :with => "Comment text we don't want to lose"
 
  38       click_on "Nodes (21-21 of 21)"
 
  40       assert_one_present_link way_paths, next_page_way_path
 
  41       assert_link "Ways (1-20 of 21)"
 
  42       assert_no_link "Ways (21-21 of 21)"
 
  44       assert_one_present_link node_paths, next_page_node_path
 
  45       assert_link "Nodes (1-20 of 21)"
 
  46       assert_no_link "Nodes (21-21 of 21)"
 
  48       assert_field "text", :with => "Comment text we don't want to lose"
 
  54   def assert_one_missing_link(hrefs)
 
  58       assert_link :href => href, :minimum => 0, :maximum => 1 do
 
  62         assert_nil missing_href, "unexpected extra missing link '#{href}'"
 
  66     assert_not_nil missing_href, "expected one link missing but all are present"
 
  70   def assert_one_present_link(hrefs, present_href)
 
  72       assert_link :href => href, :count => (href == present_href ? 1 : 0)