From 97a1e694ee9b3fb1763e29b932a0769a065f321b Mon Sep 17 00:00:00 2001 From: Jon Allured Date: Sun, 10 Nov 2024 07:47:15 -0600 Subject: [PATCH] Suppress start stop list on weekends --- app/models/daily_packet/pdf_view.rb | 6 ++-- spec/models/daily_packet/pdf_view_spec.rb | 39 +++++++++++++++++------ spec/support/shared.rb | 28 ++++++++++++++++ 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/app/models/daily_packet/pdf_view.rb b/app/models/daily_packet/pdf_view.rb index c4fd1be..2ea774b 100644 --- a/app/models/daily_packet/pdf_view.rb +++ b/app/models/daily_packet/pdf_view.rb @@ -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 diff --git a/spec/models/daily_packet/pdf_view_spec.rb b/spec/models/daily_packet/pdf_view_spec.rb index c613f90..19c1490 100644 --- a/spec/models/daily_packet/pdf_view_spec.rb +++ b/spec/models/daily_packet/pdf_view_spec.rb @@ -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 @@ -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") } @@ -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", @@ -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", diff --git a/spec/support/shared.rb b/spec/support/shared.rb index 1052a12..fa33cbf 100644 --- a/spec/support/shared.rb +++ b/spec/support/shared.rb @@ -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