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

Add remaining work column to work package index sums test

Christophe Bliard43283bc23bb6
diff --git a/spec/features/work_packages/index_sums_spec.rb b/spec/features/work_packages/index_sums_spec.rb
index 0b5d3c15f65..189d1f412b8 100644
--- a/spec/features/work_packages/index_sums_spec.rb
+++ b/spec/features/work_packages/index_sums_spec.rb
@@ -40,7 +40,9 @@ RSpec.describe 'Work package index sums', :js do
log_costs] })
end
let(:project) do
- create(:project, name: 'project1', identifier: 'project1')
+ create(:project,
+ name: 'project1',
+ identifier: 'project1')
end
let(:type) { create(:type) }
let!(:int_cf) do
@@ -50,19 +52,26 @@ RSpec.describe 'Work package index sums', :js do
end
end
let!(:float_cf) do
- create(:float_wp_custom_field).tap do |cf|
+ create(:float_wp_custom_field) do |cf|
project.work_package_custom_fields << cf
type.custom_fields << cf
end
end
- let!(:work_package_1) do
- create(:work_package, project:, type:, estimated_hours: 10).tap do |wp|
+ let!(:work_package1) do
+ create(:work_package,
+ project:, type:,
+ estimated_hours: 10,
+ remaining_hours: 5) do |wp|
wp.custom_field_values = { int_cf.id => 5, float_cf.id => 5.5 }
wp.save!
end
end
- let!(:work_package_2) do
- create(:work_package, project:, type:, estimated_hours: 15).tap do |wp|
+ let!(:work_package2) do
+ create(:work_package,
+ project:,
+ type:,
+ estimated_hours: 15,
+ remaining_hours: 7.5) do |wp|
wp.custom_field_values = { int_cf.id => 7, float_cf.id => 7.7 }
wp.save!
end
@@ -75,7 +84,7 @@ RSpec.describe 'Work package index sums', :js do
let!(:time_entry) do
create(:time_entry,
user:,
- work_package: work_package_1,
+ work_package: work_package1,
project:,
hours: 1.50)
end
@@ -88,7 +97,7 @@ RSpec.describe 'Work package index sums', :js do
end
let!(:cost_entry) do
create(:cost_entry,
- work_package: work_package_1,
+ work_package: work_package1,
project:,
units: 2.50,
cost_type:,
@@ -100,18 +109,16 @@ RSpec.describe 'Work package index sums', :js do
let(:modal) { Components::WorkPackages::TableConfigurationModal.new }
let(:group_by) { Components::WorkPackages::GroupBy.new }
- before do
- login_as(user)
-
- visit project_work_packages_path(project)
- expect(page).to have_current_path('/projects/project1/work_packages')
- end
+ current_user { user }
it 'calculates sums correctly' do
- wp_table.expect_work_package_listed work_package_1, work_package_2
+ visit project_work_packages_path(project)
+ wp_table.expect_work_package_listed work_package1, work_package2
# Add work column
columns.add 'Work'
+ # Add remaining work column
+ columns.add 'Remaining work'
# Add int cf column
columns.add int_cf.name
# Add float cf column
@@ -126,69 +133,71 @@ RSpec.describe 'Work package index sums', :js do
# Trigger action from action menu dropdown
modal.set_display_sums enable: true
- wp_table.expect_work_package_listed work_package_1, work_package_2
+ wp_table.expect_work_package_listed work_package1, work_package2
# Expect the total sums row
- expect(page).to have_css('.wp-table--sums-row', count: 1)
-
- expect(page).to have_css('.wp-table--sum-container', text: 'Total sum')
- expect(page).to have_css('.wp-table--sum-container', text: '25')
- expect(page).to have_css('.wp-table--sum-container', text: '12')
- expect(page).to have_css('.wp-table--sum-container', text: '13.2')
- # Unit costs
- expect(page).to have_css('.wp-table--sum-container', text: '7.50')
- # Overall costs
- expect(page).to have_css('.wp-table--sum-container', text: '22.50')
- # Labor costs
- expect(page).to have_css('.wp-table--sum-container', text: '15.00')
+ within(:row, "Total sum") do |row|
+ expect(row).to have_css('.estimatedTime', text: '25 h')
+ expect(row).to have_css('.remainingTime', text: '12.5 h')
+ expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: '12')
+ expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: '13.2')
+ expect(row).to have_css('.overallCosts', text: '22.50 EUR')
+ expect(row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs
+ expect(row).to have_css('.laborCosts', text: '15.00 EUR')
+ end
# Update the sum
- edit_field = wp_table.edit_field(work_package_1, :estimatedTime)
- edit_field.update '20'
-
- expect(page).to have_css('.wp-table--sum-container', text: 'Total sum')
- expect(page).to have_css('.wp-table--sum-container', text: '35')
- expect(page).to have_css('.wp-table--sum-container', text: '12')
- expect(page).to have_css('.wp-table--sum-container', text: '13.2')
- # Unit costs
- expect(page).to have_css('.wp-table--sum-container', text: '7.50')
- # Overall costs
- expect(page).to have_css('.wp-table--sum-container', text: '22.50')
- # Labor costs
- expect(page).to have_css('.wp-table--sum-container', text: '15.00')
+ wp_table.edit_field(work_package1, :estimatedTime)
+ .update '20'
+ wp_table.edit_field(work_package1, :remainingTime)
+ .update '12'
+
+ within(:row, "Total sum") do |row|
+ expect(row).to have_css('.estimatedTime', text: '35 h')
+ expect(row).to have_css('.remainingTime', text: '19.5 h')
+ expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: '12')
+ expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: '13.2')
+ expect(row).to have_css('.overallCosts', text: '22.50 EUR')
+ expect(row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs
+ expect(row).to have_css('.laborCosts', text: '15.00 EUR')
+ end
# Enable groups
group_by.enable_via_menu 'Status'
# Expect to have three sums rows now
- expect(page).to have_css('.wp-table--sums-row', count: 3)
+ expect(page).to have_row('Sum', count: 2)
+ expect(page).to have_row('Total sum', count: 1)
+ first_sum_row, second_sum_row = *find_all(:row, 'Sum')
# First status row
- expect(page).to have_css('.wp-table--sum-container', text: '20 h')
- expect(page).to have_css(".wp-table--sum-container.customField#{int_cf.id}", text: '5')
- expect(page).to have_css(".wp-table--sum-container.customField#{float_cf.id}", text: '5.5')
- # Unit costs
- expect(page).to have_css('.wp-table--sum-container.materialCosts', text: '7.50')
- # Overall costs
- expect(page).to have_css('.wp-table--sum-container.overallCosts', text: '22.50')
- # Labor costs
- expect(page).to have_css('.wp-table--sum-container.laborCosts', text: '15.00')
+ expect(first_sum_row).to have_css('.estimatedTime', text: '20 h')
+ expect(first_sum_row).to have_css('.remainingTime', text: '12 h')
+ expect(first_sum_row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: '5')
+ expect(first_sum_row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: '5.5')
+ expect(first_sum_row).to have_css('.overallCosts', text: '22.50 EUR')
+ expect(first_sum_row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs
+ expect(first_sum_row).to have_css('.laborCosts', text: '15.00 EUR')
# Second status row
- expect(page).to have_css('.wp-table--sum-container', text: '15 h')
- expect(page).to have_css(".wp-table--sum-container.customField#{int_cf.id}", text: '7')
- expect(page).to have_css(".wp-table--sum-container.customField#{float_cf.id}", text: '7.7')
+ expect(second_sum_row).to have_css('.estimatedTime', text: '15 h')
+ expect(second_sum_row).to have_css('.remainingTime', text: '7.5 h')
+ expect(second_sum_row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: '7')
+ expect(second_sum_row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: '7.7')
+ expect(second_sum_row).to have_css('.overallCosts', text: '', exact_text: true)
+ expect(second_sum_row).to have_css('.materialCosts', text: '', exact_text: true) # Unit costs
+ expect(second_sum_row).to have_css('.laborCosts', text: '', exact_text: true)
# Total sums row is unchanged
- expect(page).to have_css('tbody .wp-table--sum-container', text: '35')
- expect(page).to have_css("tbody .wp-table--sum-container.customField#{int_cf.id}", text: '12')
- expect(page).to have_css("tbody .wp-table--sum-container.customField#{float_cf.id}", text: '13.2')
- # Unit costs
- expect(page).to have_css('tbody .wp-table--sum-container.materialCosts', text: '7.50')
- # Overall costs
- expect(page).to have_css('tbody .wp-table--sum-container.overallCosts', text: '22.50')
- # Labor costs
- expect(page).to have_css('tbody .wp-table--sum-container.laborCosts', text: '15.00')
+ within(:row, "Total sum") do |row|
+ expect(row).to have_css('.estimatedTime', text: '35 h')
+ expect(row).to have_css('.remainingTime', text: '19.5 h')
+ expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: '12')
+ expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: '13.2')
+ expect(row).to have_css('.overallCosts', text: '22.50 EUR')
+ expect(row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs
+ expect(row).to have_css('.laborCosts', text: '15.00 EUR')
+ end
# Collapsing groups will also hide the sums row
page.find('.expander.icon-minus2', match: :first).click
@@ -196,6 +205,7 @@ RSpec.describe 'Work package index sums', :js do
page.find('.expander.icon-minus2', match: :first).click
# Expect to have only the final sums
- expect(page).to have_css('tbody .wp-table--sums-row', count: 1)
+ expect(page).not_to have_row('Sum')
+ expect(page).to have_row('Total sum')
end
end