Skip to content

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

Fix issue with banner text when one predecessor has no due date

Christophe Bliardc8d1a290b84a
diff --git a/app/components/work_packages/date_picker/banner_component.rb b/app/components/work_packages/date_picker/banner_component.rb
index 976d9cb3598..84093d7139b 100644
--- a/app/components/work_packages/date_picker/banner_component.rb
+++ b/app/components/work_packages/date_picker/banner_component.rb
@@ -111,7 +111,7 @@ module WorkPackages
return false if @work_package.start_date.nil?
predecessor_work_packages.any? do |wp|
- return false if wp.due_date.nil?
+ next false if wp.due_date.nil?
wp.due_date.after?(@work_package.start_date)
end
@@ -120,12 +120,9 @@ module WorkPackages
def predecessor_with_large_gap?
return false if @work_package.start_date.nil?
- sorted = predecessor_work_packages.sort_by(&:due_date)
-
- last_due_date = sorted.last.due_date
- return false if last_due_date.nil?
-
- last_due_date.before?(@work_package.start_date - 2)
+ predecessor_work_packages.filter_map(&:due_date)
+ .max
+ &.before?(@work_package.start_date - 2)
end
def predecessor_relations
diff --git a/spec/components/work_packages/date_picker/banner_component_spec.rb b/spec/components/work_packages/date_picker/banner_component_spec.rb
new file mode 100644
index 00000000000..38fa622fd63
--- /dev/null
+++ b/spec/components/work_packages/date_picker/banner_component_spec.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe WorkPackages::DatePicker::BannerComponent, type: :component do
+ include OpenProject::StaticRouting::UrlHelpers
+
+ create_shared_association_defaults_for_work_package_factory
+
+ subject(:banner) do
+ render_inline(described_class.new(work_package:, manually_scheduled:))
+ end
+
+ context "when manually scheduled" do
+ let(:manually_scheduled) { true }
+
+ context "without any predecessors or children" do
+ let(:work_package) { build(:work_package) }
+
+ it "displays banner 'Click on \"Show relations\" for Gantt overview.'" do
+ expected_text = I18n.t("work_packages.datepicker_modal.banner.description.click_on_show_relations_to_open_gantt",
+ button_name: I18n.t("work_packages.datepicker_modal.show_relations"))
+ expect(banner).to have_text(expected_text)
+ end
+ end
+
+ context "with all predecessors leaving a gap between actual start date and soonest possible start date" do
+ let_work_packages(<<~TABLE)
+ hierarchy | MTWTFSS | scheduling mode | predecessors
+ pred_no_dates | | manual |
+ pred_dates | XX | manual |
+ work_package | X | manual | pred_dates, pred_no_dates with lag 2
+ TABLE
+
+ it "displays banner 'There is a gap between this and all predecessors.'" do
+ expect(banner).to have_text(I18n.t("work_packages.datepicker_modal.banner.description.manual_gap_between_predecessors"))
+ end
+ end
+
+ context "with some predecessors dates overlapping actual start date" do
+ let_work_packages(<<~TABLE)
+ hierarchy | MTWTFSS | scheduling mode | predecessors
+ pred_no_dates | | manual |
+ pred_dates | XXXXX | manual |
+ work_package | X | manual | pred_dates, pred_no_dates with lag 2
+ TABLE
+
+ it "displays banner 'There is a gap between this and all predecessors.'" do
+ expect(banner).to have_text(I18n.t("work_packages.datepicker_modal.banner.description.manual_overlap_with_predecessors"))
+ end
+ end
+ end
+end