Skip to content

Commit f6921bb

Browse files
committed
Test: Adds overlooked cases for picklist pdf
1 parent 486b440 commit f6921bb

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

app/pdfs/picklists_pdf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "prawn/table"
2+
13
# Configures a Prawn PDF template for generating Distribution manifests
24
class PicklistsPdf
35
include Prawn::View

spec/pdfs/picklists_pdf_spec.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
describe "#compute_and_render" do
77
it "renders multiple requests correctly" do
8-
request1 = create(:request, :pending, organization: organization)
9-
request2 = create(:request, :pending, organization: organization)
8+
request1 = create(:request, :pending, organization: organization, comments: "Request 1 comments")
9+
request2 = create(:request, :pending, organization: organization, comments: "Request 2 comments")
1010
create(:item_request, request: request1, item: item1, name: "Item 1")
1111
create(:item_request, request: request2, item: item2, name: "Item 2")
1212

@@ -19,6 +19,7 @@
1919
expect(pdf_test.page(1).text).to include("Requested on:")
2020
expect(pdf_test.page(1).text).to include("Items Received Year-to-Date:")
2121
expect(pdf_test.page(1).text).to include("Comments")
22+
expect(pdf_test.page(1).text).to include(request1.comments)
2223
expect(pdf_test.page(1).text).to include("Items Requested")
2324
expect(pdf_test.page(1).text).to include("Item 1")
2425

@@ -28,10 +29,29 @@
2829
expect(pdf_test.page(2).text).to include("Requested on:")
2930
expect(pdf_test.page(2).text).to include("Items Received Year-to-Date:")
3031
expect(pdf_test.page(2).text).to include("Comments")
32+
expect(pdf_test.page(2).text).to include(request2.comments)
3133
expect(pdf_test.page(2).text).to include("Items Requested")
3234
expect(pdf_test.page(2).text).to include("Item 2")
3335
end
3436

37+
context "when ytd_on_distribution_printout is enabled for the organization" do
38+
before { organization.update(ytd_on_distribution_printout: true) }
39+
40+
it "renders the YTD quantity" do
41+
partner = create(:partner)
42+
request = create(:request, :pending, organization: organization, partner: partner)
43+
create(:item_request, request: request, item: item1, name: "Item 1", quantity: 17)
44+
45+
# stub out the quantity_year_to_date method, it's not the PDF's job to make sure the calculation is correct
46+
allow(partner).to receive(:quantity_year_to_date).and_return(17827)
47+
pdf = described_class.new(organization, [request])
48+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
49+
50+
expect(pdf_test.page(1).text).to include("Items Received Year-to-Date:")
51+
expect(pdf_test.page(1).text).to include("17827")
52+
end
53+
end
54+
3555
context "When partner pickup person is set" do
3656
it "renders pickup person details" do
3757
partner = create(:partner)

0 commit comments

Comments
 (0)