Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Write spec for flash notification to appear only in one window

Oliver Güntherc4bcd9746322
diff --git a/modules/meeting/app/components/meetings/header_component.html.erb b/modules/meeting/app/components/meetings/header_component.html.erb
index 95528e5eb7e..8219e286ac8 100644
--- a/modules/meeting/app/components/meetings/header_component.html.erb
+++ b/modules/meeting/app/components/meetings/header_component.html.erb
@@ -5,6 +5,7 @@
controller: "poll-for-changes",
poll_for_changes_updated_at_value: @meeting.updated_at.iso8601,
poll_for_changes_url_value: check_for_updates_meeting_path(@meeting),
+ poll_for_changes_interval_value: check_for_updates_interval,
}
)) do |header|
if show_state?
@@ -14,7 +15,7 @@
header.with_action_menu(menu_arguments: {},
button_arguments: { icon: "kebab-horizontal",
"aria-label": t("label_meeting_actions"),
- test_selector: 'op-meetings-header-action-trigger'}) do |menu|
+ test_selector: 'op-meetings-header-action-trigger' }) do |menu|
menu.with_item(label: t("label_meeting_edit_title"),
href: edit_meeting_path(@meeting),
content_arguments: {
diff --git a/modules/meeting/app/components/meetings/header_component.rb b/modules/meeting/app/components/meetings/header_component.rb
index 77a6de63cc9..9b76d604d5e 100644
--- a/modules/meeting/app/components/meetings/header_component.rb
+++ b/modules/meeting/app/components/meetings/header_component.rb
@@ -44,6 +44,11 @@ module Meetings
@state = fetch_or_fallback(STATE_OPTIONS, state)
end
+ # Define the interval so it can be overriden through tests
+ def check_for_updates_interval
+ 10_000
+ end
+
private
def show_state?
diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
new file mode 100644
index 00000000000..290ca058165
--- /dev/null
+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
@@ -0,0 +1,84 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# 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:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# 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.
+#++
+
+require "spec_helper"
+
+require_relative "../../support/pages/meetings/new"
+require_relative "../../support/pages/structured_meeting/show"
+
+RSpec.describe "Structured meetings CRUD",
+ :js,
+ :with_cuprite do
+ include Components::Autocompleter::NgSelectAutocompleteHelpers
+
+ shared_let(:project) { create(:project, enabled_module_names: %w[meetings work_package_tracking]) }
+ shared_let(:user) { create(:admin) }
+
+ current_user { user }
+ let(:new_page) { Pages::Meetings::New.new(project) }
+ let(:meeting) { create(:structured_meeting, project:, author: current_user) }
+ let(:show_page) { Pages::StructuredMeeting::Show.new(meeting) }
+
+ context "it shows an info toast when updated from a different page" do
+ before do
+ allow_any_instance_of(Meetings::HeaderComponent)
+ .to receive(:check_for_updates_interval)
+ .and_return(2000)
+ end
+
+ it do
+ # Visit the meeting on window1
+ show_page.visit!
+
+ # Visit meeting on window2 and do something
+ second_window = open_new_window
+ within_window(second_window) do
+ show_page.visit!
+
+ show_page.add_agenda_item do
+ fill_in "Title", with: "Update toast test item"
+ end
+ end
+
+ # Expect change in window1
+ flash_component = ".op-toast--wrapper.op-meeting-update-flash"
+ expect(page).to have_css(flash_component, wait: 5)
+ expect(page).to have_text I18n.t(:notice_meeting_updated)
+
+ # Expect no notification in window2
+ within_window(second_window) do
+ sleep 2
+ flash_component = ".op-toast--wrapper.op-meeting-update-flash"
+ expect(page).to have_no_css(flash_component)
+ expect(page).to have_no_text I18n.t(:notice_meeting_updated)
+ end
+
+ second_window.close
+ end
+ end
+end