From: Tom Hughes Date: Wed, 26 Oct 2022 17:23:17 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/3769' X-Git-Tag: live~1483 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/74081ab17619e73306c9393bfbacd6eb463ab292?hp=d2ca26f0e6e73df924ad79a6456fdcce36634ee9 Merge remote-tracking branch 'upstream/pull/3769' --- diff --git a/app/assets/javascripts/index/history.js b/app/assets/javascripts/index/history.js index d137b8456..02b48f6a0 100644 --- a/app/assets/javascripts/index/history.js +++ b/app/assets/javascripts/index/history.js @@ -43,6 +43,18 @@ OSM.History = function (map) { $("#changeset_" + id).find("a.changeset_id").simulate("click", e); } + function displayFirstChangesets(html) { + $("#sidebar_content .changesets").html(html); + } + + function displayMoreChangesets(html) { + $("#sidebar_content .changeset_more").replaceWith(html); + var oldList = $("#sidebar_content .changesets ol").first(); + var newList = oldList.next("ol"); + newList.children().appendTo(oldList); + newList.remove(); + } + function update() { var data = { list: "1" }; @@ -58,7 +70,7 @@ OSM.History = function (map) { method: "GET", data: data, success: function (html) { - $("#sidebar_content .changesets").html(html); + displayFirstChangesets(html); updateMap(); } }); @@ -73,8 +85,8 @@ OSM.History = function (map) { $(this).hide(); div.find(".loader").show(); - $.get($(this).attr("href"), function (data) { - div.replaceWith(data); + $.get($(this).attr("href"), function (html) { + displayMoreChangesets(html); updateMap(); }); } diff --git a/test/system/history_test.rb b/test/system/history_test.rb index 45654b88d..335063db9 100644 --- a/test/system/history_test.rb +++ b/test/system/history_test.rb @@ -1,6 +1,8 @@ require "application_system_test_case" class HistoryTest < ApplicationSystemTestCase + PAGE_SIZE = 20 + test "atom link on user's history is not modified" do user = create(:user) create(:changeset, :user => user, :num_changes => 1) do |changeset| @@ -13,4 +15,45 @@ class HistoryTest < ApplicationSystemTestCase assert_css "link[type='application/atom+xml'][href$='#{user_path(user)}/history/feed']", :visible => false end + + test "have only one list element on user's changesets page" do + user = create(:user) + create_visible_changeset(user, "first-changeset-in-history") + create_visible_changeset(user, "bottom-changeset-in-batch-2") + (PAGE_SIZE - 1).times do + create_visible_changeset(user, "next-changeset") + end + create_visible_changeset(user, "bottom-changeset-in-batch-1") + (PAGE_SIZE - 1).times do + create_visible_changeset(user, "next-changeset") + end + + visit "#{user_path(user)}/history" + changesets = find "div.changesets" + changesets.assert_text "bottom-changeset-in-batch-1" + changesets.assert_no_text "bottom-changeset-in-batch-2" + changesets.assert_no_text "first-changeset-in-history" + changesets.assert_selector "ol", :count => 1 + changesets.assert_selector "li", :count => PAGE_SIZE + + changesets.find(".changeset_more a.btn").click + changesets.assert_text "bottom-changeset-in-batch-1" + changesets.assert_text "bottom-changeset-in-batch-2" + changesets.assert_no_text "first-changeset-in-history" + changesets.assert_selector "ol", :count => 1 + changesets.assert_selector "li", :count => 2 * PAGE_SIZE + + changesets.find(".changeset_more a.btn").click + changesets.assert_text "bottom-changeset-in-batch-1" + changesets.assert_text "bottom-changeset-in-batch-2" + changesets.assert_text "first-changeset-in-history" + changesets.assert_selector "ol", :count => 1 + changesets.assert_selector "li", :count => (2 * PAGE_SIZE) + 1 + end + + def create_visible_changeset(user, comment) + create(:changeset, :user => user, :num_changes => 1) do |changeset| + create(:changeset_tag, :changeset => changeset, :k => "comment", :v => comment) + end + end end