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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Use retry_block around expected comments order
Oliver Günther12ccfb0cd71c
diff --git a/spec/features/activities/work_package/activities_spec.rb b/spec/features/activities/work_package/activities_spec.rbindex 2c0ef771d16..ef05adcbbad 100644--- a/spec/features/activities/work_package/activities_spec.rb+++ b/spec/features/activities/work_package/activities_spec.rb@@ -94,8 +94,11 @@ RSpec.describe "Work package activity", :js, :with_cuprite dolet(:work_package) { create(:work_package, project:, author: admin) }let(:first_comment) do- create(:work_package_journal, user: admin, notes: "First comment by admin", journable: work_package,- version: 2)+ create(:work_package_journal,+ user: admin,+ notes: "First comment by admin",+ journable: work_package,+ version: 2)endcontext "when project is public", with_settings: { login_required: false } do@@ -397,8 +400,11 @@ RSpec.describe "Work package activity", :js, :with_cuprite doit "shows the comment of another user without browser reload", :aggregate_failures do# simulate member creating a comment- first_journal = create(:work_package_journal, user: member, notes: "First comment by member", journable: work_package,- version: 2)+ first_journal = create(:work_package_journal,+ user: member,+ notes: "First comment by member",+ journable: work_package,+ version: 2)# the comment is shown without browser reloadactivity_tab.expect_journal_notes(text: "First comment by member")@@ -409,12 +415,14 @@ RSpec.describe "Work package activity", :js, :with_cuprite doactivity_tab.add_comment(text: "First comment by admin")- expect(activity_tab.get_all_comments_as_arrary).to eq([- "First comment by member",- "Second comment by member",- "Third comment by member",- "First comment by admin"- ])+ activity_tab.expect_comments_order(+ [+ "First comment by member",+ "Second comment by member",+ "Third comment by member",+ "First comment by admin"+ ]+ )first_journal.update!(notes: "First comment by member updated")@@ -620,23 +628,29 @@ RSpec.describe "Work package activity", :js, :with_cuprite doit "sorts the activities based on the sorting preference", :aggregate_failures do# expect the default sorting to be asc- expect(activity_tab.get_all_comments_as_arrary).to eq([- "First comment by admin",- "Second comment by admin"- ])+ activity_tab.expect_comments_order(+ [+ "First comment by admin",+ "Second comment by admin"+ ]+ )activity_tab.set_journal_sorting(:desc)- expect(activity_tab.get_all_comments_as_arrary).to eq([- "Second comment by admin",- "First comment by admin"- ])+ activity_tab.expect_comments_order(+ [+ "Second comment by admin",+ "First comment by admin"+ ]+ )activity_tab.set_journal_sorting(:asc)- expect(activity_tab.get_all_comments_as_arrary).to eq([- "First comment by admin",- "Second comment by admin"- ])+ activity_tab.expect_comments_order(+ [+ "First comment by admin",+ "Second comment by admin"+ ]+ )# expect a new comment to be added at the bottom# when the sorting is set to asc@@ -644,21 +658,25 @@ RSpec.describe "Work package activity", :js, :with_cuprite do# creating a new commentactivity_tab.add_comment(text: "Third comment by admin")- expect(activity_tab.get_all_comments_as_arrary).to eq([- "First comment by admin",- "Second comment by admin",- "Third comment by admin"- ])+ activity_tab.expect_comments_order(+ [+ "First comment by admin",+ "Second comment by admin",+ "Third comment by admin"+ ]+ )activity_tab.set_journal_sorting(:desc)activity_tab.add_comment(text: "Fourth comment by admin")- expect(activity_tab.get_all_comments_as_arrary).to eq([- "Fourth comment by admin",- "Third comment by admin",- "Second comment by admin",- "First comment by admin"- ])+ activity_tab.expect_comments_order(+ [+ "Fourth comment by admin",+ "Third comment by admin",+ "Second comment by admin",+ "First comment by admin"+ ]+ )endend@@ -668,8 +686,11 @@ RSpec.describe "Work package activity", :js, :with_cuprite docreate(:work_package_journal, user: admin, notes: "First comment by admin", journable: work_package, version: 2)endlet!(:journal_mentioning_admin) do- create(:work_package_journal, user: member, notes: "First comment by member mentioning @#{admin.name}",- journable: work_package, version: 3)+ create(:work_package_journal,+ user: member,+ notes: "First comment by member mentioning @#{admin.name}",+ journable: work_package,+ version: 3)endlet!(:notificaton_for_admin) docreate(:notification, recipient: admin, resource: work_package, journal: journal_mentioning_admin, reason: :mentioned)@@ -1021,8 +1042,11 @@ RSpec.describe "Work package activity", :js, :with_cuprite do# auto-scrolls to the bottom when a new comment is added by another user# add a commentlatest_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)+ create(:work_package_journal,+ user: member,+ notes: "New comment by member",+ journable: work_package,+ version: latest_journal_version + 1)# wait for the comment to be addedwait_for { page }.to have_test_selector("op-journal-notes-body", text: "New comment by member")sleep 1 # wait for auto scrolling to finish@@ -1420,7 +1444,7 @@ RSpec.describe "Work package activity", :js, :with_cuprite dobefore doallow_any_instance_of(WorkPackages::ActivitiesTabController) # rubocop:disable RSpec/AnyInstance.to receive(:create_journal_service_call)- .and_raise(StandardError.new("Test error"))+ .and_raise(StandardError.new("Test error"))endit "shows an error banner when the server returns an error" do@@ -1442,11 +1466,11 @@ RSpec.describe "Work package activity", :js, :with_cuprite dobefore doallow_any_instance_of(AddWorkPackageNoteService) # rubocop:disable RSpec/AnyInstance.to receive(:call)- .and_return(- ServiceResult.failure(errors: ActiveModel::Errors.new(Journal.new).tap do |e|- e.add(:notes, "Validation error")- end)- )+ .and_return(+ ServiceResult.failure(errors: ActiveModel::Errors.new(Journal.new).tap do |e|+ e.add(:notes, "Validation error")+ end)+ )endit "shows a validation error banner" do@@ -1474,7 +1498,7 @@ RSpec.describe "Work package activity", :js, :with_cuprite dobefore doallow_any_instance_of(WorkPackages::ActivitiesTabController) # rubocop:disable RSpec/AnyInstance.to receive(:update_journal_service_call)- .and_raise(StandardError.new("Test error"))+ .and_raise(StandardError.new("Test error"))endit "shows an error banner" do@@ -1492,11 +1516,11 @@ RSpec.describe "Work package activity", :js, :with_cuprite dobefore doallow_any_instance_of(Journals::UpdateService) # rubocop:disable RSpec/AnyInstance.to receive(:call)- .and_return(- ServiceResult.failure(errors: ActiveModel::Errors.new(Journal.new).tap do |e|- e.add(:notes, "Validation error")- end)- )+ .and_return(+ ServiceResult.failure(errors: ActiveModel::Errors.new(Journal.new).tap do |e|+ e.add(:notes, "Validation error")+ end)+ )endit "shows a validation error banner" dodiff --git a/spec/support/components/work_packages/activities.rb b/spec/support/components/work_packages/activities.rbindex 14fa1b4ae64..a8cc13c171b 100644--- a/spec/support/components/work_packages/activities.rb+++ b/spec/support/components/work_packages/activities.rb@@ -293,10 +293,16 @@ module Componentsendend- def get_all_comments_as_arrary+ def get_all_comments_as_arraypage.all(".work-packages-activities-tab-journals-item-component--journal-notes-body").map(&:text)end+ def expect_comments_order(items)+ retry_block do+ expect(get_all_comments_as_array).to eq(items)+ end+ end+def filter_journals(filter, default_sorting: User.current.preference&.comments_sorting || "desc")page.find_test_selector("op-wp-journals-filter-menu").click