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
add specs for time entry times in xls & basic-table
as-op165aa7c5f5f3
diff --git a/modules/reporting/spec/features/export_cost_report_spec.rb b/modules/reporting/spec/features/export_cost_report_spec.rbindex 8301e541d6d..99c2b943290 100644--- a/modules/reporting/spec/features/export_cost_report_spec.rb+++ b/modules/reporting/spec/features/export_cost_report_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -29,18 +31,36 @@require_relative "../spec_helper"require_relative "support/pages/cost_report_page"-RSpec.describe "Cost reports XLS export", :js do+RSpec.describe "Cost reports XLS export", :js, with_flag: { track_start_and_end_times_for_time_entries: true } doshared_let(:project) { create(:project) }shared_let(:user) { create(:admin) }shared_let(:cost_type) { create(:cost_type, name: "Post-war", unit: "cap", unit_plural: "caps") }shared_let(:work_package) { create(:work_package, project:, subject: "Some task") }- shared_let(:cost_entry) { create(:cost_entry, user:, work_package:, project:, cost_type:) }+ shared_let(:cost_entry) do+ create(:cost_entry, user:, work_package:, project:,+ cost_type:, spent_on: 3.days.ago)+ end+ shared_let(:time_entry) do+ create(:time_entry, user:, work_package:, project:,+ start_time: 1 * 60,+ spent_on: 2.days.ago,+ hours: 1.0,+ time_zone: "UTC")+ end+ shared_let(:time_entry_long) do+ create(:time_entry, user:, work_package:, project:,+ start_time: 1 * 60,+ spent_on: 1.day.ago,+ hours: 28.0,+ time_zone: "UTC")+ end+let(:report_page) { Pages::CostReportPage.new project }let(:sheet) { @download_list.refresh_from(page).latest_downloaded_content } # rubocop:disable RSpec/InstanceVariablesubject doio = StringIO.new sheet- Spreadsheet.open(io).worksheets.first+ Spreadsheet.open(io).worksheetsendbefore do@@ -52,7 +72,70 @@ RSpec.describe "Cost reports XLS export", :js doDownloadList.clearend- it "can download and open the XLS" do+ def expect_custom_cost_entry(cost_entry_row)+ date, user_ref, _, wp_ref, _, project_ref, costs, type, = cost_entry_row+ expect(date).to eq(cost_entry.spent_on.iso8601)+ expect(user_ref).to eq(user.name)+ expect(wp_ref).to include "Some task"+ expect(project_ref).to eq project.name+ expect(costs).to eq 1.0+ expect(type).to eq "Post-war"+ end++ def expect_labor_cost_entry(cost_entry_row, entry)+ date, user_ref, _, wp_ref, _, project_ref, costs, type, = cost_entry_row+ expect(date).to eq(entry.spent_on.iso8601)+ expect(user_ref).to eq(user.name)+ expect(wp_ref).to include "Some task"+ expect(project_ref).to eq project.name+ expect(costs).to eq entry.hours+ expect(type).to eq "Labor"+ end++ def expect_time_entry(time_entry_row, entry, start_time_value, end_time_value)+ date, start_time, end_time, user_ref, _, wp_ref, _, project_ref, costs, type, = time_entry_row+ expect(date).to eq(entry.spent_on.iso8601)+ expect(start_time).to eq start_time_value+ expect(end_time).to eq end_time_value+ expect(user_ref).to eq(user.name)+ expect(wp_ref).to include "Some task"+ expect(project_ref).to eq project.name+ expect(costs).to eq entry.hours+ expect(type).to eq "Labor"+ end++ def expect_sheet_title(title)+ expect(title.first).to include("Cost reports (#{Time.zone.today.strftime('%m/%d/%Y')})")+ end++ def expect_cost_entries_sheet+ title, _, cost_entry_row, time_entry_row, time_entry_long_row = subject.first.rows+ expect_sheet_title title+ expect_custom_cost_entry cost_entry_row+ expect_labor_cost_entry time_entry_row, time_entry+ expect_labor_cost_entry time_entry_long_row, time_entry_long+ end++ def expect_time_entries_sheet(allow_show_start_and_end_times)+ title, _, time_entry_row, time_entry_long_row = subject.second.rows+ expect_sheet_title title+ if allow_show_start_and_end_times+ expect_time_entry time_entry_row, time_entry, "01:00 AM", "02:00 AM"+ expect_time_entry time_entry_long_row, time_entry_long, "01:00 AM",+ "#{(time_entry_long.spent_on + 1.day).iso8601} 05:00 AM"+ else+ expect_labor_cost_entry time_entry_row, time_entry+ expect_labor_cost_entry time_entry_long_row, time_entry_long+ end+ end++ def expect_custom_type_entries_sheet+ title, _, cost_entry = subject.third.rows+ expect_sheet_title title+ expect_custom_cost_entry cost_entry+ end++ def export_xlsreport_page.visit!click_on "Export XLS"@@ -61,16 +144,23 @@ RSpec.describe "Cost reports XLS export", :js doperform_enqueued_jobsexpect(page).to have_text(I18n.t("export.succeeded"))+ end- title, _, entry, = subject.rows- expect(title.first).to include("Cost reports (#{Time.zone.today.strftime('%m/%d/%Y')})")- date, user_ref, _, wp_ref, _, project_ref, costs, type, = entry+ context "with allow_tracking_start_and_end_times", with_settings: { allow_tracking_start_and_end_times: true } do+ it "can download and open the XLS" do+ export_xls+ expect_cost_entries_sheet+ expect_time_entries_sheet true+ expect_custom_type_entries_sheet+ end+ end- expect(date).to eq(Time.zone.today.iso8601)- expect(user_ref).to eq(user.name)- expect(wp_ref).to include "Some task"- expect(project_ref).to eq project.name- expect(costs).to eq 1.0- expect(type).to eq "Post-war"+ context "without allow_tracking_start_and_end_times", with_settings: { allow_tracking_start_and_end_times: false } do+ it "can download and open the XLS" do+ export_xls+ expect_cost_entries_sheet+ expect_time_entries_sheet false+ expect_custom_type_entries_sheet+ endendenddiff --git a/modules/reporting/spec/features/support/components/cost_reports_base_table.rb b/modules/reporting/spec/features/support/components/cost_reports_base_table.rbindex 965aab2b636..ab386d906d1 100644--- a/modules/reporting/spec/features/support/components/cost_reports_base_table.rb+++ b/modules/reporting/spec/features/support/components/cost_reports_base_table.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -58,6 +60,18 @@ module Componentsexpect(page).to have_css("#{row_selector(row)} .units", text: value)end+ def expect_cell_text(value, row, column)+ expect(page).to have_css(cell_selector(row, column), text: value)+ end++ def expect_sort_header_column(text, present: true)+ if present+ expect(page).to have_css("#result-table .generic-table--sort-header", text:)+ else+ expect(page).to have_no_css("#result-table .generic-table--sort-header", text:)+ end+ end+def edit_time_entry(row, hours:)SeleniumHubWaiter.waitpage.find("#{row_selector(row)} .icon-edit").click@@ -82,7 +96,7 @@ module ComponentsSeleniumHubWaiter.waitpage.find("#{row_selector(row)} .icon-edit").click- expect(page).to have_current_path("/cost_entries/" + cost_entry_id + "/edit")+ expect(page).to have_current_path("/cost_entries/#{cost_entry_id}/edit")SeleniumHubWaiter.waitfill_in("cost_entry_units", with: new_value)@@ -106,5 +120,9 @@ module Componentsdef row_selector(row)"#result-table tbody tr:nth-of-type(#{row})"end++ def cell_selector(row, column)+ "#{row_selector(row)} td:nth-of-type(#{column})"+ endendenddiff --git a/modules/reporting/spec/features/time_entries_spec.rb b/modules/reporting/spec/features/time_entries_spec.rbnew file mode 100644index 00000000000..c919ac1a0b3--- /dev/null+++ b/modules/reporting/spec/features/time_entries_spec.rb@@ -0,0 +1,54 @@+# frozen_string_literal: true++require "spec_helper"+require_relative "support/pages/cost_report_page"+require_relative "support/components/cost_reports_base_table"++RSpec.describe "Cost report showing time entries with start & end times", :js,+ with_flag: { track_start_and_end_times_for_time_entries: true } do+ shared_let(:project) { create(:project) }+ shared_let(:user) { create(:admin) }+ shared_let(:work_package) { create(:work_package, project:) }+ shared_let(:time_entry) do+ create :time_entry, user:, work_package:, project:,+ start_time: 1 * 60,+ spent_on: 1.day.ago,+ hours: 1.0,+ time_zone: "UTC"+ end+ shared_let(:time_entry_long) do+ create :time_entry, user:, work_package:, project:,+ start_time: 1 * 60,+ hours: 28.0,+ time_zone: "UTC"+ end+ let(:report_page) { Pages::CostReportPage.new project }+ let(:table) { Components::CostReportsBaseTable.new }++ before do+ login_as(user)+ report_page.visit!+ report_page.clear+ report_page.apply+ end++ context "with allow_tracking_start_and_end_times", with_settings: { allow_tracking_start_and_end_times: true } do+ it "shows the time column" do+ table.expect_sort_header_column("TIME", present: true)+ table.rows_count 2++ table.expect_value("1.00 hours", 1)+ table.expect_cell_text("01:00 AM - 02:00 AM", 1, 2)++ table.expect_value("28.00 hours", 2)+ table.expect_cell_text("01:00 AM - 05:00 AM (+1d)", 2, 2)+ end+ end++ context "without allow_tracking_start_and_end_times", with_settings: { allow_tracking_start_and_end_times: false } do+ it "does not show the time column" do+ table.expect_sort_header_column("TIME", present: false)+ table.rows_count 2+ end+ end+end