From 380bfbc157e6c4f94fa52a926ec9ce7512d15964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 22 Aug 2022 12:55:53 +0200 Subject: [PATCH] Add scenario 2 --- .../datepicker/datepicker_logic_spec.rb | 53 +++++++++++++++++-- .../datepicker/work_package_datepicker.rb | 9 +++- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb b/spec/features/work_packages/datepicker/datepicker_logic_spec.rb index 9c729067d0..b0ecec184a 100644 --- a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb +++ b/spec/features/work_packages/datepicker/datepicker_logic_spec.rb @@ -29,7 +29,7 @@ require 'spec_helper' require 'support/edit_fields/edit_field' -describe 'Datepicker modal logic', +describe 'Datepicker modal logic test cases (WP #43539)', with_settings: { date_format: '%Y-%m-%d' }, with_flag: { work_packages_duration_field_active: true }, js: true do @@ -42,7 +42,6 @@ describe 'Datepicker modal logic', shared_let(:bug_wp) { create :work_package, project:, type: type_bug } shared_let(:milestone_wp) { create :work_package, project:, type: type_milestone } - # assume sat+sun are non working days shared_let(:weekdays) { create :week_days } @@ -57,6 +56,18 @@ describe 'Datepicker modal logic', let(:work_package) { bug_wp } + def apply_and_expect_saved(attributes) + date_field.save! + + work_packages_page.expect_and_dismiss_toaster message: I18n.t('js.notice_successful_update') + + work_package.reload + + attributes.each do |attr, value| + expect(work_package.send(attr)).to eq value + end + end + before do bug_wp.update!(bug_attributes) unless bug_attributes.nil? milestone_wp.update!(milestone_attributes) unless milestone_attributes.nil? @@ -69,7 +80,7 @@ describe 'Datepicker modal logic', date_field.expect_active! end - describe '#43539 Scenario 1' do + context 'when start_date set, update due_date (test case 1)' do let(:bug_attributes) do { start_date: Date.parse('2021-02-08'), @@ -81,11 +92,43 @@ describe 'Datepicker modal logic', it 'sets finish date to 19th if duration of 10 set' do datepicker.expect_start_date '2021-02-08' datepicker.expect_due_date '' - datepicker.set_duration '10' + datepicker.expect_duration 0 + + datepicker.set_duration 10 datepicker.expect_start_date '2021-02-08' datepicker.expect_due_date '2021-02-19' - datepicker.expect_duration '10' + datepicker.expect_duration 10 + + apply_and_expect_saved duration: 10, + start_date: Date.parse('2021-02-08'), + due_date: Date.parse('2021-02-08') + end + end + + describe 'when no values set, update duration (test case 2)' do + let(:bug_attributes) do + { + start_date: nil, + due_date: nil, + duration: nil + } + end + + it 'sets only the duration' do + datepicker.expect_start_date '' + datepicker.expect_due_date '' + datepicker.expect_duration 0 + + datepicker.set_duration 10 + + datepicker.expect_start_date '' + datepicker.expect_due_date '' + datepicker.expect_duration 10 + + apply_and_expect_saved duration: 10, + start_date: nil, + due_date: nil end end end diff --git a/spec/support/components/datepicker/work_package_datepicker.rb b/spec/support/components/datepicker/work_package_datepicker.rb index e75524b589..89534f7145 100644 --- a/spec/support/components/datepicker/work_package_datepicker.rb +++ b/spec/support/components/datepicker/work_package_datepicker.rb @@ -43,7 +43,14 @@ module Components ## # Expect duration def expect_duration(count) - expect(container).to have_field('duration', with: I18n.t('js.units.day', count:), wait: 10) + value = + if count.nil? || count == '' + '' + else + I18n.t('js.units.day', count:) + end + + expect(container).to have_field('duration', with: value, wait: 10) end def start_date_field