Skip to content

Commit

Permalink
Simplify top three page and update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Nov 7, 2024
1 parent 3dfb5ba commit 3c3d22d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 95 deletions.
29 changes: 15 additions & 14 deletions app/models/daily_packet/pdf_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def draw_front_page
end

def draw_top_three_page
text "Top Three".upcase, style: :bold_italic, size: 42
text "Top 3: Personal".upcase, style: :bold_italic, size: 42

move_up 12

Expand All @@ -80,31 +80,32 @@ def draw_top_three_page

move_down 20

text "Personal", size: 30

move_down 10

font_size(20) do
text "1. #{"_" * 40}"
text "1."
move_down 10
text "2. #{"_" * 40}"
text "2."
move_down 10
text "3. #{"_" * 40}"
text "3."
end

unless daily_packet.built_on_weekend?
move_down 20
move_cursor_to bounds.top / 2
text "Top 3: Work".upcase, style: :bold_italic, size: 42

text "Work", size: 30
move_up 12

move_down 10
stroke do
horizontal_rule
end

move_down 20

font_size(20) do
text "1. #{"_" * 40}"
text "1."
move_down 10
text "2. #{"_" * 40}"
text "2."
move_down 10
text "3. #{"_" * 40}"
text "3."
end
end
end
Expand Down
169 changes: 88 additions & 81 deletions spec/models/daily_packet/pdf_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,110 +4,117 @@
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) }

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

it "renders the document" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)

expect(inspector.pages.size).to eq 3

page_one_strings, page_two_strings, page_three_strings = inspector.pages.map { |page| page[:strings] }

expect(page_one_strings).to eq([
"DAILY PACKET #19",
"11/05/2024",
"week 45",
"Random Warm Fuzzy",
"Alright Haircut",
"Your haircut is adequate.",
"- Wife, 01/01/1970",
"Reading Pace",
"7.7 pages/day",
"Feedbin Stats",
"unread: 9",
"oldest: 14 days ago"
])

expect(page_two_strings).to eq([
"TOP THREE",
"Personal",
"1. #{"_" * 40}",
"2. #{"_" * 40}",
"3. #{"_" * 40}",
"Work",
"1. #{"_" * 40}",
"2. #{"_" * 40}",
"3. #{"_" * 40}"
])

expect(page_three_strings).to eq([
"CHORE LIST",
"unload dishwasher",
"defrost meat",
"wipe off kitchen table",
"run dishwasher"
])
describe "full packet" do
context "on a Tuesday" do
let(:built_on) { Date.parse("2024-11-05") }

it "renders the document" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)

expect(inspector.pages.size).to eq 3

page_one_strings,
page_two_strings,
page_three_strings = inspector.pages.map { |page| page[:strings] }

expect(page_one_strings).to eq([
"DAILY PACKET #19",
"11/05/2024",
"week 45",
"Random Warm Fuzzy",
"Alright Haircut",
"Your haircut is adequate.",
"- Wife, 01/01/1970",
"Reading Pace",
"7.7 pages/day",
"Feedbin Stats",
"unread: 9",
"oldest: 14 days ago"
])

expect(page_two_strings).to eq([
"TOP 3: PERSONAL",
"1.",
"2.",
"3.",
"TOP 3: WORK",
"1.",
"2.",
"3."
])

expect(page_three_strings).to eq([
"CHORE LIST",
"unload dishwasher",
"defrost meat",
"wipe off kitchen table",
"run dishwasher"
])
end
end
end

context "on a Monday" do
let(:built_on) { Date.parse("2024-11-04") }
describe "top three page" do
context "on a Saturday" do
let(:built_on) { Date.parse("2024-11-09") }

it "renders the Monday-specific chore" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)
it "does not render the work top three section" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)

_, _, page_three_strings = inspector.pages.map { |page| page[:strings] }
page_two_strings = inspector.pages[1][:strings]

expect(page_three_strings).to include "put out garbage cans"
expect(page_two_strings).to_not include "TOP 3: WORK"
end
end
end

context "on a Saturday" do
let(:built_on) { Date.parse("2024-11-09") }
describe "chore list page" do
context "on a Monday" do
let(:built_on) { Date.parse("2024-11-04") }

it "does not render the work top three section" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)
it "renders the Monday-specific chore" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)

_, page_two_strings, _ = inspector.pages.map { |page| page[:strings] }
page_five_strings = inspector.pages.last[:strings]

expect(page_two_strings).to_not include "Work"
expect(page_five_strings).to include "put out garbage cans"
end
end
end

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

it "renders the Weekend-specific chore but not the summertime ones" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)
it "renders the Weekend-specific chore but not the summertime ones" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)

_, _, page_three_strings = inspector.pages.map { |page| page[:strings] }
page_five_strings = inspector.pages.last[:strings]

expect(page_three_strings).to include "collect laundry"
expect(page_five_strings).to include "collect laundry"

expect(page_three_strings).to_not include(
"poop patrol",
"mow front",
"mow back",
"mow way back"
)
expect(page_five_strings).to_not include(
"poop patrol",
"mow front",
"mow back",
"mow way back"
)
end
end
end

context "on a Saturday in the summer" do
let(:built_on) { Date.parse("2024-07-13") }
context "on a Saturday in the summer" do
let(:built_on) { Date.parse("2024-07-13") }

it "renders the summertime Weekend-specific chores" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)
it "renders the summertime Weekend-specific chores" do
inspector = PDF::Inspector::Page.analyze(daily_packet.pdf_data)

_, _, page_three_strings = inspector.pages.map { |page| page[:strings] }
page_five_strings = inspector.pages.last[:strings]

expect(page_three_strings).to include(
"poop patrol",
"mow front",
"mow back",
"mow way back"
)
expect(page_five_strings).to include(
"poop patrol",
"mow front",
"mow back",
"mow way back"
)
end
end
end
end

0 comments on commit 3c3d22d

Please sign in to comment.