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
Adapt test to WP date field showing two months in the datepicker modal
Henriette Darge67a56cca7b17
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 3b964c8b388..9a3dc650e27 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -941,7 +941,6 @@ en:label_delete_page: "Delete current page"button_apply: "Apply"button_save: "Save"- button_clear_all: "Clear all"button_submit: "Submit"button_cancel: "Cancel"form_submit:diff --git a/frontend/src/app/components/datepicker/datepicker.modal.helper.ts b/frontend/src/app/components/datepicker/datepicker.modal.helper.tsindex 32fc93564b7..81950addf47 100644--- a/frontend/src/app/components/datepicker/datepicker.modal.helper.ts+++ b/frontend/src/app/components/datepicker/datepicker.modal.helper.ts@@ -83,7 +83,7 @@ export class DatePickerModalHelper {public setDatepickerRestrictions(dates:{ [key in DateKeys]:string }, datePicker:DatePicker) {if (!dates.start && !dates.end) {- return false;+ return;}if (this.isStateOfCurrentActivatedField('start')) {diff --git a/frontend/src/app/components/datepicker/datepicker.modal.ts b/frontend/src/app/components/datepicker/datepicker.modal.tsindex 8611e3b008f..01e2ebcfcdf 100644--- a/frontend/src/app/components/datepicker/datepicker.modal.ts+++ b/frontend/src/app/components/datepicker/datepicker.modal.ts@@ -65,7 +65,7 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {text = {save: this.I18n.t('js.button_save'),cancel: this.I18n.t('js.button_cancel'),- clear: this.I18n.t('js.button_clear'),+ clear: this.I18n.t('js.work_packages.button_clear'),manualScheduling: this.I18n.t('js.scheduling.manual'),date: this.I18n.t('js.work_packages.properties.date'),startDate: this.I18n.t('js.work_packages.properties.startDate'),@@ -107,7 +107,7 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {} else {this.dates.start = this.changeset.value('startDate');this.dates.end = this.changeset.value('dueDate');- this.datepickerHelper.setCurrentActivatedField(this.locals.fieldName === 'dueDate' ? 'end' : 'start');+ this.datepickerHelper.setCurrentActivatedField(this.initialActivatedField());}}@@ -267,4 +267,8 @@ export class DatePickerModal extends OpModalComponent implements AfterViewInit {let output = this.singleDate ? date : start + ' - ' + end;this.onDataUpdated.emit(output);}++ private initialActivatedField():DateKeys {+ return this.locals.fieldName === 'dueDate' || (this.dates.start && !this.dates.end) ? 'end' : 'start';+ }}diff --git a/spec/features/work_packages/details/date_editor_spec.rb b/spec/features/work_packages/details/date_editor_spec.rbindex e5d2e83e94a..96ffd8fb395 100644--- a/spec/features/work_packages/details/date_editor_spec.rb+++ b/spec/features/work_packages/details/date_editor_spec.rb@@ -51,17 +51,17 @@ describe 'date inplace editor',work_packages_page.ensure_page_loadedend- it 'uses the start date as a placeholder for the end date' do+ it 'can directly set the due date when only a start date is set' dostart_date.activate!start_date.expect_active!start_date.datepicker.expect_year '2016'- start_date.datepicker.expect_month 'January'+ start_date.datepicker.expect_month 'January', truestart_date.datepicker.select_day '25'start_date.save!start_date.expect_inactive!- start_date.expect_state_text '2016-01-25'+ start_date.expect_state_text '2016-01-01 - 2016-01-25'endit 'saves the date when clearing and then confirming' dodiff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rbindex 7533107a58d..e3cd3ea71fc 100644--- a/spec/support/components/datepicker/datepicker.rb+++ b/spec/support/components/datepicker/datepicker.rb@@ -16,16 +16,33 @@ module Components# Select year from inputdef select_year(value)container- .find('.numInput.cur-year')+ .first('.numInput.cur-year').set valueend##- # Select month from select- def select_month(value)- container- .find('.flatpickr-monthDropdown-months option', text: value, visible: :all)- .select_option+ # 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) do+ 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) do+ 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+ endend##@@ -36,7 +53,7 @@ module Componentsendcontainer- .find('.flatpickr-days .flatpickr-day:not(.nextMonthDay):not(.prevMonthDay)',+ .first('.flatpickr-days .flatpickr-day:not(.nextMonthDay):not(.prevMonthDay)',text: value,exact_text: true).click@@ -44,22 +61,28 @@ module Components### Set a ISO8601 date through the datepicker- def set_date(date)+ def set_date(date, multiple_month_shown = false)date = Date.parse(date) unless date.is_a?(Date)select_year date.year- select_month date.strftime('%B')+ select_month multiple_month_shown ? date.month : date.strftime('%B'), multiple_month_shownselect_day date.dayend### Expect the selected month- def expect_month(month)- month = Date::MONTHNAMES.index(month) if month.is_a?(String)+ 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)- # 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 = container.find('.flatpickr-monthDropdown-months')+ expect(field.value.to_i).to eq(month - 1)++ endend##@@ -71,18 +94,18 @@ module Components### Expect the selected yeardef expect_year(value)- field = container.find('.cur-year')+ field = 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)+ def expect_current_date(date, multiple_month_shown = false)date = Date.parse(date) unless date.is_a?(Date)expect_year(date.year)- expect_month(date.month)+ expect_month(date.month, multiple_month_shown)expect_day(date.day)endenddiff --git a/spec/support/edit_fields/date_edit_field.rb b/spec/support/edit_fields/date_edit_field.rbindex a0da4b529c8..7425eac4ef8 100644--- a/spec/support/edit_fields/date_edit_field.rb+++ b/spec/support/edit_fields/date_edit_field.rb@@ -95,7 +95,7 @@ class DateEditField < EditFieldenddef select_value(value)- datepicker.set_date value+ datepicker.set_date value, trueenddef save!@@ -110,10 +110,6 @@ class DateEditField < EditFieldscroll_to_and_click action_button('Cancel')end- def clear_changes- scroll_to_and_click action_button('Clear all')- end-def action_button(text)page.find("#{modal_selector} .datepicker-modal--action", text: text)end