diff --git a/app/assets/javascripts/initializers/initializeCommentsPage.js.erb b/app/assets/javascripts/initializers/initializeCommentsPage.js.erb index 9bdb61da8..92d26dbfd 100644 --- a/app/assets/javascripts/initializers/initializeCommentsPage.js.erb +++ b/app/assets/javascripts/initializers/initializeCommentsPage.js.erb @@ -173,6 +173,8 @@ function replaceActionButts(el) { } function warmNewCommentsArea() { + // Ignore when comment is created on /notifications. + if (window.location.pathname === "/notifications") { return } var path = '/stories/warm_comments'+ window.location.pathname window.fetch(path) } diff --git a/app/views/notifications/shared/_comment_box.html.erb b/app/views/notifications/shared/_comment_box.html.erb index 48c1b6c7c..093a5f882 100644 --- a/app/views/notifications/shared/_comment_box.html.erb +++ b/app/views/notifications/shared/_comment_box.html.erb @@ -15,11 +15,21 @@ " alt="Favorite heart button" /> <% if context == "moderation" && current_user.has_role?(:trusted) %> - - diff --git a/spec/system/notifications/notifications_page_spec.rb b/spec/system/notifications/notifications_page_spec.rb new file mode 100644 index 000000000..020f825c9 --- /dev/null +++ b/spec/system/notifications/notifications_page_spec.rb @@ -0,0 +1,76 @@ +require "rails_helper" + +RSpec.describe "Notifications page", type: :system, js: true do + let_it_be(:alex) { create(:user) } + let_it_be(:leslie) { create(:user) } + + before { sign_in alex } + + def validate_reply(id) + fill_in "comment-textarea-for-#{id}", with: "thanks i guess" + click_button("SUBMIT") + expect(page).to have_css("div.reply-sent-notice") + click_link("Check it out") + expect(page).to have_text(/thanks i guess/) + end + + it "shows 1 notification and disappear after clicking it" do + visit "/" + expect(page).to have_css("span#notifications-number", text: "1") + click_link("notifications-link") + expect(page).not_to have_css("span#notifications-number", text: "1") + end + + it "allows user to interact with replies" do + sidekiq_perform_enqueued_jobs do + article = create(:article, user: alex) + comment = create(:comment, commentable: article, user: alex) + reply = create(:comment, commentable: article, user: leslie, parent: comment) + Notification.send_new_comment_notifications_without_delay(reply) + end + + visit "/notifications" + expect(page).to have_css("div.single-notification") + click_button("heart") + expect(page).to have_css("img.reacted-emoji") + click_link("Reply") + validate_reply(leslie.comments.first.id) + end + + it "allows user to follow other users back" do + follow = leslie.follow(alex) + Notification.send_new_follower_notification_without_delay(follow, "Published") + visit "/notifications" + expect(page).to have_css("div.single-notification") + click_button("+ FOLLOW BACK") + expect(page).to have_text("FOLLOWING") + end + + context "when user is trusted" do + before do + dev_user = create(:user) + allow(User).to receive(:dev_account).and_return(dev_user) + alex.add_role :trusted + end + + def interact_with_each_emojis + %w[heart thumbsdown vomit].each do |emoji| + click_button(emoji) + expect(page).to have_css("img.reacted-emoji") + click_button(emoji) + expect(page).not_to have_css("img.reacted-emoji") + end + end + + it "allows trusted user to moderate content" do + article = create(:article, user: alex) + comment = nil + sidekiq_perform_enqueued_jobs { comment = create(:comment, commentable: article, user: leslie) } + visit "/notifications" + expect(page).to have_css("div.single-notification") + interact_with_each_emojis + click_link("Reply") + validate_reply(comment.id) + end + end +end