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

Update the option expectations with grouping argument

Dombi Attilacd61935a824d
diff --git a/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb b/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb
index 14a9582dad3..d4d045e135e 100644
--- a/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb
+++ b/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Components::Autocompleter
module NgSelectAutocompleteHelpers
def search_autocomplete(element, query:, results_selector: nil, wait_dropdown_open: true, wait_for_fetched_options: true)
@@ -55,9 +57,19 @@ module Components::Autocompleter
# Make sure the option is displayed under correct grouping title.
option_group = find(".ng-optgroup", text: grouping)
option = find(".ng-option.ng-option-child", text: option, visible: :visible)
- expect(option_group).to eq(
- option.find(:xpath, "preceding-sibling::*[contains(@class, 'ng-optgroup')][1]")
- )
+
+ expected_group = begin
+ option.find(:xpath,
+ "preceding-sibling::*[contains(@class, 'ng-optgroup')][1]",
+ wait: false)
+ rescue Capybara::ElementNotFound
+ raise "Unable to find the '.ng-optgroup' grouping for option '#{option.text}'"
+ end
+
+ expect(option_group).to eq(expected_group), <<~MSG
+ Expected the option '#{option.text}' to be under the group '#{option_group.text}',
+ but it was under '#{expected_group.text}' instead.
+ MSG
else
expect(page).to have_conditional_selector(present, ".ng-option", text: option)
end
@@ -75,6 +87,7 @@ module Components::Autocompleter
expect(page).to have_css("##{field_id} .ng-value-label", text:)
end
end
+
##
# Insert the query, typing
def ng_enter_query(element, query, wait_for_fetched_options: true)
diff --git a/spec/support/form_fields/primerized/autocomplete_field.rb b/spec/support/form_fields/primerized/autocomplete_field.rb
index 2239c2998e2..eede4cc6020 100644
--- a/spec/support/form_fields/primerized/autocomplete_field.rb
+++ b/spec/support/form_fields/primerized/autocomplete_field.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require_relative "form_field"
module FormFields
@@ -82,9 +84,19 @@ module FormFields
# Make sure the option is displayed under correct grouping title.
option_group = find(".ng-optgroup", text: grouping)
option = find(".ng-option.ng-option-child", text: option, visible: :visible)
- expect(option_group).to eq(
- option.find(:xpath, "preceding-sibling::*[contains(@class, 'ng-optgroup')][1]")
- )
+
+ expected_group = begin
+ option.find(:xpath,
+ "preceding-sibling::*[contains(@class, 'ng-optgroup')][1]",
+ wait: false)
+ rescue Capybara::ElementNotFound
+ raise "Unable to find the '.ng-optgroup' grouping for option '#{option.text}'"
+ end
+
+ expect(option_group).to eq(expected_group), <<~MSG
+ Expected the option '#{option.text}' to be under the group '#{option_group.text}',
+ but it was under '#{expected_group.text}' instead.
+ MSG
else
expect(page)
.to have_css(".ng-option", text: option, visible: :visible)