Skip to content

Commit

Permalink
Suppress start stop list on weekends
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Nov 10, 2024
1 parent 562a8ad commit 97a1e69
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
6 changes: 4 additions & 2 deletions app/models/daily_packet/pdf_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def build
start_new_page
draw_top_three_page
start_new_page
draw_start_stop_list_page
start_new_page
unless daily_packet.built_on_weekend?
draw_start_stop_list_page
start_new_page
end
draw_chore_list_page
end

Expand Down
39 changes: 30 additions & 9 deletions spec/models/daily_packet/pdf_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

describe DailyPacket::PdfView do
let(:warm_fuzzy) { FactoryBot.create(:warm_fuzzy, received_at: Time.at(0)) }
let(:daily_packet) { FactoryBot.create(:daily_packet, built_on: built_on, warm_fuzzy: warm_fuzzy) }
let(:inspector) { PDF::Inspector::Page.analyze(daily_packet.pdf_data) }

let(:page_one_strings) { inspector.pages[0][:strings] }
let(:page_two_strings) { inspector.pages[1][:strings] }
let(:page_three_strings) { inspector.pages[2][:strings] }
let(:page_four_strings) { inspector.pages[3][:strings] }
let(:daily_packet) do
FactoryBot.create(:daily_packet, built_on: built_on, warm_fuzzy: warm_fuzzy)
end

include_context "pdf inspection"

describe "full packet" do
context "on a Tuesday" do
Expand Down Expand Up @@ -74,6 +73,28 @@
end
end

describe "start/stop list page" do
context "on a Monday" do
let(:built_on) { Date.parse("2024-11-04") }

it "renders the start/stop list page" do
expect(inspector.pages.size).to eq 4
expect(page_three_strings).to include "START LIST"
expect(page_three_strings).to include "STOP LIST"
end
end

context "on a Saturday" do
let(:built_on) { Date.parse("2024-11-09") }

it "suppresses the start/stop list page" do
expect(inspector.pages.size).to eq 3
expect(page_three_strings).to_not include "START LIST"
expect(page_three_strings).to_not include "STOP LIST"
end
end
end

describe "chore list page" do
context "on a Monday" do
let(:built_on) { Date.parse("2024-11-04") }
Expand All @@ -87,9 +108,9 @@
let(:built_on) { Date.parse("2024-11-09") }

it "renders the Weekend-specific chore but not the summertime ones" do
expect(page_four_strings).to include "collect laundry"
expect(page_three_strings).to include "collect laundry"

expect(page_four_strings).to_not include(
expect(page_three_strings).to_not include(
"poop patrol",
"mow front",
"mow back",
Expand All @@ -102,7 +123,7 @@
let(:built_on) { Date.parse("2024-07-13") }

it "renders the summertime Weekend-specific chores" do
expect(page_four_strings).to include(
expect(page_three_strings).to include(
"poop patrol",
"mow front",
"mow back",
Expand Down
28 changes: 28 additions & 0 deletions spec/support/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,31 @@
.to receive(:session_password_matches?).and_return(true)
end
end

shared_context "pdf inspection" do
let(:inspector) { PDF::Inspector::Page.analyze(daily_packet.pdf_data) }

let(:page_one_strings) do
page = inspector.pages[0]
return unless page
page[:strings]
end

let(:page_two_strings) do
page = inspector.pages[1]
return unless page
page[:strings]
end

let(:page_three_strings) do
page = inspector.pages[2]
return unless page
page[:strings]
end

let(:page_four_strings) do
page = inspector.pages[3]
return unless page
page[:strings]
end
end

0 comments on commit 97a1e69

Please sign in to comment.