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
Improve month selection for date picker tests
Christophe Bliardeaba87906038
diff --git a/spec/support/components/datepicker/month_range_selection.rb b/spec/support/components/datepicker/month_range_selection.rbindex daa817a0494..1051da0d9d7 100644--- a/spec/support/components/datepicker/month_range_selection.rb+++ b/spec/support/components/datepicker/month_range_selection.rb@@ -5,24 +5,39 @@ module Componentsdef select_month(month)month = Date::MONTHNAMES.index(month) if month.is_a?(String)retry_block do- # This is for a double-month datepicker- current_month_element = flatpickr_container.all(".cur-month", wait: 0).first- current_month = if current_month_element- Date::MONTHNAMES.index(current_month_element.text)- else- # This is for a single-month datepicker- flatpickr_container.first(".flatpickr-monthDropdown-months").value.to_i + 1- end+ current_month = current_month_indexif current_month < monthmonth_difference = month - current_monthmonth_difference.times { flatpickr_container.find(".flatpickr-next-month").click }- flatpickr_container.first(".flatpickr-monthDropdown-months").value.to_i + 1elsif current_month > monthmonth_difference = current_month - monthmonth_difference.times { flatpickr_container.find(".flatpickr-prev-month").click }- flatpickr_container.first(".flatpickr-monthDropdown-months").value.to_i + 1end+ current_month_index+ end+ end++ # Returns the index of the current month.+ #+ # 1 for January, 2 for February, etc.+ #+ # When multiple months are displayed, it returns the value for the first one+ # displayed.+ def current_month_index+ # ensure flatpicker month is displayed+ flatpickr_container.first(".flatpickr-month")++ # Checking if showing multiple months or using `monthSelectorType: "static"`,+ # in which case the month is simply some static text in a span instead of a+ # `<select>` dropdown input.+ if flatpickr_container.all(".cur-month", wait: 0).any?+ # Get value from month name and convert to index+ current_month_element = flatpickr_container.first(".cur-month")+ Date::MONTHNAMES.index(current_month_element.text)+ else+ # get value from select dropdown value+ flatpickr_container.first(".flatpickr-monthDropdown-months").value.to_i + 1endendend