From ef919179fa8dbebad66cb48279613e697823b84f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 8 Jan 2024 17:44:05 +0300 Subject: [PATCH] Show api error message if failed to (un)subscribe --- app/assets/javascripts/index/changeset.js | 18 ++++----- app/views/browse/changeset.html.erb | 46 +++++++++++------------ test/system/changeset_comments_test.rb | 37 ++++++++++++++++++ 3 files changed, 68 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/index/changeset.js b/app/assets/javascripts/index/changeset.js index 23d24d141..40f6aa05b 100644 --- a/app/assets/javascripts/index/changeset.js +++ b/app/assets/javascripts/index/changeset.js @@ -26,14 +26,14 @@ OSM.Changeset = function (map) { }); } - function updateChangeset(form, method, url, include_data) { + function updateChangeset(method, url, include_data) { var data; - $(form).find("#comment-error").prop("hidden", true); - $(form).find("button").prop("disabled", true); + content.find("#comment-error").prop("hidden", true); + content.find("button[data-method][data-url]").prop("disabled", true); if (include_data) { - data = { text: $(form.text).val() }; + data = { text: content.find("textarea").val() }; } else { data = {}; } @@ -47,19 +47,19 @@ OSM.Changeset = function (map) { OSM.loadSidebarContent(window.location.pathname, page.load); }, error: function (xhr) { - $(form).find("#comment-error").text(xhr.responseText); - $(form).find("#comment-error").prop("hidden", false); - $(form).find("button").prop("disabled", false); + content.find("#comment-error").text(xhr.responseText); + content.find("#comment-error").prop("hidden", false); + content.find("button[data-method][data-url]").prop("disabled", false); } }); } function initialize() { - content.find("button").on("click", function (e) { + content.find("button[data-method][data-url]").on("click", function (e) { e.preventDefault(); var data = $(e.target).data(); var include_data = e.target.name === "comment"; - updateChangeset(e.target.form, data.method, data.url, include_data); + updateChangeset(data.method, data.url, include_data); }); content.find("textarea").on("input", function (e) { diff --git a/app/views/browse/changeset.html.erb b/app/views/browse/changeset.html.erb index 4fe82d120..88d90d0f7 100644 --- a/app/views/browse/changeset.html.erb +++ b/app/views/browse/changeset.html.erb @@ -27,30 +27,28 @@ <% if @comments.length > 0 %> -
- -
+ <% end %> <% unless current_user %> diff --git a/test/system/changeset_comments_test.rb b/test/system/changeset_comments_test.rb index 82fd81286..b12aab5ee 100644 --- a/test/system/changeset_comments_test.rb +++ b/test/system/changeset_comments_test.rb @@ -122,4 +122,41 @@ class ChangesetCommentsTest < ApplicationSystemTestCase assert_text "Wanted comment" end end + + test "can subscribe" do + changeset = create(:changeset, :closed) + user = create(:user) + sign_in_as(user) + visit changeset_path(changeset) + + within_sidebar do + assert_button "Subscribe" + assert_no_button "Unsubscribe" + + click_on "Subscribe" + + assert_no_button "Subscribe" + assert_button "Unsubscribe" + end + end + + test "can't subscribe when blocked" do + changeset = create(:changeset, :closed) + user = create(:user) + sign_in_as(user) + visit changeset_path(changeset) + create(:user_block, :user => user) + + within_sidebar do + assert_no_text "Your access to the API has been blocked" + assert_button "Subscribe" + assert_no_button "Unsubscribe" + + click_on "Subscribe" + + assert_text "Your access to the API has been blocked" + assert_button "Subscribe" + assert_no_button "Unsubscribe" + end + end end -- 2.39.5