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
[50961] Ensure derived values are computed
Christophe Bliardbd6223f67f66
diff --git a/spec/features/work_packages/update_ancestors_spec.rb b/spec/features/work_packages/update_ancestors_spec.rbnew file mode 100644index 00000000000..22bd6418090--- /dev/null+++ b/spec/features/work_packages/update_ancestors_spec.rb@@ -0,0 +1,94 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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 'spec_helper'++RSpec.describe 'Update ancestors', :js, :with_cuprite do+ shared_let(:user) { create(:admin) }+ shared_let(:project) { create(:project) }+ shared_let(:parent) do+ create(:work_package,+ project:,+ subject: 'parent',+ estimated_hours: 2,+ remaining_hours: 1)+ end+ shared_let(:child) do+ create(:work_package,+ project:,+ parent:,+ subject: 'child',+ estimated_hours: 6,+ remaining_hours: 3)+ end+ shared_let(:query) do+ create(:query,+ user:,+ project:,+ show_hierarchies: true,+ column_names: %i[id estimated_hours remaining_hours subject])+ end++ let(:wp_table) { Pages::WorkPackagesTable.new project }++ before do+ # make sure the derived fields are initially displayed right+ WorkPackages::UpdateAncestorsService+ .new(user:, work_package: child)+ .call(%i[estimated_hours remaining_hours])++ login_as(user)+ wp_table.visit_query query+ end++ context 'when changing the child work and remaining work values' do+ it 'updates the parent work and remaining work values' do+ expect do+ wp_table.update_work_package_attributes(child, estimatedTime: child.estimated_hours + 1)+ parent.reload+ end.to change(parent, :derived_estimated_hours).by(1)+ expect do+ wp_table.update_work_package_attributes(child, remainingTime: child.remaining_hours + 2)+ parent.reload+ end.to change(parent, :derived_remaining_hours).by(2)+ end+ end++ context 'when deleting the child' do+ it 'updates the parent work and remaining work values' do+ context_menu = wp_table.open_context_menu_for(child)+ context_menu.choose_delete_and_confirm_deletion++ parent.reload+ expect(parent.derived_estimated_hours).to eq(parent.estimated_hours)+ expect(parent.derived_remaining_hours).to eq(parent.remaining_hours)+ end+ end+enddiff --git a/spec/support/components/work_packages/context_menu.rb b/spec/support/components/work_packages/context_menu.rbindex d2210ec7319..a520e6965cc 100644--- a/spec/support/components/work_packages/context_menu.rb+++ b/spec/support/components/work_packages/context_menu.rb@@ -26,12 +26,15 @@# See COPYRIGHT and LICENSE files for more details.#+++require_relative '../../toasts/expectations'+module Componentsmodule WorkPackagesclass ContextMenuinclude Capybara::DSLinclude Capybara::RSpecMatchersinclude RSpec::Matchers+ include Toasts::Expectationsdef open_for(work_package, card_view: nil)# Close@@ -69,6 +72,15 @@ module Componentsfind("#{selector} .menu-item", text: target, exact_text: true).clickend+ def choose_delete_and_confirm_deletion+ choose 'Delete'+ # only handle the case where the modal does _not_ ask for descendants deletion confirmation+ within_modal(I18n.t('js.modals.destroy_work_package.title', label: 'work package')) do+ click_button 'Delete'+ end+ expect_and_dismiss_toaster+ end+def expect_no_options(*options)expect_openoptions.each do |text|diff --git a/spec/support/pages/work_packages/work_packages_table.rb b/spec/support/pages/work_packages/work_packages_table.rbindex 43fee4ddd71..d1f82e2b263 100644--- a/spec/support/pages/work_packages/work_packages_table.rb+++ b/spec/support/pages/work_packages/work_packages_table.rb@@ -295,6 +295,20 @@ module Pageswork_package_field(work_package, context, attribute)end+ # Opens the context menu for the specified work package row.+ #+ # It returns a `Components::WorkPackages::ContextMenu` instance which can+ # be used to interact with the context menu.+ #+ # @param work_package [WorkPackage] The work package object.+ # @return [Components::WorkPackages::ContextMenu] The context menu object.+ def open_context_menu_for(work_package)+ expect_work_package_subject(work_package.subject)+ context_menu = Components::WorkPackages::ContextMenu.new+ context_menu.open_for work_package+ context_menu+ end+# Clicks on the specified setting item in the page context menu.## @param label [String] The label of the setting item.