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

[Op#40437]: wait for activity tab comments to load (#17055)

Kabiru Mwenja32f9763c23f3
diff --git a/app/components/work_packages/activities_tab/journals/index_component.html.erb b/app/components/work_packages/activities_tab/journals/index_component.html.erb
index df3573e39ee..aa761592d11 100644
--- a/app/components/work_packages/activities_tab/journals/index_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/index_component.html.erb
@@ -1,6 +1,6 @@
<%=
component_wrapper(class: "work-packages-activities-tab-journals-index-component") do
- flex_layout do |journals_index_wrapper_container|
+ flex_layout(data: { test_selector: "op-wp-journals-#{filter}-#{journal_sorting}" }) do |journals_index_wrapper_container|
journals_index_wrapper_container.with_row(
classes: "work-packages-activities-tab-journals-index-component--journals-inner-container",
mb: inner_container_margin_bottom
diff --git a/spec/features/activities/work_package/activities_spec.rb b/spec/features/activities/work_package/activities_spec.rb
index 2ef9fdb1161..8a9ec6b0c85 100644
--- a/spec/features/activities/work_package/activities_spec.rb
+++ b/spec/features/activities/work_package/activities_spec.rb
@@ -370,7 +370,7 @@ RSpec.describe "Work package activity", :js, :with_cuprite, with_flag: { primeri
version: 2)
# the comment is shown without browser reload
- activity_tab.expect_journal_notes(text: "First comment by member")
+ wait_for { page }.to have_test_selector("op-journal-notes-body", text: "First comment by member")
# simulate comments made within the polling interval
create(:work_package_journal, user: member, notes: "Second comment by member", journable: work_package, version: 3)
@@ -387,10 +387,8 @@ RSpec.describe "Work package activity", :js, :with_cuprite, with_flag: { primeri
first_journal.update!(notes: "First comment by member updated")
- sleep 1 # avoid flaky test
-
# properly updates the comment when the comment is updated
- activity_tab.expect_journal_notes(text: "First comment by member updated")
+ wait_for { page }.to have_test_selector("op-journal-notes-body", text: "First comment by member updated")
end
end
@@ -872,7 +870,6 @@ RSpec.describe "Work package activity", :js, :with_cuprite, with_flag: { primeri
# auto-scrolls to the bottom when a new comment is added by the user
# add a comment
activity_tab.add_comment(text: "New comment by admin")
- activity_tab.expect_journal_notes(text: "New comment by admin") # wait for the comment to be added
activity_tab.expect_journal_container_at_bottom
# auto-scrolls to the bottom when a new comment is added by another user
@@ -880,7 +877,8 @@ RSpec.describe "Work package activity", :js, :with_cuprite, with_flag: { primeri
latest_journal_version = work_package.journals.last.version
create(:work_package_journal, user: member, notes: "New comment by member", journable: work_package,
version: latest_journal_version + 1)
- activity_tab.expect_journal_notes(text: "New comment by member") # wait for the comment to be added
+ # wait for the comment to be added
+ wait_for { page }.to have_test_selector("op-journal-notes-body", text: "New comment by member")
sleep 1 # wait for auto scrolling to finish
activity_tab.expect_journal_container_at_bottom
end
diff --git a/spec/support/components/work_packages/activities.rb b/spec/support/components/work_packages/activities.rb
index b6848487046..cab633769ee 100644
--- a/spec/support/components/work_packages/activities.rb
+++ b/spec/support/components/work_packages/activities.rb
@@ -32,6 +32,7 @@ module Components
include Capybara::DSL
include Capybara::RSpecMatchers
include RSpec::Matchers
+ include RSpec::Wait
attr_reader :work_package
@@ -144,7 +145,6 @@ module Components
end
def add_comment(text: nil, save: true)
- # TODO: get rid of static sleep
sleep 1 # otherwise the stimulus component is not mounted yet and the click does not work
if page.find_test_selector("op-open-work-package-journal-form-trigger")
@@ -160,7 +160,8 @@ module Components
if save
page.within_test_selector("op-wp-journals-container") do
- expect(page).to have_text(text)
+ # wait for the comment to be loaded
+ wait_for { page }.to have_test_selector("op-journal-notes-body", text:)
end
end
end
@@ -175,12 +176,12 @@ module Components
page.find_test_selector("op-submit-work-package-journal-form").click
end
- expect(page).to have_text(text)
+ # wait for the comment to be loaded
+ wait_for { page }.to have_test_selector("op-journal-notes-body", text:)
end
end
def quote_comment(journal)
- # TODO: get rid of static sleep
sleep 1 # otherwise the stimulus component is not mounted yet and the click does not work
within_journal_entry(journal) do
@@ -199,7 +200,7 @@ module Components
page.all(".work-packages-activities-tab-journals-item-component--journal-notes-body").map(&:text)
end
- def filter_journals(filter)
+ def filter_journals(filter, default_sorting: User.current.preference&.comments_sorting || "desc")
page.find_test_selector("op-wp-journals-filter-menu").click
case filter
@@ -211,10 +212,11 @@ module Components
page.find_test_selector("op-wp-journals-filter-show-only-changes").click
end
- sleep 1 # wait for the journals to be reloaded, TODO: get rid of static sleep
+ # Ensure the journals are reloaded
+ wait_for { page }.to have_test_selector("op-wp-journals-#{filter}-#{default_sorting}")
end
- def set_journal_sorting(sorting)
+ def set_journal_sorting(sorting, default_filter: :all)
page.find_test_selector("op-wp-journals-sorting-menu").click
case sorting
@@ -224,7 +226,7 @@ module Components
page.find_test_selector("op-wp-journals-sorting-desc").click
end
- sleep 1 # wait for the journals to be reloaded, TODO: get rid of static sleep
+ wait_for { page }.to have_test_selector("op-wp-journals-#{default_filter}-#{sorting}")
end
end
end
diff --git a/spec/support/components/work_packages/emoji_reactions.rb b/spec/support/components/work_packages/emoji_reactions.rb
index ce4e53197cf..0917e203e52 100644
--- a/spec/support/components/work_packages/emoji_reactions.rb
+++ b/spec/support/components/work_packages/emoji_reactions.rb
@@ -29,8 +29,6 @@
module Components
module WorkPackages
class EmojiReactions < Activities
- include RSpec::Wait
-
def add_first_emoji_reaction_for_journal(journal, emoji)
within_journal_entry(journal) do
click_on "Add reaction"