Merge remote-tracking branch 'upstream/pull/4462'
This commit is contained in:
commit
9387df9141
4 changed files with 129 additions and 24 deletions
|
@ -52,20 +52,18 @@ OSM.Note = function (map) {
|
||||||
OSM.loadSidebarContent(path, function () {
|
OSM.loadSidebarContent(path, function () {
|
||||||
initialize(path, id, moveToNote);
|
initialize(path, id, moveToNote);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
error: function (xhr) {
|
||||||
|
$(form).find("#comment-error")
|
||||||
|
.text(xhr.responseText)
|
||||||
|
.prop("hidden", false);
|
||||||
|
updateButtons(form);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
content.find("textarea").on("input", function (e) {
|
content.find("textarea").on("input", function (e) {
|
||||||
var form = e.target.form;
|
updateButtons(e.target.form);
|
||||||
|
|
||||||
if ($(e.target).val() === "") {
|
|
||||||
$(form.close).val($(form.close).data("defaultActionText"));
|
|
||||||
$(form.comment).prop("disabled", true);
|
|
||||||
} else {
|
|
||||||
$(form.close).val($(form.close).data("commentActionText"));
|
|
||||||
$(form.comment).prop("disabled", false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
content.find("textarea").val("").trigger("input");
|
content.find("textarea").val("").trigger("input");
|
||||||
|
@ -84,6 +82,17 @@ OSM.Note = function (map) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateButtons(form) {
|
||||||
|
$(form).find("input[type=submit]").prop("disabled", false);
|
||||||
|
if ($(form.text).val() === "") {
|
||||||
|
$(form.close).val($(form.close).data("defaultActionText"));
|
||||||
|
$(form.comment).prop("disabled", true);
|
||||||
|
} else {
|
||||||
|
$(form.close).val($(form.close).data("commentActionText"));
|
||||||
|
$(form.comment).prop("disabled", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function moveToNote() {
|
function moveToNote() {
|
||||||
var data = $(".details").data();
|
var data = $(".details").data();
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
|
@ -49,6 +49,8 @@
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<textarea class="form-control" name="text" cols="40" rows="5" maxlength="2000"></textarea>
|
<textarea class="form-control" name="text" cols="40" rows="5" maxlength="2000"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="comment-error" class="alert alert-danger p-2 mb-3" hidden>
|
||||||
|
</div>
|
||||||
<div class="btn-wrapper">
|
<div class="btn-wrapper">
|
||||||
<% if current_user.moderator? -%>
|
<% if current_user.moderator? -%>
|
||||||
<%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-light",
|
<%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-light",
|
||||||
|
@ -73,6 +75,8 @@
|
||||||
<% else %>
|
<% else %>
|
||||||
<form class="mb-3" action="#">
|
<form class="mb-3" action="#">
|
||||||
<input type="hidden" name="text" value="" autocomplete="off">
|
<input type="hidden" name="text" value="" autocomplete="off">
|
||||||
|
<div id="comment-error" class="alert alert-danger p-2 mb-3" hidden>
|
||||||
|
</div>
|
||||||
<div class="btn-wrapper">
|
<div class="btn-wrapper">
|
||||||
<% if @note.status != "hidden" and current_user and current_user.moderator? -%>
|
<% if @note.status != "hidden" and current_user and current_user.moderator? -%>
|
||||||
<input type="submit" name="hide" value="<%= t(".hide") %>" class="btn btn-light" data-method="DELETE" data-url="<%= api_note_url(@note, "json") %>">
|
<input type="submit" name="hide" value="<%= t(".hide") %>" class="btn btn-light" data-method="DELETE" data-url="<%= api_note_url(@note, "json") %>">
|
||||||
|
|
|
@ -21,4 +21,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||||
Settings.reload!
|
Settings.reload!
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def within_sidebar(&block)
|
||||||
|
within "#sidebar_content", &block
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,17 +5,21 @@ class NoteCommentsTest < ApplicationSystemTestCase
|
||||||
note = create(:note_with_comments)
|
note = create(:note_with_comments)
|
||||||
visit note_path(note)
|
visit note_path(note)
|
||||||
|
|
||||||
assert_no_button "Resolve"
|
within_sidebar do
|
||||||
assert_no_button "Comment"
|
assert_no_button "Resolve"
|
||||||
assert_link "Log in to comment on this note", :href => login_path(:referer => note_path(note))
|
assert_no_button "Comment"
|
||||||
|
assert_link "Log in to comment on this note", :href => login_path(:referer => note_path(note))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "closed note has no login notice" do
|
test "closed note has no login notice" do
|
||||||
note = create(:note_with_comments, :closed)
|
note = create(:note_with_comments, :closed)
|
||||||
visit note_path(note)
|
visit note_path(note)
|
||||||
|
|
||||||
assert_no_button "Reactivate"
|
within_sidebar do
|
||||||
assert_no_link "Log in to comment on this note"
|
assert_no_button "Reactivate"
|
||||||
|
assert_no_link "Log in to comment on this note"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_add_comment
|
def test_add_comment
|
||||||
|
@ -24,19 +28,101 @@ class NoteCommentsTest < ApplicationSystemTestCase
|
||||||
sign_in_as(user)
|
sign_in_as(user)
|
||||||
visit note_path(note)
|
visit note_path(note)
|
||||||
|
|
||||||
assert_no_content "Comment from #{user.display_name}"
|
within_sidebar do
|
||||||
assert_no_content "Some newly added note comment"
|
assert_no_content "Comment from #{user.display_name}"
|
||||||
assert_button "Resolve"
|
assert_no_content "Some newly added note comment"
|
||||||
assert_button "Comment", :disabled => true
|
assert_button "Resolve"
|
||||||
|
assert_button "Comment", :disabled => true
|
||||||
|
|
||||||
fill_in "text", :with => "Some newly added note comment"
|
fill_in "text", :with => "Some newly added note comment"
|
||||||
|
|
||||||
assert_button "Comment & Resolve"
|
assert_button "Comment & Resolve"
|
||||||
assert_button "Comment", :disabled => false
|
assert_button "Comment", :disabled => false
|
||||||
|
|
||||||
click_on "Comment"
|
click_on "Comment"
|
||||||
|
|
||||||
assert_content "Comment from #{user.display_name}"
|
assert_content "Comment from #{user.display_name}"
|
||||||
assert_content "Some newly added note comment"
|
assert_content "Some newly added note comment"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "can't add a comment when blocked" do
|
||||||
|
note = create(:note_with_comments)
|
||||||
|
user = create(:user)
|
||||||
|
sign_in_as(user)
|
||||||
|
visit note_path(note)
|
||||||
|
block = create(:user_block, :user => user)
|
||||||
|
|
||||||
|
within_sidebar do
|
||||||
|
fill_in "text", :with => "Comment that won't be added while blocked"
|
||||||
|
|
||||||
|
assert_no_text "Comment from #{user.display_name}"
|
||||||
|
assert_no_text "Comment that won't be added while blocked"
|
||||||
|
assert_no_text "Your access to the API has been blocked"
|
||||||
|
assert_button "Comment & Resolve", :disabled => false
|
||||||
|
assert_button "Comment", :disabled => false
|
||||||
|
|
||||||
|
click_on "Comment"
|
||||||
|
|
||||||
|
assert_no_text "Comment from #{user.display_name}"
|
||||||
|
assert_no_text "Comment that won't be added while blocked"
|
||||||
|
assert_text "Your access to the API has been blocked"
|
||||||
|
assert_button "Comment & Resolve", :disabled => false
|
||||||
|
assert_button "Comment", :disabled => false
|
||||||
|
|
||||||
|
block.revoke! block.creator
|
||||||
|
|
||||||
|
click_on "Comment"
|
||||||
|
|
||||||
|
assert_text "Comment from #{user.display_name}"
|
||||||
|
assert_text "Comment that won't be added while blocked"
|
||||||
|
assert_no_text "Your access to the API has been blocked"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "can't resolve a note when blocked" do
|
||||||
|
note = create(:note_with_comments)
|
||||||
|
user = create(:user)
|
||||||
|
sign_in_as(user)
|
||||||
|
visit note_path(note)
|
||||||
|
create(:user_block, :user => user)
|
||||||
|
|
||||||
|
within_sidebar do
|
||||||
|
assert_text "Unresolved note"
|
||||||
|
assert_no_text "Resolved note"
|
||||||
|
assert_no_text "Your access to the API has been blocked"
|
||||||
|
assert_button "Resolve", :disabled => false
|
||||||
|
assert_button "Comment", :disabled => true
|
||||||
|
|
||||||
|
click_on "Resolve"
|
||||||
|
|
||||||
|
assert_text "Unresolved note"
|
||||||
|
assert_no_text "Resolved note"
|
||||||
|
assert_text "Your access to the API has been blocked"
|
||||||
|
assert_button "Resolve", :disabled => false
|
||||||
|
assert_button "Comment", :disabled => true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "can't reactivate a note when blocked" do
|
||||||
|
note = create(:note_with_comments, :closed)
|
||||||
|
user = create(:user)
|
||||||
|
sign_in_as(user)
|
||||||
|
visit note_path(note)
|
||||||
|
create(:user_block, :user => user)
|
||||||
|
|
||||||
|
within_sidebar do
|
||||||
|
assert_no_text "Unresolved note"
|
||||||
|
assert_text "Resolved note"
|
||||||
|
assert_no_text "Your access to the API has been blocked"
|
||||||
|
assert_button "Reactivate", :disabled => false
|
||||||
|
|
||||||
|
click_on "Reactivate"
|
||||||
|
|
||||||
|
assert_no_text "Unresolved note"
|
||||||
|
assert_text "Resolved note"
|
||||||
|
assert_text "Your access to the API has been blocked"
|
||||||
|
assert_button "Reactivate", :disabled => false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue