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
Fix lifecycle modal datepicker spec not displaying the expected date.
Dombi Attila84bbf8d54955
diff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rbindex 7d158a3be42..960f6e7ee3f 100644--- a/spec/support/components/datepicker/datepicker.rb+++ b/spec/support/components/datepicker/datepicker.rb@@ -180,6 +180,7 @@ module Components### Expect the given date to be visible and a non-working daydef expect_non_working(date)+ ensure_date_is_displayed(date) unless displays_date?(date)label = date.strftime("%B %-d, %Y")expect(page).to have_css(".flatpickr-day.flatpickr-non-working-day[aria-label='#{label}']")end@@ -187,6 +188,7 @@ module Components### Expect the given date to be visible and a working daydef expect_working(date)+ ensure_date_is_displayed(date) unless displays_date?(date)label = date.strftime("%B %-d, %Y")expect(page).to have_css(".flatpickr-day:not(.flatpickr-non-working-day)[aria-label='#{label}']")end@@ -194,6 +196,7 @@ module Components### Expect the given date to be visible and disableddef expect_disabled(date)+ ensure_date_is_displayed(date) unless displays_date?(date)label = date.strftime("%B %-d, %Y")expect(page).to have_css(".flatpickr-day.flatpickr-disabled[aria-label='#{label}']," \".flatpickr-day.flatpickr-non-working-day[aria-label='#{label}']")@@ -202,6 +205,7 @@ module Components### Expect the given date to be visible and enableddef expect_not_disabled(date)+ ensure_date_is_displayed(date) unless displays_date?(date)label = date.strftime("%B %-d, %Y")expect(page).to have_css(".flatpickr-day:not(.flatpickr-disabled):not(.flatpickr-non-working-day)[aria-label='#{label}']")end@@ -215,6 +219,11 @@ module Componentspage.has_css?(".flatpickr-prev-month")end+ def ensure_date_is_displayed(date)+ select_year(date.year)+ select_month(date.month)+ end+protecteddef save_button_labeldiff --git a/spec/support/components/datepicker/datepicker_modal.rb b/spec/support/components/datepicker/datepicker_modal.rbindex 235eae59a9d..e4c340acf3c 100644--- a/spec/support/components/datepicker/datepicker_modal.rb+++ b/spec/support/components/datepicker/datepicker_modal.rb@@ -18,5 +18,46 @@ module Componentsdef has_day_selected?(value)flatpickr_container.has_css?(".flatpickr-day.selected", text: value, wait: 1)end++ ##+ # Select month from datepicker+ def select_month(month)+ month = Date::MONTHNAMES.index(month) if month.is_a?(String)+ retry_block do+ current_month = current_month_index++ if current_month < month+ month_difference = month - current_month+ month_difference.times { flatpickr_container.find(".flatpickr-next-month").click }+ elsif current_month > month+ month_difference = current_month - month+ month_difference.times { flatpickr_container.find(".flatpickr-prev-month").click }+ end+ 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 + 1+ end+ endendend