Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair Image upload and reply of comment Section #8240

Merged
merged 9 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/javascripts/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
if(!$(this).hasClass('bound-beforeSend')) {
$(this).addClass('bound-beforeSend').bind('ajax:beforeSend', function(event){
$(this).find("#text-input").prop('disabled',true)
$(this).find('#text-input').val('');
$(this).find(".btn-primary").button('loading',true);
});
}
Expand All @@ -25,13 +26,15 @@
notyNotification('mint', 3000, 'success', 'topRight', 'Some error occured while adding comment');
$(this).find('.control-group').addClass('has-error')
$(this).find('.control-group .help-block ').remove()
$(this).find('#text-input').val('');
$(this).find('.control-group').append('<span class="help-block ">Error: there was a problem.</span>')
});
}

if(!$(this).hasClass('bound-keypress')) {
$(this).addClass('bound-keypress');

$(this).find('#text-input').val('');
$(this).on('keypress', function (e) {
var isPostCommentShortcut = (e.ctrlKey && e.keyCode === 10) || (e.metaKey && e.keyCode === 13);

Expand Down
5 changes: 3 additions & 2 deletions app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@
</span>

<!-- http://stackoverflow.com/questions/11235206/twitter-bootstrap-form-file-element-upload-button -->
<input aria-label="Choose File" id="fileinput" type="file" name="image[photo]" style="display:none;" />
<a onClick="handleClick()" class="d-none d-md-inline text-underline">choose one</a>
<label for="fileinput">
<input id="fileinput" type="file" name="image[photo]" style="display:none;" />
<a onClick="handleClick()" style="cursor: pointer;" class="d-none d-md-inline text-underline">choose one</a>
<span class="d-md-none">
<i class="fa fa-upload"></i>
<a><%= translation('comments._form.upload_image') %></a>
Expand Down
32 changes: 32 additions & 0 deletions test/system/comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def setup
click_on "Publish"
find(".noty_body", text: "Comment Added!")
find("p", text: "Awesome comment! :)")

# replying to the comment
first("p", text: "Reply to this comment...").click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!!!! Great work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I wonder if you could simulate clicking the "choose one" link and selecting an image? Is it possible?

See how this test works!

test 'comment image upload' do
Capybara.ignore_hidden_elements = false
visit "/wiki/wiki-page-path/comments"
find("p", text: "Reply to this comment...").click()
reply_preview_button = page.all('#post_comment')[0]
fileinput_element = page.all('#fileinput')[0]
# Upload the image
fileinput_element.set("#{Rails.root.to_s}/public/images/pl.png")
# Wait for image upload to finish
wait_for_ajax
Capybara.ignore_hidden_elements = true
# Toggle preview
reply_preview_button.click()
# Make sure that image has been uploaded
page.assert_selector('#preview img', count: 1)
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I wonder if you could simulate clicking the "choose one" link and selecting an image? Is it possible?

See how this test works!

test 'comment image upload' do
Capybara.ignore_hidden_elements = false
visit "/wiki/wiki-page-path/comments"
find("p", text: "Reply to this comment...").click()
reply_preview_button = page.all('#post_comment')[0]
fileinput_element = page.all('#fileinput')[0]
# Upload the image
fileinput_element.set("#{Rails.root.to_s}/public/images/pl.png")
# Wait for image upload to finish
wait_for_ajax
Capybara.ignore_hidden_elements = true
# Toggle preview
reply_preview_button.click()
# Make sure that image has been uploaded
page.assert_selector('#preview img', count: 1)
end

Ok, willl do this.


fill_in("body", with: "Awesome Reply")

# preview reply
first("#post_comment").click
find("p", text: "Awesome Reply")
end

test 'comment preview button' do
Expand Down Expand Up @@ -100,7 +109,30 @@ def setup
# Make sure that image has been uploaded
page.assert_selector('#preview img', count: 1)
end

test 'comment image upload by choose one' do
Capybara.ignore_hidden_elements = false
visit "/wiki/wiki-page-path/comments"

find("p", text: "Reply to this comment...").click()
first("a", text: "choose one").click()

reply_preview_button = page.all('#post_comment')[0]
fileinput_element = page.all('#fileinput')[0]

# Upload the image
fileinput_element.set("#{Rails.root.to_s}/public/images/pl.png")

# Wait for image upload to finish
wait_for_ajax
Capybara.ignore_hidden_elements = true

# Toggle preview
reply_preview_button.click()

# Make sure that image has been uploaded
page.assert_selector('#preview img', count: 1)
end
test 'comment image drag and drop upload' do
Capybara.ignore_hidden_elements = false
visit "/wiki/wiki-page-path/comments"
Expand Down