Skip to content

Commit

Permalink
Fix tests about progress modal
Browse files Browse the repository at this point in the history
Remaining work can only be set if work is set first.

Also refactored `Pages::WorkPackagesTable` a bit to remove duplicated
methods.
  • Loading branch information
cbliard committed Mar 29, 2024
1 parent bd1735d commit bb17095
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
6 changes: 5 additions & 1 deletion spec/features/work_packages/remaining_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
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"

Expand All @@ -58,13 +60,15 @@
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"
Expand Down
11 changes: 8 additions & 3 deletions spec/support/edit_fields/progress_edit_modal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -63,7 +67,8 @@ def update(value, save: true, expect_failure: false)

private

attr_reader :property_name,
attr_reader :container,
:property_name,
:field_name,
:selector

Expand All @@ -72,7 +77,7 @@ def activate_modal
end

def display_field
page.find(selector)
container.find(selector)
end

def within_modal(&)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/pages/work_packages/abstract_work_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def work_package_field(key)
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,
Expand Down
40 changes: 22 additions & 18 deletions spec/support/pages/work_packages/work_packages_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def expect_work_package_count(count)
# @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
Expand Down Expand Up @@ -270,6 +270,14 @@ def row(work_package)
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.
Expand All @@ -285,14 +293,7 @@ def row_selector(elem)
# @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.
Expand Down Expand Up @@ -347,11 +348,11 @@ def table_container
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
Expand All @@ -360,12 +361,15 @@ def container
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

Expand Down

0 comments on commit bb17095

Please sign in to comment.