Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

178 lines
5.4 KiB
Ruby
Raw Permalink Normal View History

2025-05-05 09:29:55 +02:00
# frozen_string_literal: true
2015-04-17 16:42:35 +01:00
#-- copyright
2020-01-15 11:31:26 +01:00
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
2015-04-17 16:42:35 +01:00
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
2021-01-13 17:47:45 +01:00
# Copyright (C) 2006-2013 Jean-Philippe Lang
2015-04-17 16:42:35 +01:00
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
2015-04-17 16:42:35 +01:00
#++
require "spec_helper"
2025-01-13 15:19:28 +01:00
RSpec.describe "messages", :js, :selenium do
2021-08-23 15:25:47 +02:00
let(:forum) do
2022-01-24 19:22:35 +01:00
create(:forum)
2021-08-23 15:25:47 +02:00
end
2018-07-09 13:12:45 +02:00
let(:notification_settings_all_false) do
NotificationSetting
.all_settings
.index_with(false)
end
2018-07-09 13:12:45 +02:00
let(:user) do
create(:user,
member_with_roles: { forum.project => role },
notification_settings: [
build(:notification_setting, **notification_settings_all_false, watched: true)
])
2018-07-09 13:12:45 +02:00
end
let(:other_user) do
2022-01-24 19:22:35 +01:00
create(:user,
member_with_roles: { forum.project => role },
notification_settings: [
build(:notification_setting, **notification_settings_all_false, watched: true)
]).tap do |u|
2021-08-23 15:25:47 +02:00
forum.watcher_users << u
end
2018-07-09 13:12:45 +02:00
end
2023-10-05 15:28:31 +02:00
let(:role) { create(:project_role, permissions: [:add_messages]) }
2018-07-09 13:12:45 +02:00
2019-03-12 10:34:45 +01:00
let(:index_page) { Pages::Messages::Index.new(forum.project) }
2015-04-17 16:42:35 +01:00
before do
2021-08-23 15:25:47 +02:00
other_user
2018-07-09 13:12:45 +02:00
login_as user
2015-04-17 16:42:35 +01:00
end
2021-08-23 15:25:47 +02:00
it "adding, checking replies, replying" do
2018-07-09 13:12:45 +02:00
index_page.visit!
click_link forum.name
2018-07-09 13:12:45 +02:00
create_page = index_page.click_create_message
2021-02-02 15:33:33 +01:00
SeleniumHubWaiter.wait
2018-07-09 13:12:45 +02:00
create_page.set_subject "The message is"
create_page.click_save
2024-10-01 20:54:01 +02:00
expect_flash(type: :error, message: "Content can't be blank")
2021-02-02 15:33:33 +01:00
SeleniumHubWaiter.wait
2018-07-09 13:12:45 +02:00
create_page.add_text "There is no message here"
perform_enqueued_jobs do
2021-08-23 15:25:47 +02:00
create_page.click_save
expect(page).to have_text "There is no message here"
show_page = Pages::Messages::Show.new(Message.last)
show_page.expect_current_path
2018-07-09 13:12:45 +02:00
show_page.expect_subject("The message is")
show_page.expect_content("There is no message here")
end
2018-07-09 13:12:45 +02:00
index_page.visit!
click_link forum.name
2018-07-09 13:12:45 +02:00
index_page.expect_listed(subject: "The message is",
replies: 0)
2021-08-23 15:25:47 +02:00
# Register as a watcher to later on get mails
click_link "Watch"
# Creating a message will have sent a mail to the other user who was already watching the forum
expect(ActionMailer::Base.deliveries.size)
.to be 1
expect(ActionMailer::Base.deliveries.last.to)
2023-07-19 09:42:12 +02:00
.to contain_exactly other_user.mail
2021-08-23 15:25:47 +02:00
expect(ActionMailer::Base.deliveries.last.subject)
.to include "The message is"
2018-07-09 13:12:45 +02:00
# Replying as other user
login_as other_user
show_page = Pages::Messages::Show.new(Message.last)
2018-07-09 13:12:45 +02:00
show_page.visit!
show_page.expect_no_replies
2021-08-23 15:25:47 +02:00
reply = perform_enqueued_jobs do
message = show_page.reply "But, but there should be one"
show_page.expect_current_path(message)
show_page.expect_num_replies(1)
2018-07-09 13:12:45 +02:00
show_page.expect_reply(subject: "RE: The message is",
content: "But, but there should be one")
2018-07-09 13:12:45 +02:00
message
end
2018-07-09 13:12:45 +02:00
index_page.visit!
click_link forum.name
2018-07-09 13:12:45 +02:00
index_page.expect_listed(subject: "The message is",
replies: 1,
last_message: "RE: The message is")
2021-08-23 15:25:47 +02:00
# Creating a reply will have sent a mail to the first user who was watching the forum
expect(ActionMailer::Base.deliveries.size)
.to be 2
expect(ActionMailer::Base.deliveries.last.to)
2023-07-19 09:42:12 +02:00
.to contain_exactly user.mail
2021-08-23 15:25:47 +02:00
expect(ActionMailer::Base.deliveries.last.subject)
.to include "RE: The message is"
2018-07-09 13:12:45 +02:00
# Quoting as first user again
login_as user
show_page.visit!
quote = show_page.quote(quoted_message: reply,
subject: "And now to something completely different",
content: "No, there really isn't\n\n")
show_page.expect_current_path(quote)
show_page.expect_num_replies(2)
show_page.expect_reply(reply: quote,
subject: "And now to something completely different",
content: "No, there really isn't")
2024-01-04 17:01:17 +01:00
expect(page).to have_css("blockquote", text: "But, but there should be one")
2018-07-09 13:12:45 +02:00
2023-07-19 09:42:12 +02:00
# Quoting the first message
show_page.quote(subject: "Also quoting the first message",
2023-07-19 09:42:12 +02:00
content: "Should also work")
show_page.expect_num_replies(3)
2018-07-09 13:12:45 +02:00
index_page.visit!
click_link forum.name
2018-07-09 13:12:45 +02:00
index_page.expect_listed(subject: "The message is",
2023-07-19 09:42:12 +02:00
replies: 3,
last_message: "Also quoting the first message")
2015-04-17 16:42:35 +01:00
end
end