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
[50962] Add feature test for query sums with filters
Christophe Bliard2bb40dc8bcfd
diff --git a/spec/factories/query_factory.rb b/spec/factories/query_factory.rbindex 471d5d05900..984e4cbdf62 100644--- a/spec/factories/query_factory.rb+++ b/spec/factories/query_factory.rb@@ -31,6 +31,8 @@ FactoryBot.define doprojectuser factory: :userinclude_subprojects { Setting.display_subprojects_work_packages? }+ show_hierarchies { false }+ display_sums { false }sequence(:name) { |n| "Query #{n}" }factory :public_query dodiff --git a/spec/features/work_packages/index_sums_spec.rb b/spec/features/work_packages/index_sums_spec.rbindex 189d1f412b8..ee9097e4027 100644--- a/spec/features/work_packages/index_sums_spec.rb+++ b/spec/features/work_packages/index_sums_spec.rb@@ -29,6 +29,12 @@require 'spec_helper'RSpec.describe 'Work package index sums', :js do+ shared_let(:type_bug) { create(:type_bug) }+ shared_let(:type_task) { create(:type_task) }+ shared_let(:status_new) { create(:status, name: 'New') }+ shared_let(:status_in_progress) { create(:status, name: 'In progress') }+ shared_let(:project) { create(:project, types: [type_bug, type_task]) }+let(:user) docreate(:user,member_with_permissions: { project => %i[view_own_hourly_rate@@ -39,27 +45,25 @@ RSpec.describe 'Work package index sums', :js doview_cost_rateslog_costs] })end- let(:project) do- create(:project,- name: 'project1',- identifier: 'project1')- end- let(:type) { create(:type) }let!(:int_cf) docreate(:integer_wp_custom_field) do |cf|project.work_package_custom_fields << cf- type.custom_fields << cf+ type_bug.custom_fields << cf+ type_task.custom_fields << cfendendlet!(:float_cf) docreate(:float_wp_custom_field) do |cf|project.work_package_custom_fields << cf- type.custom_fields << cf+ type_bug.custom_fields << cf+ type_task.custom_fields << cfendendlet!(:work_package1) docreate(:work_package,- project:, type:,+ project:,+ type: type_bug,+ status: status_new,estimated_hours: 10,remaining_hours: 5) do |wp|wp.custom_field_values = { int_cf.id => 5, float_cf.id => 5.5 }@@ -69,13 +73,15 @@ RSpec.describe 'Work package index sums', :js dolet!(:work_package2) docreate(:work_package,project:,- type:,+ type: type_task,+ status: status_in_progress,estimated_hours: 15,remaining_hours: 7.5) do |wp|wp.custom_field_values = { int_cf.id => 7, float_cf.id => 7.7 }wp.save!endend+ # labor costslet!(:hourly_rate) docreate(:default_hourly_rate,user:,@@ -88,6 +94,7 @@ RSpec.describe 'Work package index sums', :js doproject:,hours: 1.50)end+ # unit costslet(:cost_type) dotype = create(:cost_type, name: 'Translations')create(:cost_rate,@@ -108,6 +115,7 @@ RSpec.describe 'Work package index sums', :js dolet(:columns) { Components::WorkPackages::Columns.new }let(:modal) { Components::WorkPackages::TableConfigurationModal.new }let(:group_by) { Components::WorkPackages::GroupBy.new }+ let(:filters) { Components::WorkPackages::Filters.new }current_user { user }@@ -123,12 +131,12 @@ RSpec.describe 'Work package index sums', :js docolumns.add int_cf.name# Add float cf columncolumns.add float_cf.name- # Add overall costs column- columns.add 'Overall costs'- # Add unit costs column- columns.add 'Unit costs'# Add labor costs columncolumns.add 'Labor costs'+ # Add unit costs column+ columns.add 'Unit costs'+ # Add overall costs column+ columns.add 'Overall costs'# Trigger action from action menu dropdownmodal.set_display_sums enable: true@@ -141,9 +149,9 @@ RSpec.describe 'Work package index sums', :js doexpect(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 costsexpect(row).to have_css('.laborCosts', text: '15.00 EUR')+ expect(row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs+ expect(row).to have_css('.overallCosts', text: '22.50 EUR')end# Update the sum@@ -157,9 +165,9 @@ RSpec.describe 'Work package index sums', :js doexpect(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 costsexpect(row).to have_css('.laborCosts', text: '15.00 EUR')+ expect(row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs+ expect(row).to have_css('.overallCosts', text: '22.50 EUR')end# Enable groups@@ -175,18 +183,18 @@ RSpec.describe 'Work package index sums', :js doexpect(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 costsexpect(first_sum_row).to have_css('.laborCosts', text: '15.00 EUR')+ expect(first_sum_row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs+ expect(first_sum_row).to have_css('.overallCosts', text: '22.50 EUR')# Second status rowexpect(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 costsexpect(second_sum_row).to have_css('.laborCosts', 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('.overallCosts', text: '', exact_text: true)# Total sums row is unchangedwithin(:row, "Total sum") do |row|@@ -194,9 +202,9 @@ RSpec.describe 'Work package index sums', :js doexpect(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 costsexpect(row).to have_css('.laborCosts', text: '15.00 EUR')+ expect(row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs+ expect(row).to have_css('.overallCosts', text: '22.50 EUR')end# Collapsing groups will also hide the sums row@@ -208,4 +216,130 @@ RSpec.describe 'Work package index sums', :js doexpect(page).not_to have_row('Sum')expect(page).to have_row('Total sum')end++ context 'when filtering' do+ let!(:work_package3) do+ create(:work_package,+ project:,+ type: type_bug,+ status: status_in_progress,+ 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_package4) do+ create(:work_package,+ project:,+ type: type_task,+ status: status_new,+ 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+ end+ # labor costs+ let!(:time_entry2) do+ create(:time_entry,+ user:,+ work_package: work_package3,+ project:,+ hours: 2.50)+ end+ # unit costs+ let!(:cost_entry2) do+ create(:cost_entry,+ work_package: work_package3,+ project:,+ units: 3.50,+ cost_type:,+ user:)+ end++ it 'calculates sums correctly' do+ query = create(:query,+ project:,+ user:,+ display_sums: true,+ column_names: [:id, :subject, :type, :status, :estimated_hours, :remaining_hours,+ :"#{int_cf.column_name}", :"#{float_cf.column_name}",+ :labor_costs, :material_costs, :overall_costs])+ wp_table.visit_query query+ wp_table.expect_work_package_listed work_package1, work_package2, work_package3, work_package4++ # Expect the total sums row without filtering+ within(:row, "Total sum") do |row|+ expect(row).to have_css('.estimatedTime', text: '50 h')+ expect(row).to have_css('.remainingTime', text: '25 h')+ expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: '24')+ expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: '26.4')+ expect(row).to have_css('.laborCosts', text: '40.00 EUR')+ expect(row).to have_css('.materialCosts', text: '18.00 EUR') # Unit costs+ expect(row).to have_css('.overallCosts', text: '58.00 EUR')+ end++ # Filter+ filters.open+ filters.add_filter_by('Type', 'is (OR)', type_task.name)+ puts Capybara::Screenshot.screenshot_and_save_page++ # Expect 2 work packages shown+ expect(page).to have_row('WorkPackage', count: 2) # works because the subject name includes "WorkPackage"++ # Expect the total sums row to have changed+ within(:row, "Total sum") do |row|+ expect(row).to have_css('.estimatedTime', text: '30 h')+ expect(row).to have_css('.remainingTime', text: '15 h')+ expect(row).to have_css(".#{int_cf.attribute_name(:camel_case)}", text: '14')+ expect(row).to have_css(".#{float_cf.attribute_name(:camel_case)}", text: '15.4')+ expect(row).to have_css('.laborCosts', text: '', exact_text: true)+ expect(row).to have_css('.materialCosts', text: '', exact_text: true) # Unit costs+ expect(row).to have_css('.overallCosts', text: '', exact_text: true)+ end++ # Filter by status open+ filters.remove_filter('type')+ filters.remove_filter('status')+ filters.add_filter_by('Status', 'is (OR)', status_new.name)++ # Enable groups by type+ group_by.enable_via_menu 'Type'++ # Expect to have three sums rows now+ 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(first_sum_row).to have_css('.estimatedTime', text: '10 h')+ expect(first_sum_row).to have_css('.remainingTime', text: '5 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('.laborCosts', text: '15.00 EUR')+ expect(first_sum_row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs+ expect(first_sum_row).to have_css('.overallCosts', text: '22.50 EUR')++ # Second status row+ 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('.laborCosts', 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('.overallCosts', text: '', exact_text: true)++ # Total sum+ 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('.laborCosts', text: '15.00 EUR')+ expect(row).to have_css('.materialCosts', text: '7.50 EUR') # Unit costs+ expect(row).to have_css('.overallCosts', text: '22.50 EUR')+ end+ end+ endend