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 updated on child creation
Christophe Bliard443940dd5baa
diff --git a/spec/features/work_packages/new/new_work_package_spec.rb b/spec/features/work_packages/new/new_work_package_spec.rbindex 7a223b59a08..2f705a3c2b2 100644--- a/spec/features/work_packages/new/new_work_package_spec.rb+++ b/spec/features/work_packages/new/new_work_package_spec.rb@@ -427,7 +427,7 @@ RSpec.describe 'new work package', :js, :with_cuprite dotype_field.set_value type_bug.name# wait after the type changesleep(0.2)- subject_field.update('new work package')+ subject_field.update('new work package', save: true)wp_page.expect_and_dismiss_toaster(message: 'Successful creation.'diff --git a/spec/features/work_packages/update_ancestors_spec.rb b/spec/features/work_packages/update_ancestors_spec.rbindex 22bd6418090..f8ac7af01f7 100644--- a/spec/features/work_packages/update_ancestors_spec.rb+++ b/spec/features/work_packages/update_ancestors_spec.rb@@ -32,17 +32,26 @@ require 'spec_helper'RSpec.describe 'Update ancestors', :js, :with_cuprite doshared_let(:user) { create(:admin) }- shared_let(:project) { create(:project) }+ shared_let(:priority) { create(:default_priority) }+ shared_let(:status) { create(:default_status) }+ shared_let(:project) { create(:project_with_types) }++ before_all do+ set_factory_default(:priority, priority)+ set_factory_default(:project, project)+ set_factory_default(:project_with_types, project)+ set_factory_default(:status, status)+ set_factory_default(:user, user)+ end+shared_let(:parent) docreate(:work_package,- project:,subject: 'parent',estimated_hours: 2,remaining_hours: 1)endshared_let(:child) docreate(:work_package,- project:,parent:,subject: 'child',estimated_hours: 6,@@ -50,8 +59,6 @@ RSpec.describe 'Update ancestors', :js, :with_cuprite doendshared_let(:query) docreate(:query,- user:,- project:,show_hierarchies: true,column_names: %i[id estimated_hours remaining_hours subject])end@@ -91,4 +98,21 @@ RSpec.describe 'Update ancestors', :js, :with_cuprite doexpect(parent.derived_remaining_hours).to eq(parent.remaining_hours)endend++ context 'when adding another the child' do+ it 'updates the parent work and remaining work values' do+ context_menu = wp_table.open_context_menu_for(parent)+ context_menu.choose('Create new child')++ split_view_create = Pages::SplitWorkPackageCreate.new(project:)+ split_view_create.set_attributes({ subject: 'child 2', estimatedTime: 1, remainingTime: 3 })+ split_view_create.save!+ split_view_create.expect_and_dismiss_toaster message: 'Successful creation'++ parent.reload+ new_child = WorkPackage.last+ expect(parent.derived_estimated_hours).to eq(parent.estimated_hours + child.estimated_hours + new_child.estimated_hours)+ expect(parent.derived_remaining_hours).to eq(parent.remaining_hours + child.remaining_hours + new_child.remaining_hours)+ end+ endenddiff --git a/spec/support/edit_fields/edit_field.rb b/spec/support/edit_fields/edit_field.rbindex a1195cd92c7..703d4903d94 100644--- a/spec/support/edit_fields/edit_field.rb+++ b/spec/support/edit_fields/edit_field.rb@@ -10,17 +10,35 @@ class EditFieldattr_accessor :field_type+ # Initializes a new EditField object. It represents a work package field on a+ # work packages table page, a work package view page (split or full), or a+ # work package creation page (split or full).+ #+ # @param context [Object] The context in which the EditField is being used.+ # @param property_name [Symbol] The name of the property associated with the+ # EditField. Generally camel case.+ # @param selector [String] (optional) The CSS selector used to locate the+ # EditField element. if unspecified, the `property_name` is used.+ # @param create_form [Boolean] (optional) Indicates whether the EditField is+ # used in a create form. It changes the way the field is clicked or not to+ # activate it on edition. It is `false` by default.def initialize(context,property_name,- selector: nil)+ selector: nil,+ create_form: false)@property_name = property_name.to_s@context = context@field_type = derive_field_type+ @create_form = create_form@selector = selector || ".inline-edit--container.#{property_name}"end+ def create_form?+ @create_form+ end+def field_containercontext.find @selectorend@@ -99,7 +117,7 @@ class EditFieldenddef expect_state!(open:)- if open+ if open || create_form?expect_active!elseexpect_inactive!@@ -186,7 +204,7 @@ class EditFieldactivate!scroll_to_element(input_element)- if field_type.end_with?('-autocompleter')+ if autocompleter_field?if multipage.find('.ng-value-label', visible: :all, text: content).sibling('.ng-value-icon').clickelse@@ -211,10 +229,14 @@ class EditFieldinput_element.send_keys textend- ##- # Update this attribute while retrying to open the field- # if unsuccessful at first.- def update(value, save: true, expect_failure: false)+ # Updates the value of the edit field. It retries if unsuccessful at first.+ #+ # @param value [Object] The new value to set.+ # @param save [Boolean] Whether to save the field after updating. Save happens+ # by pressing Enter key. Default is `true` for non-create pages.+ # @param expect_failure [Boolean] Whether to expect the update to fail. This+ # will check if field is still in edit state after save. Default is `false`.+ def update(value, save: !create_form?, expect_failure: false)# Retry to set attributes due to reloading the page after setting# an attribute, which may cause an input not to open properly.retry_block do@@ -222,13 +244,13 @@ class EditFieldset_value value# select fields are saved on change- save! if save && !field_type.end_with?('-autocompleter')+ save! if save && !autocompleter_field?expect_state! open: expect_failureendenddef submit_by_enter- if field_type.end_with? '-autocompleter'+ if autocompleter_field?autocomplete_selector.send_keys :returnelseinput_element.native.send_keys :return@@ -236,7 +258,7 @@ class EditFieldenddef cancel_by_escape- if field_type.end_with? '-autocompleter'+ if autocompleter_field?autocomplete_selector.send_keys :escapeelseinput_element.native.send_keys :escapediff --git a/spec/support/pages/work_packages/abstract_work_package.rb b/spec/support/pages/work_packages/abstract_work_package.rbindex 43a18656f29..9af4ea4aaf8 100644--- a/spec/support/pages/work_packages/abstract_work_package.rb+++ b/spec/support/pages/work_packages/abstract_work_package.rb@@ -37,6 +37,10 @@ module Pages@project = projectend+ def create_page?+ is_a?(AbstractWorkPackageCreate)+ end+def visit_tab!(tab)visit path(tab)end@@ -189,15 +193,15 @@ module Pagesendend- def update_attributes(save: true, **key_value_map)+ def update_attributes(save: !create_page?, **key_value_map)set_attributes(key_value_map, save:)end- def set_attributes(key_value_map, save: true)+ def set_attributes(key_value_map, save: !create_page?)key_value_map.each_with_index.map do |(key, value), index|field = work_package_field(key)field.update(value, save:)- unless index == key_value_map.length - 1+ if save && (index != key_value_map.length - 1)ensure_no_conflicting_modificationsendend@@ -214,13 +218,13 @@ module Pages# The AbstractWorkPackageCreate pages do not require a special WorkPackageStatusField,# because the status field on the create pages is a simple EditField.when :status- if is_a?(AbstractWorkPackageCreate)- EditField.new container, key+ if create_page?+ EditField.new container, key, create_form: trueelseWorkPackageStatusField.new containerendelse- EditField.new container, key+ EditField.new container, key, create_form: create_page?endend