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 feature specs

Christophe Bliardf1cc39aa3b10
diff --git a/spec/features/work_packages/details/relations/primerized_relations_spec.rb b/spec/features/work_packages/details/relations/primerized_relations_spec.rb
index 5e640f7d860..463626bb438 100644
--- a/spec/features/work_packages/details/relations/primerized_relations_spec.rb
+++ b/spec/features/work_packages/details/relations/primerized_relations_spec.rb
@@ -156,12 +156,13 @@ RSpec.describe "Primerized work package relations tab",
expect(page).to have_css(relations_panel_selector)
- tabs.expect_counter("relations", 7)
+ tabs.expect_counter("relations", 8)
relations_tab.expect_not_closest_relation(relation_follows1)
relations_tab.expect_closest_relation(relation_follows2)
relations_tab.expect_relation(relation_relates)
relations_tab.expect_relation(relation_blocked)
+ relations_tab.expect_relation(parent_work_package)
# Relations not visible due to lack of permissions on the project
relations_tab.expect_ghost_relation(restricted_relation_relates)
@@ -197,7 +198,7 @@ RSpec.describe "Primerized work package relations tab",
expect { relation_follows1.reload }.to raise_error(ActiveRecord::RecordNotFound)
- tabs.expect_counter("relations", 6)
+ tabs.expect_counter("relations", 7)
# Relations not visible due to lack of permissions on the project
relations_tab.expect_ghost_relation(restricted_relation_relates)
@@ -212,7 +213,7 @@ RSpec.describe "Primerized work package relations tab",
relations_tab.remove_child(child_wp)
expect(child_wp.reload.parent).to be_nil
- tabs.expect_counter("relations", 6)
+ tabs.expect_counter("relations", 7)
# Relations not visible due to lack of permissions on the project
relations_tab.expect_ghost_relation(restricted_relation_relates)
@@ -237,7 +238,7 @@ RSpec.describe "Primerized work package relations tab",
expect(relation_row).to have_text("5 days")
# Unchanged
- tabs.expect_counter("relations", 7)
+ tabs.expect_counter("relations", 8)
relations_tab.expect_ghost_relation(restricted_relation_relates)
relations_tab.expect_ghost_relation(restricted_child_work_package)
@@ -248,7 +249,7 @@ RSpec.describe "Primerized work package relations tab",
expect(relation_row).to have_text("And they can be edited!")
# Unchanged
- tabs.expect_counter("relations", 7)
+ tabs.expect_counter("relations", 8)
# Relations not visible due to lack of permissions on the project
relations_tab.expect_ghost_relation(restricted_relation_relates)
@@ -324,7 +325,7 @@ RSpec.describe "Primerized work package relations tab",
relations_tab.expect_relation(wp_successor)
# Bumped by one
- tabs.expect_counter("relations", 8)
+ tabs.expect_counter("relations", 9)
# Relation is created
expect(Relation.follows.where(from: wp_successor, to: work_package)).to exist
@@ -355,7 +356,7 @@ RSpec.describe "Primerized work package relations tab",
relations_tab.expect_relation(wp_blocks)
# Bumped by one
- tabs.expect_counter("relations", 8)
+ tabs.expect_counter("relations", 9)
# Relation is created
expect(Relation.blocks.where(from: wp_blocks, to: work_package)).to exist
end
@@ -388,13 +389,13 @@ RSpec.describe "Primerized work package relations tab",
wait_for_network_idle
- tabs.expect_counter("relations", 7)
+ tabs.expect_counter("relations", 8)
relations_tab.add_existing_child(not_child_yet_wp)
relations_tab.expect_child(not_child_yet_wp)
# Bumped by one
- tabs.expect_counter("relations", 8)
+ tabs.expect_counter("relations", 9)
# Child relation is created
expect(not_child_yet_wp.reload.parent).to eq work_package
@@ -455,7 +456,7 @@ RSpec.describe "Primerized work package relations tab",
wait_for_network_idle
- tabs.expect_counter("relations", 7)
+ tabs.expect_counter("relations", 8)
relations_tab.expect_no_add_relation_button
relations_tab.expect_no_relatable_action_menu(wp_related)
@@ -472,7 +473,7 @@ RSpec.describe "Primerized work package relations tab",
wait_for_network_idle
- tabs.expect_counter("relations", 7)
+ tabs.expect_counter("relations", 8)
# The menu is shown as the user can add a relation
relations_tab.expect_add_relation_button
@@ -527,7 +528,7 @@ RSpec.describe "Primerized work package relations tab",
wait_for_network_idle
- tabs.expect_counter("relations", 7)
+ tabs.expect_counter("relations", 8)
# The menu is shown as the user can add a child
relations_tab.expect_add_relation_button
diff --git a/spec/support/matchers/has_test_selector.rb b/spec/support/matchers/has_test_selector.rb
index bcef321cd64..f2c953d7dad 100644
--- a/spec/support/matchers/has_test_selector.rb
+++ b/spec/support/matchers/has_test_selector.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -29,15 +31,44 @@ RSpec::Matchers.define :have_test_selector do |expected, **args|
include TestSelectorFinders
match do |page|
- page.has_selector?(test_selector(expected), **args)
+ @actual_args = args.dup
+ @selector_name = test_selector(expected)
+ page.has_selector?(@selector_name, **args)
end
match_when_negated do |page|
- page.has_no_selector?(test_selector(expected), **args)
+ @actual_args = args.dup
+ @selector_name = test_selector(expected)
+ page.has_no_selector?(@selector_name, **args)
end
- failure_message do
- "expected page to have test selector #{expected}"
+ failure_message do |page|
+ message = "expected page to have test selector #{expected}"
+
+ if @actual_args.key?(:text)
+ message << " with text #{@actual_args[:text].to_s.inspect}"
+ end
+
+ # Try to find the actual element without text filter to provide more context
+ found_elements = []
+ begin
+ args_without_text = @actual_args.dup
+ args_without_text.delete(:text)
+
+ # Only search for visible elements with a short timeout
+ search_args = args_without_text.merge(visible: true, wait: 0)
+ page.all(@selector_name, **search_args).each do |element| # rubocop:disable Rails/FindEach
+ found_elements << element.text.to_s.strip
+ end
+
+ if found_elements.any?
+ message << ". Also found: #{found_elements.map(&:inspect).join(', ')}, which matched the selector but not all filters."
+ end
+ rescue StandardError
+ # Ignore errors during the additional context gathering
+ end
+
+ message
end
failure_message_when_negated do