diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee index 7a8743f88..452b706e7 100644 --- a/app/assets/javascripts/comments.js.coffee +++ b/app/assets/javascripts/comments.js.coffee @@ -4,10 +4,15 @@ App.Comments = $(response_html).insertAfter($("#js-comment-form-#{parent_id}")) reset_and_hide_form: (id) -> - form = $("#js-comment-form-#{id}") - form.val('') + form = $("#js-comment-form-#{id} form") + input = form.find("textarea") + input.val('') form.hide() + reset_form: (id) -> + input = $("#js-comment-form-#{id} form textarea") + input.val('') + toggle_form: (id) -> $("#js-comment-form-#{id}").toggle() @@ -16,5 +21,3 @@ App.Comments = id = $(this).data().id App.Comments.toggle_form(id) false - - diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 9eeec3108..f2b078195 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,3 +1,9 @@ var parent_id = '<%= dom_id(@parent) %>'; -App.Comments.reset_and_hide_form(parent_id); + +<% if @parent.is_a?(Debate) -%> + App.Comments.reset_form(parent_id); +<% else -%> + App.Comments.reset_and_hide_form(parent_id); +<% end -%> + App.Comments.add_response(parent_id, "<%= j(render @comment) %>"); diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 1ec6a8c10..0cc64bce1 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -59,6 +59,7 @@ feature 'Comments' do visit debate_path(debate) click_link "Reply" + within "#js-comment-form-comment_#{comment.id}" do fill_in 'comment_body', with: 'It will be done next week.' click_button 'Publish reply' @@ -67,6 +68,8 @@ feature 'Comments' do within "#comment-#{comment.id}" do expect(page).to have_content 'It will be done next week.' end + + expect(page).to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end scenario "N replies", :js do @@ -74,13 +77,13 @@ feature 'Comments' do parent = create(:comment, commentable: debate) 7.times do - create(:comment, commentable: debate). - move_to_child_of(parent) - parent = parent.children.first + create(:comment, commentable: debate). + move_to_child_of(parent) + parent = parent.children.first end visit debate_path(debate) expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") end -end \ No newline at end of file +end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index b625138b0..5e56d2cea 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -56,4 +56,4 @@ module CommonActions SimpleCaptcha::SimpleCaptchaData.first.value end -end \ No newline at end of file +end