diff --git a/Gemfile b/Gemfile index 2c2c3e208..f3661c06c 100644 --- a/Gemfile +++ b/Gemfile @@ -25,7 +25,7 @@ gem "globalize-accessors", "~> 0.2.1" gem "graphiql-rails", "~> 1.4.1" gem "graphql", "~> 1.7.8" gem "groupdate", "~> 3.2.0" -gem "initialjs-rails", "~> 0.2.0.5" +gem "initialjs-rails", "~> 0.2.0.8" gem "invisible_captcha", "~> 0.10.0" gem "jquery-fileupload-rails" gem "jquery-rails", "~> 4.3.3" diff --git a/Gemfile.lock b/Gemfile.lock index 1d64d39ba..4494283b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -282,7 +282,7 @@ GEM rainbow (>= 2.2.2, < 4.0) terminal-table (>= 1.5.1) ice_nine (0.11.2) - initialjs-rails (0.2.0.5) + initialjs-rails (0.2.0.8) railties (>= 3.1, < 6.0) invisible_captcha (0.10.0) rails (>= 3.2.0) @@ -642,7 +642,7 @@ DEPENDENCIES graphql (~> 1.7.8) groupdate (~> 3.2.0) i18n-tasks (~> 0.9.29) - initialjs-rails (~> 0.2.0.5) + initialjs-rails (~> 0.2.0.8) invisible_captcha (~> 0.10.0) jquery-fileupload-rails jquery-rails (~> 4.3.3) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index e8127b705..05229bce5 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -1,15 +1,8 @@ (function() { "use strict"; App.Comments = { - add_comment: function(parent_id, response_html) { - $(response_html).insertAfter($("#js-comment-form-" + parent_id)); - this.update_comments_count(); - }, - add_reply: function(parent_id, response_html) { - if ($("#" + parent_id + " .comment-children").length === 0) { - $("#" + parent_id).append("
  • "); - } - $("#" + parent_id + " .comment-children:first").prepend($(response_html)); + add_comment: function(parent_selector, response_html) { + $(parent_selector + " .comment-list:first").prepend($(response_html)); this.update_comments_count(); }, update_comments_count: function() { @@ -24,24 +17,19 @@ display_error: function(field_with_errors, error_html) { $(error_html).insertAfter($("" + field_with_errors)); }, - reset_and_hide_form: function(id) { - var form_container, input; - form_container = $("#js-comment-form-" + id); - input = form_container.find("form textarea"); - input.val(""); - form_container.hide(); - }, - reset_form: function(id) { - var input; - input = $("#js-comment-form-" + id + " form textarea"); - input.val(""); + reset_form: function(parent_selector) { + var form_container; + + form_container = $(parent_selector + " .comment-form:first"); + form_container.find("textarea").val(""); + + if (parent_selector !== "") { + form_container.hide(); + } }, toggle_form: function(id) { $("#js-comment-form-" + id).toggle(); }, - toggle_arrow: function(id) { - $("span#" + id + "_arrow").toggleClass("fa-minus-square").toggleClass("fa-plus-square"); - }, initialize: function() { $("body").on("click", ".js-add-comment-link", function() { App.Comments.toggle_form($(this).data().id); @@ -49,10 +37,8 @@ }); $("body").on("click", ".js-toggle-children", function() { - var children_container_id; - children_container_id = ($(this).data().id) + "_children"; - $("#" + children_container_id).toggle("slow"); - App.Comments.toggle_arrow(children_container_id); + $(this).closest(".comment").find(".comment-list:first").toggle("slow"); + $(this).children(".far").toggleClass("fa-minus-square fa-plus-square"); $(this).children(".js-child-toggle").toggle(); return false; }); diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 82aee720f..3c195b1d8 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -2084,6 +2084,7 @@ table { } .comment { + line-height: $list-lineheight; margin: $line-height / 4 0; position: relative; @@ -2171,12 +2172,24 @@ table { } } -.comment-children { - border-left: 1px dashed $border; - display: inline-block; - margin-left: rem-calc(16); - padding-left: rem-calc(8); - width: 100%; +.comment-list { + margin: $line-height / 4 0; + + .comment-list { + border-left: 1px dashed $border; + display: inline-block; + padding-left: rem-calc(8); + width: 100%; + + } + + .comment-form { + display: none; + } + + &:empty { + display: none; + } } .comment-info { diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb index de38661a5..b0eee0ec3 100644 --- a/app/views/budgets/investments/show.html.erb +++ b/app/views/budgets/investments/show.html.erb @@ -19,7 +19,6 @@
    <%= render "/comments/comment_tree", comment_tree: @comment_tree, - comment_flags: @comment_flags, display_comments_count: false %>
    diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 0f51daac0..382555b62 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,12 +1,7 @@ -<% comment_flags ||= @comment_flags %> <% valuation = local_assigns.fetch(:valuation, false) %> -<% allow_votes = local_assigns.fetch(:allow_votes, true) %> -<% allow_actions = local_assigns.fetch(:allow_actions, true) %> -<% allow_comments = local_assigns.fetch(:allow_comments, true) %> -<% admin_layout = local_assigns.fetch(:admin_layout, false) %> -<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags), (admin_layout if admin_layout)] do %> - +
    + + <%= render "comments/comment_list", comments: child_comments_of(comment), valuation: valuation %> + <% end %> diff --git a/app/views/comments/_comment_list.html.erb b/app/views/comments/_comment_list.html.erb new file mode 100644 index 000000000..26138c7f5 --- /dev/null +++ b/app/views/comments/_comment_list.html.erb @@ -0,0 +1,7 @@ +<% valuation = local_assigns.fetch(:valuation, false) %> + +<%= tag.ul class: "no-bullet comment-list" do %> + <% comments.each do |comment| %> + <%= tag.li render("comments/comment", { comment: comment, valuation: valuation }) %> + <% end %> +<% end %> diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb index 78acd65c4..c8014178c 100644 --- a/app/views/comments/_comment_tree.html.erb +++ b/app/views/comments/_comment_tree.html.erb @@ -1,8 +1,6 @@ <% commentable = comment_tree.commentable %> <% valuation = local_assigns.fetch(:valuation, false) %> -<% allow_comments = local_assigns.fetch(:allow_comments, true) %> -<% admin_layout = local_assigns.fetch(:admin_layout, false) %> -<% cache [locale_and_user_status, comment_tree.order, commentable_cache_key(commentable), comment_tree.comments, comment_tree.comment_authors, commentable.comments_count, comment_flags, admin_layout] do %> +<% cache [locale_and_user_status, comment_tree.order, commentable_cache_key(commentable), comment_tree.comments, comment_tree.comment_authors, commentable.comments_count] do %>
    @@ -26,10 +24,9 @@
    <%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %>
    - <% elsif allow_comments %> + <% elsif !valuation || can?(:comment_valuation, commentable) %> <%= render "comments/form", { commentable: commentable, parent_id: nil, - toggeable: false, valuation: valuation } %> <% end %> <% else %> @@ -37,15 +34,7 @@ <%= render "shared/login_to_comment" %> <% end %> - <% comment_tree.root_comments.each do |comment| %> - <%= render "comments/comment", { comment: comment, - comment_flags: comment_flags, - valuation: valuation, - allow_votes: !valuation, - allow_actions: !valuation, - allow_comments: allow_comments, - admin_layout: admin_layout } %> - <% end %> + <%= render "comments/comment_list", comments: comment_tree.root_comments, valuation: valuation %> <%= paginate comment_tree.root_comments %>
    diff --git a/app/views/comments/_commentable_tree.html.erb b/app/views/comments/_commentable_tree.html.erb deleted file mode 100644 index 8ec0fb268..000000000 --- a/app/views/comments/_commentable_tree.html.erb +++ /dev/null @@ -1,33 +0,0 @@ -<% valuation = local_assigns.fetch(:valuation, false) %> -<% allow_comments = local_assigns.fetch(:allow_comments, true) %> -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@investment), @comment_tree.comments, @comment_tree.comment_authors, @investment.comments_count, @comment_flags] do %> -
    -
    -
    -

    - <%= t("debates.show.comments_title") %> - (<%= @investment.comments_count %>) -

    - - <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> - - <% if user_signed_in? && allow_comments %> - <%= render "comments/form", { commentable: @investment, - parent_id: nil, - toggeable: false, - valuation: valuation } %> - <% else %> -
    - <%= render "shared/login_to_comment" %> - <% end %> - - <% @comment_tree.root_comments.each do |comment| %> - <%= render "comments/comment", { comment: comment, - valuation: valuation, - allow_comments: allow_comments } %> - <% end %> - <%= paginate @comment_tree.root_comments %> -
    -
    -
    -<% end %> diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 6b3c9d85f..41b5e61eb 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,19 +1,19 @@ <% valuation = local_assigns.fetch(:valuation, false) %> <% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable), valuation] do %> <% css_id = parent_or_commentable_dom_id(parent_id, commentable) %> -
    class="comment-form"> - <%= form_for Comment.new, remote: true do |f| %> +
    + <%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %> <%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment.body_max_length, label: leave_comment_text(commentable) %> - <%= f.hidden_field :commentable_type, value: commentable.class.name %> - <%= f.hidden_field :commentable_id, value: commentable.id %> - <%= f.hidden_field :parent_id, value: parent_id %> - <%= f.hidden_field :valuation, value: valuation %> + <%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %> + <%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %> + <%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %> + <%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %> - <%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment" %> + <%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %> <% if can? :comment_as_moderator, commentable %>
    diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index aa2bd9b1c..1492140f0 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,11 +1,8 @@ -var comment_html = "<%= j(render @comment) %>" - <% if @comment.root? -%> - var commentable_id = "<%= dom_id(@commentable) %>"; - App.Comments.reset_form(commentable_id); - App.Comments.add_comment(commentable_id, comment_html); + var parent_id = ""; <% else -%> - var parent_id = "<%= "comment_#{@comment.parent_id}" %>"; - App.Comments.reset_and_hide_form(parent_id); - App.Comments.add_reply(parent_id, comment_html); + var parent_id = "#" + "<%= "comment_#{@comment.parent_id}" %>"; <% end -%> + +App.Comments.reset_form(parent_id); +App.Comments.add_comment(parent_id, "
  • <%= j(render @comment) %>
  • "); diff --git a/app/views/debates/_comments.html.erb b/app/views/debates/_comments.html.erb index aec0a1414..9b0348930 100644 --- a/app/views/debates/_comments.html.erb +++ b/app/views/debates/_comments.html.erb @@ -1,4 +1,4 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@debate), @comment_tree.comments, @comment_tree.comment_authors, @debate.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@debate), @comment_tree.comments, @comment_tree.comment_authors, @debate.comments_count] do %>

    @@ -9,15 +9,13 @@ <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> <% if user_signed_in? %> - <%= render "comments/form", { commentable: @debate, parent_id: nil, toggeable: false } %> + <%= render "comments/form", { commentable: @debate, parent_id: nil } %> <% else %>
    <%= render "shared/login_to_comment" %> <% end %> - <% @comment_tree.root_comments.each do |comment| %> - <%= render "comments/comment", comment: comment %> - <% end %> + <%= render "comments/comment_list", comments: @comment_tree.root_comments %> <%= paginate @comment_tree.root_comments %>

    diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb index f8aeeb655..d5297bc50 100644 --- a/app/views/legislation/annotations/show.html.erb +++ b/app/views/legislation/annotations/show.html.erb @@ -43,7 +43,6 @@
    <%= render "/comments/comment_tree", comment_tree: @comment_tree, - comment_flags: @comment_flags, display_comments_count: true %>
    diff --git a/app/views/legislation/proposals/_comments.html.erb b/app/views/legislation/proposals/_comments.html.erb index a3b0c635e..a8e657835 100644 --- a/app/views/legislation/proposals/_comments.html.erb +++ b/app/views/legislation/proposals/_comments.html.erb @@ -1,18 +1,16 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count] do %>
    <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> <% if user_signed_in? %> - <%= render "comments/form", { commentable: @proposal, parent_id: nil, toggeable: false } %> + <%= render "comments/form", { commentable: @proposal, parent_id: nil } %> <% else %>
    <%= render "shared/login_to_comment" %> <% end %> - <% @comment_tree.root_comments.each do |comment| %> - <%= render "comments/comment", comment: comment %> - <% end %> + <%= render "comments/comment_list", comments: @comment_tree.root_comments %> <%= paginate @comment_tree.root_comments %>
    diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index e8bd1a4f0..dec291438 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -43,6 +43,5 @@ <%= render "/comments/comment_tree", comment_tree: @comment_tree, - comment_flags: @comment_flags, display_comments_count: true %>
    diff --git a/app/views/polls/_comments.html.erb b/app/views/polls/_comments.html.erb index 5ac2dfb64..b99b9f351 100644 --- a/app/views/polls/_comments.html.erb +++ b/app/views/polls/_comments.html.erb @@ -1,18 +1,16 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@poll), @comment_tree.comments, @comment_tree.comment_authors, @poll.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@poll), @comment_tree.comments, @comment_tree.comment_authors, @poll.comments_count] do %>
    <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> <% if user_signed_in? %> - <%= render "comments/form", { commentable: @poll, parent_id: nil, toggeable: false } %> + <%= render "comments/form", { commentable: @poll, parent_id: nil } %> <% else %>
    <%= render "shared/login_to_comment" %> <% end %> - <% @comment_tree.root_comments.each do |comment| %> - <%= render "comments/comment", comment: comment %> - <% end %> + <%= render "comments/comment_list", comments: @comment_tree.root_comments %> <%= paginate @comment_tree.root_comments %>
    diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index a3b0c635e..a8e657835 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -1,18 +1,16 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count] do %>
    <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> <% if user_signed_in? %> - <%= render "comments/form", { commentable: @proposal, parent_id: nil, toggeable: false } %> + <%= render "comments/form", { commentable: @proposal, parent_id: nil } %> <% else %>
    <%= render "shared/login_to_comment" %> <% end %> - <% @comment_tree.root_comments.each do |comment| %> - <%= render "comments/comment", comment: comment %> - <% end %> + <%= render "comments/comment_list", comments: @comment_tree.root_comments %> <%= paginate @comment_tree.root_comments %>
    diff --git a/app/views/topics/_comments.html.erb b/app/views/topics/_comments.html.erb index a5ca165fe..abcaba601 100644 --- a/app/views/topics/_comments.html.erb +++ b/app/views/topics/_comments.html.erb @@ -1,17 +1,14 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@topic), @comment_tree.comments, @comment_tree.comment_authors, @topic.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@topic), @comment_tree.comments, @comment_tree.comment_authors, @topic.comments_count] do %>
    <%= render "shared/wide_order_selector", i18n_namespace: "comments" %> - <% @comment_tree.root_comments.each do |comment| %> - <%= render "comments/comment", comment: comment %> - <% end %> - + <%= render "comments/comment_list", comments: @comment_tree.root_comments %> <%= paginate @comment_tree.root_comments %> <% if user_signed_in? %> - <%= render "comments/form", { commentable: @topic, parent_id: nil, toggeable: false } %> + <%= render "comments/form", { commentable: @topic, parent_id: nil } %> <% else %> <%= render "shared/login_to_comment" %> <% end %> diff --git a/app/views/valuation/budget_investments/_valuation_comments.html.erb b/app/views/valuation/budget_investments/_valuation_comments.html.erb index f6b4c9a53..39f9995dc 100644 --- a/app/views/valuation/budget_investments/_valuation_comments.html.erb +++ b/app/views/valuation/budget_investments/_valuation_comments.html.erb @@ -1,9 +1,6 @@

    <%= t("valuation.budget_investments.valuation_comments") %>

    <% unless @comment_tree.nil? %> <%= render "/comments/comment_tree", comment_tree: @comment_tree, - comment_flags: @comment_flags, display_comments_count: false, - valuation: true, - allow_comments: can?(:comment_valuation, @investment), - admin_layout: true %> + valuation: true %> <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index feadd4cd5..24fb4fe6f 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -723,7 +723,6 @@ en: notice: "Now you are following this citizen proposal!
    We will notify you of changes as they occur so that you are up-to-date." destroy: notice: "You have stopped following this citizen proposal!
    You will no longer receive notifications related to this proposal." - hide: Hide print: print_button: Print this info search: Search diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index fb88107af..92de921d8 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -721,7 +721,6 @@ es: notice: "¡Ahora estás siguiendo esta propuesta ciudadana!
    Te notificaremos los cambios a medida que se produzcan para que estés al día." destroy: notice: "¡Has dejado de seguir esta propuesta ciudadana!
    Ya no recibirás más notificaciones relacionadas con esta propuesta." - hide: Ocultar print: print_button: Imprimir esta información search: Buscar diff --git a/spec/shared/system/notifiable_in_app.rb b/spec/shared/system/notifiable_in_app.rb index c141b98c4..afddae9d3 100644 --- a/spec/shared/system/notifiable_in_app.rb +++ b/spec/shared/system/notifiable_in_app.rb @@ -30,7 +30,7 @@ shared_examples "notifiable in-app" do |factory_name| visit path_for(notifiable) fill_in comment_body(notifiable), with: "Number #{n + 1} is the best!" - click_button "publish_comment" + click_button submit_comment_text(notifiable) within "#comments" do expect(page).to have_content "Number #{n + 1} is the best!" end @@ -53,7 +53,7 @@ shared_examples "notifiable in-app" do |factory_name| click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I replied to your comment" + fill_in comment_body(notifiable), with: "I replied to your comment" click_button "Publish reply" end @@ -79,7 +79,7 @@ shared_examples "notifiable in-app" do |factory_name| within("#comment_#{comment.id}_reply") { click_link "Reply" } within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Reply number #{n}" + fill_in comment_body(notifiable), with: "Reply number #{n}" click_button "Publish reply" end @@ -102,7 +102,7 @@ shared_examples "notifiable in-app" do |factory_name| visit path_for(notifiable) fill_in comment_body(notifiable), with: "I commented on my own notifiable" - click_button "publish_comment" + click_button submit_comment_text(notifiable) within "#comments" do expect(page).to have_content "I commented on my own notifiable" end @@ -121,7 +121,7 @@ shared_examples "notifiable in-app" do |factory_name| click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I replied to my own comment" + fill_in comment_body(notifiable), with: "I replied to my own comment" click_button "Publish reply" end diff --git a/spec/support/common_actions/comments.rb b/spec/support/common_actions/comments.rb index 1c8a60b7c..a53c17cd9 100644 --- a/spec/support/common_actions/comments.rb +++ b/spec/support/common_actions/comments.rb @@ -17,7 +17,7 @@ module Comments click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end expect(page).to have_content "It will be done next week." diff --git a/spec/support/common_actions/notifications.rb b/spec/support/common_actions/notifications.rb index 9dbb38091..569010555 100644 --- a/spec/support/common_actions/notifications.rb +++ b/spec/support/common_actions/notifications.rb @@ -10,7 +10,19 @@ module Notifications end def comment_body(resource) - "comment-body-#{resource.class.name.parameterize(separator: "_").to_sym}_#{resource.id}" + if resource.class.name == "Legislation::Question" + "Leave your answer" + else + "Leave your comment" + end + end + + def submit_comment_text(resource) + if resource.class.name == "Legislation::Question" + "Publish answer" + else + "Publish comment" + end end def create_proposal_notification(proposal) diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 2970da0df..7364c4698 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -23,22 +23,22 @@ describe "Commenting Budget::Investments" do end scenario "Show" do - parent_comment = create(:comment, commentable: investment) - first_child = create(:comment, commentable: investment, parent: parent_comment) - second_child = create(:comment, commentable: investment, parent: parent_comment) + parent_comment = create(:comment, commentable: investment, body: "Parent") + create(:comment, commentable: investment, parent: parent_comment, body: "First subcomment") + create(:comment, commentable: investment, parent: parent_comment, body: "Last subcomment") visit comment_path(parent_comment) expect(page).to have_css(".comment", count: 3) - expect(page).to have_content parent_comment.body - expect(page).to have_content first_child.body - expect(page).to have_content second_child.body + expect(page).to have_content "Parent" + expect(page).to have_content "First subcomment" + expect(page).to have_content "Last subcomment" expect(page).to have_link "Go back to #{investment.title}", href: budget_investment_path(investment.budget, investment) - expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2) - expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1) - expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1) + within ".comment", text: "Parent" do + expect(page).to have_selector(".comment", count: 2) + end end scenario "Link to comment show" do @@ -66,20 +66,26 @@ describe "Commenting Budget::Investments" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -193,7 +199,7 @@ describe "Commenting Budget::Investments" do login_as(user) visit budget_investment_path(investment.budget, investment) - fill_in "comment-body-budget_investment_#{investment.id}", with: "Have you thought about...?" + fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" within "#tab-comments-label" do @@ -225,7 +231,7 @@ describe "Commenting Budget::Investments" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end @@ -328,7 +334,7 @@ describe "Commenting Budget::Investments" do login_as(moderator.user) visit budget_investment_path(investment.budget, investment) - fill_in "comment-body-budget_investment_#{investment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-budget_investment_#{investment.id}" click_button "Publish comment" @@ -352,7 +358,7 @@ describe "Commenting Budget::Investments" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -385,7 +391,7 @@ describe "Commenting Budget::Investments" do login_as(admin.user) visit budget_investment_path(investment.budget, investment) - fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-budget_investment_#{investment.id}" click_button "Publish comment" @@ -404,7 +410,7 @@ describe "Commenting Budget::Investments" do visit admin_budget_budget_investment_path(investment.budget, investment) - fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-budget_investment_#{investment.id}" click_button "Publish comment" @@ -428,7 +434,7 @@ describe "Commenting Budget::Investments" do login_as(admin.user) visit admin_budget_budget_investment_path(investment.budget, investment) - fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-budget_investment_#{investment.id}" click_button "Publish comment" @@ -452,7 +458,7 @@ describe "Commenting Budget::Investments" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your comment", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end diff --git a/spec/system/comments/budget_investments_valuation_spec.rb b/spec/system/comments/budget_investments_valuation_spec.rb index 9e43dda3b..c4d3c7990 100644 --- a/spec/system/comments/budget_investments_valuation_spec.rb +++ b/spec/system/comments/budget_investments_valuation_spec.rb @@ -61,7 +61,7 @@ describe "Internal valuation comments on Budget::Investments" do scenario "Collapsable comments", :js do parent_comment = create(:comment, :valuation, author: valuator_user, body: "Main comment", commentable: investment) - child_comment = create(:comment, :valuation, author: valuator_user, body: "First child", + child_comment = create(:comment, :valuation, author: valuator_user, body: "First subcomment", commentable: investment, parent: parent_comment) grandchild_comment = create(:comment, :valuation, author: valuator_user, parent: child_comment, @@ -73,20 +73,26 @@ describe "Internal valuation comments on Budget::Investments" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 1b5db3283..2b8bbc3e8 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -20,22 +20,22 @@ describe "Commenting debates" do end scenario "Show" do - parent_comment = create(:comment, commentable: debate) - first_child = create(:comment, commentable: debate, parent: parent_comment) - second_child = create(:comment, commentable: debate, parent: parent_comment) + parent_comment = create(:comment, commentable: debate, body: "Parent") + create(:comment, commentable: debate, parent: parent_comment, body: "First subcomment") + create(:comment, commentable: debate, parent: parent_comment, body: "Last subcomment") visit comment_path(parent_comment) expect(page).to have_css(".comment", count: 3) - expect(page).to have_content parent_comment.body - expect(page).to have_content first_child.body - expect(page).to have_content second_child.body + expect(page).to have_content "Parent" + expect(page).to have_content "First subcomment" + expect(page).to have_content "Last subcomment" expect(page).to have_link "Go back to #{debate.title}", href: debate_path(debate) - expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2) - expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1) - expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1) + within ".comment", text: "Parent" do + expect(page).to have_selector(".comment", count: 2) + end end scenario "Link to comment show" do @@ -63,20 +63,26 @@ describe "Commenting debates" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -210,7 +216,7 @@ describe "Commenting debates" do login_as(user) visit debate_path(debate) - fill_in "comment-body-debate_#{debate.id}", with: "Have you thought about...?" + fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" within "#comments" do @@ -239,7 +245,7 @@ describe "Commenting debates" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end @@ -365,7 +371,7 @@ describe "Commenting debates" do login_as(user) visit debate_path(debate) - fill_in "comment-body-debate_#{debate.id}", with: "Testing submit button!" + fill_in "Leave your comment", with: "Testing submit button!" click_button "Publish comment" # The button"s text should now be "..." @@ -382,7 +388,7 @@ describe "Commenting debates" do login_as(moderator.user) visit debate_path(debate) - fill_in "comment-body-debate_#{debate.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-debate_#{debate.id}" click_button "Publish comment" @@ -406,7 +412,7 @@ describe "Commenting debates" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -438,7 +444,7 @@ describe "Commenting debates" do login_as(admin.user) visit debate_path(debate) - fill_in "comment-body-debate_#{debate.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-debate_#{debate.id}" click_button "Publish comment" @@ -462,7 +468,7 @@ describe "Commenting debates" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your comment", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 18b9f40d2..bb1788660 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -22,25 +22,25 @@ describe "Commenting legislation questions" do end scenario "Show" do - parent_comment = create(:comment, commentable: legislation_annotation) - first_child = create(:comment, commentable: legislation_annotation, parent: parent_comment) - second_child = create(:comment, commentable: legislation_annotation, parent: parent_comment) href = legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + parent_comment = create(:comment, commentable: legislation_annotation, body: "Parent") + create(:comment, commentable: legislation_annotation, parent: parent_comment, body: "First subcomment") + create(:comment, commentable: legislation_annotation, parent: parent_comment, body: "Last subcomment") visit comment_path(parent_comment) expect(page).to have_css(".comment", count: 3) - expect(page).to have_content parent_comment.body - expect(page).to have_content first_child.body - expect(page).to have_content second_child.body + expect(page).to have_content "Parent" + expect(page).to have_content "First subcomment" + expect(page).to have_content "Last subcomment" expect(page).to have_link "Go back to #{legislation_annotation.title}", href: href - expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2) - expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1) - expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1) + within ".comment", text: "Parent" do + expect(page).to have_selector(".comment", count: 2) + end end scenario "Link to comment show" do @@ -71,20 +71,26 @@ describe "Commenting legislation questions" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: parent_comment.body do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -227,7 +233,7 @@ describe "Commenting legislation questions" do legislation_annotation.draft_version, legislation_annotation) - fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "Have you thought about...?" + fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" within "#comments" do @@ -261,7 +267,7 @@ describe "Commenting legislation questions" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end @@ -378,7 +384,7 @@ describe "Commenting legislation questions" do legislation_annotation.draft_version, legislation_annotation) - fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "Testing submit button!" + fill_in "Leave your comment", with: "Testing submit button!" click_button "Publish comment" # The button's text should now be "..." @@ -397,7 +403,7 @@ describe "Commenting legislation questions" do legislation_annotation.draft_version, legislation_annotation) - fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-legislation_annotation_#{legislation_annotation.id}" click_button "Publish comment" @@ -424,7 +430,7 @@ describe "Commenting legislation questions" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -460,7 +466,7 @@ describe "Commenting legislation questions" do legislation_annotation.draft_version, legislation_annotation) - fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-legislation_annotation_#{legislation_annotation.id}" click_button "Publish comment" @@ -487,7 +493,7 @@ describe "Commenting legislation questions" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your comment", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end @@ -661,7 +667,7 @@ describe "Commenting legislation questions" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "replying in single annotation thread" + fill_in "Leave your comment", with: "replying in single annotation thread" click_button "Publish reply" end @@ -700,7 +706,7 @@ describe "Commenting legislation questions" do end within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "replying in multiple annotation thread" + fill_in "Leave your comment", with: "replying in multiple annotation thread" click_button "Publish reply" end diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 67510cae2..87167555f 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -25,23 +25,23 @@ describe "Commenting legislation questions" do end scenario "Show" do - parent_comment = create(:comment, commentable: legislation_question) - first_child = create(:comment, commentable: legislation_question, parent: parent_comment) - second_child = create(:comment, commentable: legislation_question, parent: parent_comment) href = legislation_process_question_path(legislation_question.process, legislation_question) + parent_comment = create(:comment, commentable: legislation_question, body: "Parent") + create(:comment, commentable: legislation_question, parent: parent_comment, body: "First subcomment") + create(:comment, commentable: legislation_question, parent: parent_comment, body: "Last subcomment") visit comment_path(parent_comment) expect(page).to have_css(".comment", count: 3) - expect(page).to have_content parent_comment.body - expect(page).to have_content first_child.body - expect(page).to have_content second_child.body + expect(page).to have_content "Parent" + expect(page).to have_content "First subcomment" + expect(page).to have_content "Last subcomment" expect(page).to have_link "Go back to #{legislation_question.title}", href: href - expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2) - expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1) - expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1) + within ".comment", text: "Parent" do + expect(page).to have_selector(".comment", count: 2) + end end scenario "Link to comment show" do @@ -69,20 +69,26 @@ describe "Commenting legislation questions" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -196,7 +202,7 @@ describe "Commenting legislation questions" do login_as(user) visit legislation_process_question_path(legislation_question.process, legislation_question) - fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "Have you thought about...?" + fill_in "Leave your answer", with: "Have you thought about...?" click_button "Publish answer" within "#comments" do @@ -243,7 +249,7 @@ describe "Commenting legislation questions" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your answer", with: "It will be done next week." click_button "Publish reply" end @@ -342,7 +348,7 @@ describe "Commenting legislation questions" do login_as(user) visit legislation_process_question_path(legislation_question.process, legislation_question) - fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "Testing submit button!" + fill_in "Leave your answer", with: "Testing submit button!" click_button "Publish answer" # The button's text should now be "..." @@ -359,7 +365,7 @@ describe "Commenting legislation questions" do login_as(moderator.user) visit legislation_process_question_path(legislation_question.process, legislation_question) - fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I am moderating!" + fill_in "Leave your answer", with: "I am moderating!" check "comment-as-moderator-legislation_question_#{legislation_question.id}" click_button "Publish answer" @@ -383,7 +389,7 @@ describe "Commenting legislation questions" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your answer", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -415,7 +421,7 @@ describe "Commenting legislation questions" do login_as(admin.user) visit legislation_process_question_path(legislation_question.process, legislation_question) - fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I am your Admin!" + fill_in "Leave your answer", with: "I am your Admin!" check "comment-as-administrator-legislation_question_#{legislation_question.id}" click_button "Publish answer" @@ -439,7 +445,7 @@ describe "Commenting legislation questions" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your answer", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index ad4db74ec..298e8cb1f 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -64,20 +64,26 @@ describe "Commenting polls" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -191,7 +197,7 @@ describe "Commenting polls" do login_as(user) visit poll_path(poll) - fill_in "comment-body-poll_#{poll.id}", with: "Have you thought about...?" + fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" within "#comments" do @@ -223,7 +229,7 @@ describe "Commenting polls" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end @@ -334,7 +340,7 @@ describe "Commenting polls" do login_as(moderator.user) visit poll_path(poll) - fill_in "comment-body-poll_#{poll.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-poll_#{poll.id}" click_button "Publish comment" @@ -360,7 +366,7 @@ describe "Commenting polls" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -396,7 +402,7 @@ describe "Commenting polls" do login_as(admin.user) visit poll_path(poll) - fill_in "comment-body-poll_#{poll.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-poll_#{poll.id}" click_button "Publish comment" @@ -422,7 +428,7 @@ describe "Commenting polls" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your comment", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index e1b74613b..d23aad2b4 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -20,21 +20,21 @@ describe "Commenting proposals" do end scenario "Show" do - parent_comment = create(:comment, commentable: proposal) - first_child = create(:comment, commentable: proposal, parent: parent_comment) - second_child = create(:comment, commentable: proposal, parent: parent_comment) + parent_comment = create(:comment, commentable: proposal, body: "Parent") + create(:comment, commentable: proposal, parent: parent_comment, body: "First subcomment") + create(:comment, commentable: proposal, parent: parent_comment, body: "Last subcomment") visit comment_path(parent_comment) expect(page).to have_css(".comment", count: 3) - expect(page).to have_content parent_comment.body - expect(page).to have_content first_child.body - expect(page).to have_content second_child.body + expect(page).to have_content "Parent" + expect(page).to have_content "First subcomment" + expect(page).to have_content "Last subcomment" expect(page).to have_link "Go back to #{proposal.title}", href: proposal_path(proposal) - expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2) - expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1) - expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1) + within ".comment", text: "Parent" do + expect(page).to have_selector(".comment", count: 2) + end end scenario "Link to comment show" do @@ -62,20 +62,26 @@ describe "Commenting proposals" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -189,7 +195,7 @@ describe "Commenting proposals" do login_as(user) visit proposal_path(proposal) - fill_in "comment-body-proposal_#{proposal.id}", with: "Have you thought about...?" + fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" within "#comments" do @@ -221,7 +227,7 @@ describe "Commenting proposals" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end @@ -324,7 +330,7 @@ describe "Commenting proposals" do login_as(moderator.user) visit proposal_path(proposal) - fill_in "comment-body-proposal_#{proposal.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-proposal_#{proposal.id}" click_button "Publish comment" @@ -348,7 +354,7 @@ describe "Commenting proposals" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -380,7 +386,7 @@ describe "Commenting proposals" do login_as(admin.user) visit proposal_path(proposal) - fill_in "comment-body-proposal_#{proposal.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-proposal_#{proposal.id}" click_button "Publish comment" @@ -404,7 +410,7 @@ describe "Commenting proposals" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your comment", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index 4afc13ff1..a00698047 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -67,20 +67,26 @@ describe "Commenting topics from proposals" do expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).to have_content("1 response (collapse)") expect(page).to have_content("1 response (show)") expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content("1 response (collapse)", count: 2) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).to have_content("1 response (show)") @@ -210,7 +216,7 @@ describe "Commenting topics from proposals" do login_as(user) visit community_topic_path(community, topic) - fill_in "comment-body-topic_#{topic.id}", with: "Have you thought about...?" + fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" within "#comments" do @@ -247,7 +253,7 @@ describe "Commenting topics from proposals" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end @@ -363,7 +369,7 @@ describe "Commenting topics from proposals" do login_as(moderator.user) visit community_topic_path(community, topic) - fill_in "comment-body-topic_#{topic.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-topic_#{topic.id}" click_button "Publish comment" @@ -389,7 +395,7 @@ describe "Commenting topics from proposals" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -425,7 +431,7 @@ describe "Commenting topics from proposals" do login_as(admin.user) visit community_topic_path(community, topic) - fill_in "comment-body-topic_#{topic.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-topic_#{topic.id}" click_button "Publish comment" @@ -451,7 +457,7 @@ describe "Commenting topics from proposals" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your comment", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end @@ -625,17 +631,23 @@ describe "Commenting topics from budget investments" do expect(page).to have_css(".comment", count: 3) - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (collapse)" + end expect(page).to have_css(".comment", count: 2) expect(page).not_to have_content grandchild_comment.body - find("#comment_#{child_comment.id}_children_arrow").click + within ".comment .comment", text: "First subcomment" do + click_link text: "1 response (show)" + end expect(page).to have_css(".comment", count: 3) expect(page).to have_content grandchild_comment.body - find("#comment_#{parent_comment.id}_children_arrow").click + within ".comment", text: "Main comment" do + click_link text: "1 response (collapse)", match: :first + end expect(page).to have_css(".comment", count: 1) expect(page).not_to have_content child_comment.body @@ -764,7 +776,7 @@ describe "Commenting topics from budget investments" do login_as(user) visit community_topic_path(community, topic) - fill_in "comment-body-topic_#{topic.id}", with: "Have you thought about...?" + fill_in "Leave your comment", with: "Have you thought about...?" click_button "Publish comment" within "#comments" do @@ -801,7 +813,7 @@ describe "Commenting topics from budget investments" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end @@ -917,7 +929,7 @@ describe "Commenting topics from budget investments" do login_as(moderator.user) visit community_topic_path(community, topic) - fill_in "comment-body-topic_#{topic.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-topic_#{topic.id}" click_button "Publish comment" @@ -943,7 +955,7 @@ describe "Commenting topics from budget investments" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + fill_in "Leave your comment", with: "I am moderating!" check "comment-as-moderator-comment_#{comment.id}" click_button "Publish reply" end @@ -979,7 +991,7 @@ describe "Commenting topics from budget investments" do login_as(admin.user) visit community_topic_path(community, topic) - fill_in "comment-body-topic_#{topic.id}", with: "I am your Admin!" + fill_in "Leave your comment", with: "I am your Admin!" check "comment-as-administrator-topic_#{topic.id}" click_button "Publish comment" @@ -1005,7 +1017,7 @@ describe "Commenting topics from budget investments" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + fill_in "Leave your comment", with: "Top of the world!" check "comment-as-administrator-comment_#{comment.id}" click_button "Publish reply" end diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 7b23eea21..345cc33cc 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -443,7 +443,7 @@ describe "Emails" do click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week." + fill_in "Leave your comment", with: "It will be done next week." click_button "Publish reply" end