diff --git a/lib/open_project/pdf_export/taskboard_card/document_generator.rb b/lib/open_project/pdf_export/taskboard_card/document_generator.rb index 3241ab9c02..2bdddf8113 100644 --- a/lib/open_project/pdf_export/taskboard_card/document_generator.rb +++ b/lib/open_project/pdf_export/taskboard_card/document_generator.rb @@ -51,10 +51,12 @@ module OpenProject::PdfExport::TaskboardCard } card_element = CardElement.new(pdf, orientation, config.rows_hash, wp) + if i > 0 && i % @config.per_page == 0 + pdf.start_new_page + end card_element.draw if (i + 1) % @config.per_page == 0 - pdf.start_new_page card_y_offset = pdf.bounds.height - padding else card_y_offset -= (card_height + padding) diff --git a/spec/taskboard_card/document_generator_spec.rb b/spec/taskboard_card/document_generator_spec.rb index 741ccdd6cd..e9bf9710c5 100644 --- a/spec/taskboard_card/document_generator_spec.rb +++ b/spec/taskboard_card/document_generator_spec.rb @@ -1,27 +1,63 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe OpenProject::PdfExport::TaskboardCard::DocumentGenerator do - # let(:pdf) { Prawn::Document.new(:margin => 0) } let(:config) { TaskboardCardConfiguration.new({ name: "Default", identifier: "default", per_page: 1, page_size: "A4", orientation: "landscape", - rows: "rows:\n row1:\n has_border: false\n columns:\n id:\n has_label: false\n font_size: 15\n row1:\n has_border: false\n columns:\n subject:\n has_label: false\n font_size: 15" + rows: "rows:\n row1:\n has_border: false\n columns:\n subject:\n has_label: false\n font_size: 15\n row2:\n has_border: false\n columns:\n non_existent:\n has_label: false\n font_size: 15\n has_label: true\n render_if_empty: true" })} - let(:work_package) { WorkPackage.new({ - id: 1234, - subject: "Test work package", - description: "This is a test work package" + + let(:work_package1) { WorkPackage.new({ + subject: "Work package 1", + description: "This is work package 1" + })} + + let(:work_package2) { WorkPackage.new({ + subject: "Work package 2", + description: "This is work package 2" })} - it 'shows work package subject' do - work_packages = [work_package] - generator = OpenProject::PdfExport::TaskboardCard::DocumentGenerator.new(config, work_packages) + describe "Single work package rendering" do + before(:each) do + work_packages = [work_package1] + @generator = OpenProject::PdfExport::TaskboardCard::DocumentGenerator.new(config, work_packages) + end + + it 'shows work package subject' do + text_analysis = PDF::Inspector::Text.analyze(@generator.render) + text_analysis.strings.include?('Work package 1').should be_true + end + + it 'shows empty field label' do + text_analysis = PDF::Inspector::Text.analyze(@generator.render) + text_analysis.strings.include?('Non existent:-').should be_true + end + + it 'should be 1 page' do + page_analysis = PDF::Inspector::Page.analyze(@generator.render) + page_analysis.pages.size.should == 1 + end + end + + describe "Multiple work package rendering" do + before(:each) do + work_packages = [work_package1, work_package2] + @generator = OpenProject::PdfExport::TaskboardCard::DocumentGenerator.new(config, work_packages) + end + + it 'shows work package subject' do + text = PDF::Inspector::Text.analyze(@generator.render) + text.strings.include?('Work package 1').should be_true + text.strings.include?('Work package 2').should be_true + end - text = PDF::Inspector::Text.analyze(generator.render) - text.strings.join.should == 'Test work package' + it 'should be 2 pages' do + page_analysis = PDF::Inspector::Page.analyze(@generator.render) + page_analysis.pages.size.should == 2 + end end end \ No newline at end of file