From f15991dd3e76b93eddf22e705c90fc7a60ead751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 27 Mar 2025 17:06:17 +0100 Subject: [PATCH] Simplify tests replying to a comment We were using the `reply_to` method in some places, but not in others. --- spec/shared/system/notifiable_in_app.rb | 26 ++----------------------- spec/support/common_actions/comments.rb | 12 +++++++++--- spec/system/comments_spec.rb | 16 +-------------- 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/spec/shared/system/notifiable_in_app.rb b/spec/shared/system/notifiable_in_app.rb index 6efd98e0b..8f8af11fd 100644 --- a/spec/shared/system/notifiable_in_app.rb +++ b/spec/shared/system/notifiable_in_app.rb @@ -51,18 +51,7 @@ shared_examples "notifiable in-app" do |factory_name| scenario "A user replied to my comment" do comment = create(:comment, commentable: notifiable, user: author) - login_as(create(:user, :verified)) - visit path_for(notifiable) - - click_link "Reply" - within "#js-comment-form-comment_#{comment.id}" do - fill_in comment_body(notifiable), with: "I replied to your comment" - click_button "Publish reply" - end - - within "#comment_#{comment.id}" do - expect(page).to have_content "I replied to your comment" - end + reply_to(comment, with: "I replied to your comment", replier: create(:user, :verified)) logout login_as author @@ -120,18 +109,7 @@ shared_examples "notifiable in-app" do |factory_name| scenario "Author replied to his own comment" do comment = create(:comment, commentable: notifiable, user: author) - login_as author - visit path_for(notifiable) - - click_link "Reply" - within "#js-comment-form-comment_#{comment.id}" do - fill_in comment_body(notifiable), with: "I replied to my own comment" - click_button "Publish reply" - end - - within "#comment_#{comment.id}" do - expect(page).to have_content "I replied to my own comment" - end + reply_to(comment, with: "I replied to my own comment", replier: author) within("#notifications") do click_link "You don't have new notifications" diff --git a/spec/support/common_actions/comments.rb b/spec/support/common_actions/comments.rb index c6c7bcbe8..5702789d2 100644 --- a/spec/support/common_actions/comments.rb +++ b/spec/support/common_actions/comments.rb @@ -4,11 +4,17 @@ module Comments visit polymorphic_path(comment.commentable) - click_link "Reply" + within "#comment_#{comment.id}" do + click_link "Reply" + end + within "#js-comment-form-comment_#{comment.id}" do - fill_in "Leave your comment", with: with + fill_in comment_body(comment.commentable), with: with click_button "Publish reply" end - expect(page).to have_content with + + within "#comment_#{comment.id}" do + expect(page).to have_content with + end end end diff --git a/spec/system/comments_spec.rb b/spec/system/comments_spec.rb index 0702c1b2c..a5676fd3c 100644 --- a/spec/system/comments_spec.rb +++ b/spec/system/comments_spec.rb @@ -383,21 +383,7 @@ describe "Comments" do scenario "Reply" do comment = create(:comment, commentable: resource) - login_as(user) - visit polymorphic_path(resource) - - within "#comment_#{comment.id}" do - click_link "Reply" - end - - within "#js-comment-form-comment_#{comment.id}" do - fill_in fill_text, with: "It will be done next week." - click_button "Publish reply" - end - - within "#comment_#{comment.id}" do - expect(page).to have_content "It will be done next week." - end + reply_to(comment, with: "It will be done next week.", replier: user) expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}" end