1 # frozen_string_literal: true
3 require "application_system_test_case"
5 class ChangesetElementsTest < ApplicationSystemTestCase
6 test "can navigate between element subpages without losing comment input" do
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) }
14 sign_in_as(create(:user))
15 visit changeset_path(changeset)
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"]
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"]
26 fill_in "text", :with => "Comment text we don't want to lose"
28 click_on "Ways (21-21 of 21)"
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"]
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"]
38 assert_field "text", :with => "Comment text we don't want to lose"
40 click_on "Nodes (21-21 of 21)"
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"]
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"]
50 assert_field "text", :with => "Comment text we don't want to lose"
56 def assert_one_missing_link(hrefs)
60 assert_link :href => href, :minimum => 0, :maximum => 1 do
64 assert_nil missing_href, "unexpected extra missing link '#{href}'"
68 assert_not_nil missing_href, "expected one link missing but all are present"
72 def assert_one_present_link(hrefs, present_href)
74 assert_link :href => href, :count => (href == present_href ? 1 : 0)