});
}
- 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 = {};
}
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) {
</div>
<% if @comments.length > 0 %>
- <form action="#">
- <ul class="list-unstyled">
- <% @comments.each do |comment| %>
- <% next unless comment.visible || current_user&.moderator? %>
- <li id="c<%= comment.id %>">
- <small class='text-muted'>
- <%= t(comment.visible ? ".comment_by_html" : ".hidden_comment_by_html",
- :time_ago => friendly_date_ago(comment.created_at),
- :user => link_to(comment.author.display_name, user_path(comment.author))) %>
- <% if current_user&.moderator? %>
- —
- <%= tag.button t("javascripts.changesets.show.#{comment.visible ? 'hide' : 'unhide'}_comment"),
- :class => "btn btn-sm small btn-link link-secondary p-0 align-baseline",
- :data => { :method => "POST",
- :url => comment.visible ? changeset_comment_hide_url(comment) : changeset_comment_unhide_url(comment) } %>
- <% end %>
- </small>
- <div class="mx-2">
- <%= comment.body.to_html %>
- </div>
- </li>
- <% end %>
- </ul>
- </form>
+ <ul class="list-unstyled">
+ <% @comments.each do |comment| %>
+ <% next unless comment.visible || current_user&.moderator? %>
+ <li id="c<%= comment.id %>">
+ <small class='text-muted'>
+ <%= t comment.visible ? ".comment_by_html" : ".hidden_comment_by_html",
+ :time_ago => friendly_date_ago(comment.created_at),
+ :user => link_to(comment.author.display_name, user_path(comment.author)) %>
+ <% if current_user&.moderator? %>
+ —
+ <%= tag.button t("javascripts.changesets.show.#{comment.visible ? 'hide' : 'unhide'}_comment"),
+ :class => "btn btn-sm small btn-link link-secondary p-0 align-baseline",
+ :data => { :method => "POST",
+ :url => comment.visible ? changeset_comment_hide_url(comment) : changeset_comment_unhide_url(comment) } %>
+ <% end %>
+ </small>
+ <div class="mx-2">
+ <%= comment.body.to_html %>
+ </div>
+ </li>
+ <% end %>
+ </ul>
<% end %>
<% unless current_user %>
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