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

Refactor `calculations_spec` and switch it over to cuprite

Aaron Contreras1dcc01e0877a
diff --git a/modules/reporting/spec/features/calculations_spec.rb b/modules/reporting/spec/features/calculations_spec.rb
index a5a26d04912..096b2905a07 100644
--- a/modules/reporting/spec/features/calculations_spec.rb
+++ b/modules/reporting/spec/features/calculations_spec.rb
@@ -1,48 +1,38 @@
require 'spec_helper'
-RSpec.describe 'Cost report calculations', js: true do
+RSpec.describe 'Cost Report', 'calculations', :js, :with_cuprite do
let(:project) { create(:project) }
let(:user) { create(:admin) }
-
let(:work_package) { create(:work_package, project:) }
- let!(:hourly_rate1) { create(:default_hourly_rate, user:, rate: 1.00, valid_from: 1.year.ago) }
- let!(:hourly_rate2) { create(:default_hourly_rate, user:, rate: 5.00, valid_from: 2.years.ago) }
- let!(:hourly_rate3) { create(:default_hourly_rate, user:, rate: 10.00, valid_from: 3.years.ago) }
- let!(:time_entry1) do
- create(:time_entry,
- spent_on: 6.months.ago,
- user:,
- work_package:,
- project:,
- hours: 10)
- end
- let!(:time_entry2) do
- create(:time_entry,
- spent_on: 18.months.ago,
- user:,
- work_package:,
- project:,
- hours: 10)
+ def create_hourly_rates
+ create(:default_hourly_rate, user:, rate: 1.00, valid_from: 1.year.ago)
+ create(:default_hourly_rate, user:, rate: 5.00, valid_from: 2.years.ago)
+ create(:default_hourly_rate, user:, rate: 10.00, valid_from: 3.years.ago)
end
- let!(:time_entry3) do
- create(:time_entry,
- spent_on: 30.months.ago,
- user:,
- work_package:,
- project:,
- hours: 10)
+
+ def create_time_entries_on(*timestamps_of_recordings)
+ timestamps_of_recordings.each do |spent_on|
+ create(:time_entry,
+ spent_on:,
+ user:,
+ work_package:,
+ project:,
+ hours: 10)
+ end
end
before do
- login_as(user)
+ create_hourly_rates
+ create_time_entries_on(6.months.ago, 18.months.ago, 30.months.ago)
+ login_as user
visit '/cost_reports?set_filter=1'
end
it 'shows the correct calculations' do
- expect(page).to have_text '10.00' # 1 EUR x 10
- expect(page).to have_text '50.00' # 5 EUR x 10
+ expect(page).to have_text '10.00' # 1 EUR x 10
+ expect(page).to have_text '50.00' # 5 EUR x 10
expect(page).to have_text '100.00' # 10 EUR x 10
- expect(page).to have_text '160.00'
+ expect(page).to have_text '160.00' # Total
end
end