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
Add functionality to work package datepicker
Oliver Günthera10643070488
diff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rbindex 48d5fdf80e3..312db444abd 100644--- a/spec/support/components/datepicker/datepicker.rb+++ b/spec/support/components/datepicker/datepicker.rb@@ -9,44 +9,31 @@ module Componentsenddef container- page.find("#{context_selector} .flatpickr-calendar")+ page.find(context_selector)+ end++ def flatpickr_container+ container.find(".flatpickr-calendar")enddef expect_visible- expect(container).to be_present+ expect(flatpickr_container).to be_presentend### Select year from inputdef select_year(value)- container+ flatpickr_container.first('.numInput.cur-year').set valueend### Select month from datepicker- def select_month(month, multiple_month_shown = false)- if multiple_month_shown- month = Date::MONTHNAMES.index(month) if month.is_a?(String)- current_month = Date::MONTHNAMES.index(container.first('.cur-month').text)-- if current_month < month- while current_month < month- container.find('.flatpickr-next-month').click- current_month = Date::MONTHNAMES.index(container.first('.cur-month').text)- end- elsif current_month > month- while current_month > month- container.find('.flatpickr-prev-month').click- current_month = Date::MONTHNAMES.index(container.first('.cur-month').text)- end- end- else- container- .first('.flatpickr-monthDropdown-months option', text: month, visible: :all)- .select_option- end+ def select_month(month)+ flatpickr_container+ .first('.flatpickr-monthDropdown-months option', text: month, visible: :all)+ .select_optionend##@@ -57,7 +44,7 @@ module Componentsendretry_block do- container+ flatpickr_container.first('.flatpickr-days .flatpickr-day:not(.nextMonthDay):not(.prevMonthDay)',text: value,exact_text: true)@@ -67,51 +54,46 @@ module Components### Set a ISO8601 date through the datepicker- def set_date(date, multiple_month_shown = false)+ def set_date(date)date = Date.parse(date) unless date.is_a?(Date)select_year date.year- select_month multiple_month_shown ? date.month : date.strftime('%B'), multiple_month_shown+ select_month date.strftime('%B')select_day date.dayend### Expect the selected month- def expect_month(month, multiple_month_shown = false)- if multiple_month_shown- field = container.first('.cur-month')- expect(field.text).to eq(month)- else- month = Date::MONTHNAMES.index(month) if month.is_a?(String)+ def expect_month(mont)+ month = Date::MONTHNAMES.index(month) if month.is_a?(String)- # Month is 0-index in select- field = container.find('.flatpickr-monthDropdown-months')- expect(field.value.to_i).to eq(month - 1)+ # Month is 0-index in select+ field = flatpickr_container.find('.flatpickr-monthDropdown-months')+ expect(field.value.to_i).to eq(month - 1)- endend### Expect the selected daydef expect_day(value)- expect(container).to have_selector('.flatpickr-day.selected', text: value)+ expect(flatpickr_container).to have_selector('.flatpickr-day.selected', text: value)end### Expect the selected yeardef expect_year(value)- field = container.first('.cur-year')+ field = flatpickr_container.first('.cur-year')expect(field.value.to_i).to eq(value.to_i)end### Expect the current selection to match the# given ISO601 date- def expect_current_date(date, multiple_month_shown = false)+ def expect_current_date(date)date = Date.parse(date) unless date.is_a?(Date)expect_year(date.year)- expect_month(date.month, multiple_month_shown)+ expect_month(date.month)expect_day(date.day)endenddiff --git a/spec/support/components/datepicker/work_package_datepicker.rb b/spec/support/components/datepicker/work_package_datepicker.rbnew file mode 100644index 00000000000..e75524b589c--- /dev/null+++ b/spec/support/components/datepicker/work_package_datepicker.rb@@ -0,0 +1,70 @@+require_relative 'datepicker'++module Components+ class WorkPackageDatepicker < Datepicker+ ##+ # Select month from datepicker+ def select_month(month)+ month = Date::MONTHNAMES.index(month) if month.is_a?(String)+ current_month = Date::MONTHNAMES.index(flatpickr_container.first('.cur-month').text)++ if current_month < month+ while current_month < month+ flatpickr_container.find('.flatpickr-next-month').click+ current_month = Date::MONTHNAMES.index(flatpickr_container.first('.cur-month').text)+ end+ elsif current_month > month+ while current_month > month+ flatpickr_container.find('.flatpickr-prev-month').click+ current_month = Date::MONTHNAMES.index(flatpickr_container.first('.cur-month').text)+ end+ end+ end++ ##+ # Expect the selected month+ def expect_month(month)+ field = flatpickr_container.first('.cur-month')+ expect(field.text).to eq(month)+ end++ ##+ # Expect start date+ def expect_start_date(value)+ expect(container).to have_field('startDate', with: value, wait: 10)+ end++ ##+ # Expect start date+ def expect_due_date(value)+ expect(container).to have_field('endDate', with: value, wait: 10)+ end++ ##+ # Expect duration+ def expect_duration(count)+ expect(container).to have_field('duration', with: I18n.t('js.units.day', count:), wait: 10)+ end++ def start_date_field+ container.find_field 'startDate'+ end++ def end_date_field+ container.find_field 'endDate'+ end++ def duration_field+ container.find_field 'duration'+ end++ def set_duration(value)+ duration = find_field 'duration'+ duration.click+ duration.set value++ # Focus a different field+ start_date_field.click+ end+ end+enddiff --git a/spec/support/edit_fields/date_edit_field.rb b/spec/support/edit_fields/date_edit_field.rbindex c1dee412e9e..99807f993c4 100644--- a/spec/support/edit_fields/date_edit_field.rb+++ b/spec/support/edit_fields/date_edit_field.rb@@ -15,7 +15,7 @@ class DateEditField < EditFieldenddef datepicker- @datepicker ||= ::Components::Datepicker.new modal_selector+ @datepicker ||= ::Components::WorkPackageDatepicker.new modal_selectorenddef modal_selector