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

Fix flaky meeting spec partially

Christophe Bliard36b9e2517f10
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
index 2fc21de5c09..cc9e4cedb86 100644
--- 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
@@ -94,7 +94,7 @@ RSpec.describe "Meetings CRUD",
show_page.edit_agenda_item(item) do
fill_in "Title", with: "Updated title"
- click_on "Save"
+ show_page.click_save_and_wait_for_agenda_item_update
end
# Expect no notification in window1
@@ -285,6 +285,7 @@ RSpec.describe "Meetings CRUD",
next_occurrence_page.edit_agenda_item(item) do
fill_in "Title", with: "Edited title"
click_on "Save"
+ sleep 0.5 # wait for save to apply
end
next_occurrence_page.trigger_change_poll
diff --git a/modules/meeting/spec/features/structured_meetings/update_flash_shared_examples.rb b/modules/meeting/spec/features/structured_meetings/update_flash_shared_examples.rb
index 775bf296a43..eee406a1095 100644
--- a/modules/meeting/spec/features/structured_meetings/update_flash_shared_examples.rb
+++ b/modules/meeting/spec/features/structured_meetings/update_flash_shared_examples.rb
@@ -52,6 +52,7 @@ RSpec.shared_examples "no flash appears when interacting with backlog in multipl
show_page.edit_agenda_item(item) do
fill_in "Title", with: "Edited title"
click_on "Save"
+ sleep 1 # cannot use `show_page.click_save_and_wait_for_agenda_item_update` because of `travel_to`
end
show_page.trigger_change_poll
diff --git a/modules/meeting/spec/support/pages/meetings/show.rb b/modules/meeting/spec/support/pages/meetings/show.rb
index 64c8cfebd71..740f4a1de2e 100644
--- a/modules/meeting/spec/support/pages/meetings/show.rb
+++ b/modules/meeting/spec/support/pages/meetings/show.rb
@@ -33,6 +33,7 @@ require_relative "base"
module Pages::Meetings
class Show < Base
include ::Components::Autocompleter::NgSelectAutocompleteHelpers
+
attr_accessor :meeting
def initialize(meeting)
@@ -116,10 +117,12 @@ module Pages::Meetings
click_on type.model_name.human
end
+ created_id = nil
in_agenda_form do
yield
- click_on("Save") if save
+ created_id = click_save_and_wait_for_agenda_item_creation if save
end
+ expect(page).to have_css("#meeting-agenda-items-item-component-#{created_id}") if created_id
end
def expect_modal(...)
@@ -134,10 +137,12 @@ module Pages::Meetings
select_section_action(section, "Add #{type.model_name.human.downcase}")
within("#meeting-sections-show-component-#{section.id}") do
+ created_id = nil
in_agenda_form do
yield
- click_on("Save") if save
+ created_id = click_save_and_wait_for_agenda_item_creation if save
end
+ expect(page).to have_css("#meeting-agenda-items-item-component-#{created_id}") if created_id
end
end
@@ -370,13 +375,36 @@ module Pages::Meetings
select_backlog_action("Add #{type.model_name.human.downcase}")
within("#meeting-sections-backlogs-container-component") do
+ created_id = nil
in_agenda_form do
yield
- click_on("Save")
+ created_id = click_save_and_wait_for_agenda_item_creation
end
+ expect(page).to have_css("#meeting-agenda-items-item-component-#{created_id}")
end
end
+ def click_save_and_wait_for_agenda_item_creation
+ initial_db_items_count = MeetingAgendaItem.count
+ click_on("Save")
+
+ # wait for db save
+ wait_for { MeetingAgendaItem.count }.not_to eq(initial_db_items_count)
+
+ # return created item id so that caller can wait for it (can't do it here
+ # because of being "in_agenda_form" scope)
+ MeetingAgendaItem.maximum(:id)
+ end
+
+ # warning: does not work when using `travel_to` because time is stopped.
+ def click_save_and_wait_for_agenda_item_update
+ initial_db_items_updated_at = MeetingAgendaItem.order(:id).pluck(:updated_at)
+ click_on("Save")
+
+ # wait for db save
+ wait_for { MeetingAgendaItem.order(:id).pluck(:updated_at) }.not_to eq(initial_db_items_updated_at)
+ end
+
def select_backlog_action(action)
retry_block do
click_on_backlog_menu