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 tests about progress modal

Christophe Bliardbb1709521577
diff --git a/spec/features/work_packages/remaining_time_spec.rb b/spec/features/work_packages/remaining_time_spec.rb
index 2ba7212cfbc..7d253396f69 100644
--- a/spec/features/work_packages/remaining_time_spec.rb
+++ b/spec/features/work_packages/remaining_time_spec.rb
@@ -47,6 +47,8 @@ RSpec.describe "Work packages remaining time", :js, :with_cuprite do
wp_page.expect_subject
wp_page.expect_attributes remainingTime: "-"
+ # need to update work first to enable the remaining work field
+ wp_page.update_attributes estimatedTime: "200" # rubocop:disable Rails/ActiveRecordAliases
wp_page.update_attributes remainingTime: "125" # rubocop:disable Rails/ActiveRecordAliases
wp_page.expect_attributes remainingTime: "125 h"
@@ -58,13 +60,15 @@ RSpec.describe "Work packages remaining time", :js, :with_cuprite do
wp_table_page = Pages::WorkPackagesTable.new(project)
query_props = JSON.dump({
- c: %w(id subject remainingTime),
+ c: %w[id subject estimatedTime remainingTime],
s: true
})
wp_table_page.visit_with_params("query_props=#{query_props}")
wp_table_page.expect_work_package_with_attributes work_package, remainingTime: "-"
+ # need to update work first to enable the remaining work field
+ wp_table_page.update_work_package_attributes work_package, estimatedTime: "200"
wp_table_page.update_work_package_attributes work_package, remainingTime: "125"
wp_table_page.expect_work_package_with_attributes work_package, remainingTime: "125 h"
wp_table_page.expect_sums_row_with_attributes remainingTime: "125 h"
diff --git a/spec/support/edit_fields/progress_edit_modal.rb b/spec/support/edit_fields/progress_edit_modal.rb
index 2693e9d32a7..21d0cc317f8 100644
--- a/spec/support/edit_fields/progress_edit_modal.rb
+++ b/spec/support/edit_fields/progress_edit_modal.rb
@@ -41,8 +41,12 @@ class ProgressEditModal
"remainingTime" => :remaining_hours
}.freeze
- def initialize(property_name,
+ def initialize(container,
+ property_name,
selector: nil)
+ # This is the container for the display field. The input field is in the
+ # modal, attached to the page.
+ @container = container
@property_name = property_name.to_s
@field_name = "work_package_#{FIELD_NAME_MAP[@property_name]}"
@selector = selector || ".inline-edit--display-field.#{@property_name}"
@@ -63,7 +67,8 @@ class ProgressEditModal
private
- attr_reader :property_name,
+ attr_reader :container,
+ :property_name,
:field_name,
:selector
@@ -72,7 +77,7 @@ class ProgressEditModal
end
def display_field
- page.find(selector)
+ container.find(selector)
end
def within_modal(&)
diff --git a/spec/support/pages/work_packages/abstract_work_package.rb b/spec/support/pages/work_packages/abstract_work_package.rb
index 96bb0c236f7..abc39103cb6 100644
--- a/spec/support/pages/work_packages/abstract_work_package.rb
+++ b/spec/support/pages/work_packages/abstract_work_package.rb
@@ -215,7 +215,7 @@ module Pages
when :date, :startDate, :dueDate, :combinedDate
DateEditField.new container, key, is_milestone: work_package&.milestone?
when :estimatedTime, :remainingTime
- ProgressEditModal.new key
+ ProgressEditModal.new container, key
when :description
TextEditorField.new container, key
# The AbstractWorkPackageCreate pages do not require a special WorkPackageStatusField,
diff --git a/spec/support/pages/work_packages/work_packages_table.rb b/spec/support/pages/work_packages/work_packages_table.rb
index 120169e29cb..e5fa7555fef 100644
--- a/spec/support/pages/work_packages/work_packages_table.rb
+++ b/spec/support/pages/work_packages/work_packages_table.rb
@@ -126,7 +126,7 @@ module Pages
# @param key_value_map [Hash] The attribute-value map.
def update_work_package_attributes(work_package, **key_value_map)
key_value_map.each do |key, value|
- field = EditField.new(work_package_container(work_package), key)
+ field = work_package_field(work_package, key)
field.update(value, save: true)
end
end
@@ -270,6 +270,14 @@ module Pages
table_container.find(row_selector(work_package))
end
+ # Returns the row element for the work package inline creation (after
+ # clicking "Create new work package").
+ #
+ # @return [Capybara::Node::Element] The row element.
+ def creation_row
+ table_container.find(".wp-inline-create-row")
+ end
+
# Returns the CSS selector for the row of the specified work package.
#
# @param elem [WorkPackage, String, Integer] The work package object or ID.
@@ -285,14 +293,7 @@ module Pages
# @param attribute [Symbol] The attribute name.
# @return [EditField, DateEditField] The edit field.
def edit_field(work_package, attribute)
- context =
- if work_package.nil?
- table_container.find(".wp-inline-create-row")
- else
- row(work_package)
- end
-
- work_package_field(work_package, context, attribute)
+ work_package_field(work_package, attribute)
end
# Opens the context menu for the specified work package row.
@@ -347,11 +348,11 @@ module Pages
end
def work_package_container(work_package)
- table_container.find(work_package_row_selector(work_package))
- end
-
- def work_package_row_selector(work_package)
- ".wp-row-#{work_package.id}"
+ if work_package.nil?
+ creation_row
+ else
+ row(work_package)
+ end
end
protected
@@ -360,12 +361,15 @@ module Pages
page
end
- def work_package_field(work_package, context, key)
+ def work_package_field(work_package, key)
+ container = work_package_container(work_package)
case key.to_sym
- when :date, :startDate, :dueDate
- DateEditField.new context, key, is_milestone: work_package.milestone?, is_table: true
+ when :date, :startDate, :dueDate, :combinedDate
+ DateEditField.new container, key, is_milestone: work_package.milestone?, is_table: true
+ when :estimatedTime, :remainingTime
+ ProgressEditModal.new container, key
else
- EditField.new context, key
+ EditField.new container, key
end
end