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

test(pdf-export): remove filtered out work package attributes from tests, do not hardcode column names

as-opc5d840fee5fb
diff --git a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb
index b62e4467995..2d1c22fd36f 100644
--- a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb
+++ b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb
@@ -68,7 +68,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
q.sort_criteria = [%w[id asc]]
end
end
- let(:column_titles) { column_names.map { |name| WorkPackage.human_attribute_name(name).upcase } }
+ let(:column_titles) { column_names.map { |name| column_title(name) } }
let(:options) { {} }
let(:export) do
login_as(user)
@@ -82,17 +82,24 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
end
let(:column_names) { %i[id subject status story_points] }
+ def column_title(column_name)
+ label_title(column_name).upcase
+ end
+
+ def label_title(column_name)
+ WorkPackage.human_attribute_name(column_name)
+ end
+
def work_package_columns(work_package)
[work_package.id.to_s, work_package.subject, work_package.status.name, work_package.story_points.to_s]
end
def work_package_details(work_package, index)
["#{index}.", work_package.subject,
- 'ID', work_package.id.to_s,
- 'STATUS', work_package.status.name,
- 'STORY POINTS', work_package.story_points.to_s,
- 'Description',
- work_package.description]
+ column_title(:id), work_package.id.to_s,
+ column_title(:status), work_package.status.name,
+ column_title(:story_points), work_package.story_points.to_s,
+ label_title(:description), work_package.description]
end
subject(:pdf) do
@@ -137,11 +144,11 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
work_package_parent.type.name,
*column_titles,
*work_package_columns(work_package_parent),
- "Sum", work_package_parent.story_points.to_s,
+ I18n.t('js.label_sum'), work_package_parent.story_points.to_s,
work_package_child.type.name,
*column_titles,
*work_package_columns(work_package_child),
- "Sum", work_package_child.story_points.to_s,
+ I18n.t('js.label_sum'), work_package_child.story_points.to_s,
'1/1', export_time_formatted, query.name
])
end
@@ -190,9 +197,9 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
'1.', '2', work_package_parent.subject,
'2.', '2', work_package_child.subject,
'1/2', export_time_formatted, query.name,
- "Overview",
- "STORY POINTS",
- "Sum", (work_package_parent.story_points + work_package_child.story_points).to_s,
+ I18n.t('js.work_packages.tabs.overview'),
+ column_title(:story_points),
+ I18n.t('js.label_sum'), (work_package_parent.story_points + work_package_child.story_points).to_s,
*work_package_details(work_package_parent, 1),
*work_package_details(work_package_child, 2),
'2/2', export_time_formatted, query.name
@@ -210,11 +217,11 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
'1.', '2', work_package_parent.subject,
'2.', '2', work_package_child.subject,
'1/2', export_time_formatted, query.name,
- "Overview",
- "TYPE", "STORY POINTS",
+ I18n.t('js.work_packages.tabs.overview'),
+ column_title(:type), column_title(:story_points),
work_package_parent.type.name, work_package_parent.story_points.to_s,
work_package_child.type.name, work_package_child.story_points.to_s,
- "Sum", (work_package_parent.story_points + work_package_child.story_points).to_s,
+ I18n.t('js.label_sum'), (work_package_parent.story_points + work_package_child.story_points).to_s,
*work_package_details(work_package_parent, 1),
*work_package_details(work_package_child, 2),
'2/2', export_time_formatted, query.name
diff --git a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb
index 1062ab97c92..110a080256b 100644
--- a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb
+++ b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb
@@ -79,7 +79,16 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do
end
end
+ def column_title(column_name)
+ label_title(column_name).upcase
+ end
+
+ def label_title(column_name)
+ WorkPackage.human_attribute_name(column_name)
+ end
+
subject(:pdf) do
+ # File.binwrite('WorkPackageToPdf-test-preview.pdf', export_pdf.content)
PDF::Inspector::Text.analyze(export_pdf.content)
end
@@ -87,19 +96,13 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do
it 'contains correct data' do
expect(pdf.strings).to eq([
"#{type.name} ##{work_package.id} - #{work_package.subject}",
- 'ID', work_package.id.to_s,
- 'UPDATED ON', export_time_formatted,
- 'TYPE', type.name,
- 'CREATED ON', export_time_formatted,
- 'STATUS', work_package.status.name,
- 'FINISH DATE',
- 'VERSION',
- 'PRIORITY', work_package.priority.name,
- 'DURATION',
- 'WORK',
- 'CATEGORY',
- 'ASSIGNEE',
- 'Description',
+ column_title(:id), work_package.id.to_s,
+ column_title(:updated_at), export_time_formatted,
+ column_title(:type), type.name,
+ column_title(:created_at), export_time_formatted,
+ column_title(:status), work_package.status.name,
+ column_title(:priority), work_package.priority.name,
+ label_title(:description),
'Lorem', ' ', 'ipsum', ' ', 'dolor', ' ', 'sit', ' ',
'amet', ', consetetur sadipscing elitr.', ' ', '@OpenProject Admin',
'Image Caption',