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 specs

Dombi Attila01fcdcd23afc
diff --git a/app/views/filters/_autocomplete.html.erb b/app/views/filters/_autocomplete.html.erb
index ee53c9902bf..107d7cae215 100644
--- a/app/views/filters/_autocomplete.html.erb
+++ b/app/views/filters/_autocomplete.html.erb
@@ -6,6 +6,7 @@
multipleAsSeparateInputs: false,
inputValue: filter.values,
appendTo: "body",
+ id: "#{filter.name}_value",
hiddenFieldAction: "change->filter--filters-form#autocompleteSendForm"
# Set on the template as there is a timing issue where the
# angular component is not yet ready in the DOM and hence
@@ -13,11 +14,9 @@
# of the #connect lifecycle hook of the filter--filters-form
# Stimulus controller.
}.merge(autocomplete_options.except(:component)),
- id: "#{filter.name}_value",
data: {
"filter-autocomplete": true,
"filter--filters-form-target": "filterValueContainer",
"filter-name": filter.name
- }
- %>
+ } %>
</div>
diff --git a/spec/features/projects/lists/filters_spec.rb b/spec/features/projects/lists/filters_spec.rb
index 55d5faa41bc..f120924c86f 100644
--- a/spec/features/projects/lists/filters_spec.rb
+++ b/spec/features/projects/lists/filters_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2010-2024 the OpenProject GmbH
@@ -454,41 +456,17 @@ RSpec.describe "Projects list filters", :js, with_settings: { login_required?: f
select_value_id = "#{list_custom_field.column_name}_value"
within(cf_filter) do
- # Initial filter is a 'single select'
- expect(cf_filter.find(:select, select_value_id)).not_to be_multiple
- click_on "Toggle multiselect"
- # switching to multiselect keeps the current selection
- expect(cf_filter.find(:select, select_value_id)).to be_multiple
- expect(cf_filter).to have_select(select_value_id, selected: list_custom_field.possible_values[2].value)
-
- select list_custom_field.possible_values[3].value, from: select_value_id
- end
- wait_for_reload
-
- cf_filter = page.find("li[data-filter-name='#{list_custom_field.column_name}']")
- within(cf_filter) do
- # Query has two values for that filter, so it should show a 'multi select'.
- expect(cf_filter.find(:select, select_value_id)).to be_multiple
- expect(cf_filter)
- .to have_select(select_value_id,
- selected: [list_custom_field.possible_values[2].value,
- list_custom_field.possible_values[3].value])
-
- # switching to single select keeps the first selection
- select list_custom_field.possible_values[1].value, from: select_value_id
- unselect list_custom_field.possible_values[2].value, from: select_value_id
-
- click_on "Toggle multiselect"
- expect(cf_filter.find(:select, select_value_id)).not_to be_multiple
- expect(cf_filter).to have_select(select_value_id, selected: list_custom_field.possible_values[1].value)
- expect(cf_filter).to have_no_select(select_value_id, selected: list_custom_field.possible_values[3].value)
+ projects_page.expect_ng_value_label(select_value_id, list_custom_field.possible_values[2].value)
+ projects_page.set_autocomplete_filter list_custom_field.possible_values[3].value, clear: false
end
wait_for_reload
cf_filter = page.find("li[data-filter-name='#{list_custom_field.column_name}']")
within(cf_filter) do
- # Query has one value for that filter, so it should show a 'single select'.
- expect(cf_filter.find(:select, select_value_id)).not_to be_multiple
+ # Query has two values for that filter.
+ projects_page.expect_ng_value_label(select_value_id,
+ [list_custom_field.possible_values[2].value,
+ list_custom_field.possible_values[3].value])
end
# CF date filter work (at least for one operator)
diff --git a/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb b/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb
index 9666b147ddf..63ef8dcc9d6 100644
--- a/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb
+++ b/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb
@@ -35,7 +35,9 @@ module Components::Autocompleter
retry_block do
if results_selector
results_selector = "#{results_selector} .ng-dropdown-panel" if results_selector == "body"
- page.find(results_selector, wait: 5)
+ within_window(current_window) do
+ page.find(results_selector, wait: 5)
+ end
else
within(element) do
page.find("ng-select .ng-dropdown-panel", wait: 5)
@@ -59,6 +61,11 @@ module Components::Autocompleter
end
end
+ def expect_ng_value_label(field_id, labels)
+ Array(labels).each do |text|
+ 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)
@@ -96,8 +103,10 @@ module Components::Autocompleter
##
# clear the ng select field
- def ng_select_clear(from_element)
- from_element.find(".ng-clear-wrapper", visible: :all).click
+ def ng_select_clear(from_element, raise_on_missing: true)
+ if raise_on_missing || from_element.has_css?(".ng-clear-wrapper", visible: :all, wait: 1)
+ from_element.find(".ng-clear-wrapper", visible: :all).click
+ end
end
def select_autocomplete(element,
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index ff2119dcb97..f6f801624ed 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -273,12 +273,14 @@ module Pages
if boolean_filter?(name)
set_toggle_filter(values)
+ elsif autocomplete_filter?(selected_filter)
+ set_autocomplete_filter(values)
elsif name == "created_at"
select(human_operator, from: "operator")
set_created_at_filter(human_operator, values, send_keys:)
- elsif /cf_\d+/.match?(name)
+ elsif date_filter?(selected_filter) && human_operator == "on"
select(human_operator, from: "operator")
- set_custom_field_filter(selected_filter, human_operator, values)
+ set_date_filter(values, send_keys)
end
end
end
@@ -288,8 +290,8 @@ module Pages
within(selected_filter) do
find('[data-filter-autocomplete="true"]').click
- visible_user_auto_completer_options
end
+ visible_user_auto_completer_options
end
def select_filter(name, human_name)
@@ -347,19 +349,13 @@ module Pages
end
end
- def set_custom_field_filter(selected_filter, human_operator, values, send_keys: false)
- if selected_filter.has_css?('[data-filter-autocomplete="true"]', wait: 0)
- set_autocomplete_filter(values)
- elsif selected_filter[:"data-filter-type"] == "list_optional" && values.size == 1
- set_list_filter(values)
- elsif selected_filter[:"data-filter-type"] == "date" && human_operator == "on"
- set_date_filter(values, send_keys)
- end
- end
+ def set_autocomplete_filter(values, clear: true)
+ element = find('[data-filter-autocomplete="true"]')
- def set_autocomplete_filter(values)
- values.each do |query|
- select_autocomplete find('[data-filter-autocomplete="true"]'),
+ ng_select_clear(element, raise_on_missing: false) if clear
+
+ Array(values).each do |query|
+ select_autocomplete element,
query:,
results_selector: "body"
end
@@ -660,6 +656,14 @@ module Pages
%w[active member_of favored public templated].include?(filter.to_s)
end
+ def autocomplete_filter?(filter)
+ filter.has_css?('[data-filter-autocomplete="true"]', wait: 0)
+ end
+
+ def date_filter?(filter)
+ filter[:"data-filter-type"] == "date"
+ end
+
def submenu
Components::Submenu.new
end