Tests/OrgAppTests/OverdueBadgeTests.swift
49 lines · 1880 bytes
1import Foundation
2import OrgCore
3import OrgPresentation
4import Testing
5@testable import OrgApp
6
7struct OverdueBadgeTests {
8 static let file = """
9 * TODO Send forms
10 DEADLINE: <2026-10-02 Fri>
11 * TODO Water plants
12 SCHEDULED: <2026-10-05 Mon>
13 * DONE Took out bins
14 SCHEDULED: <2026-10-05 Mon>
15 * Standup
16 SCHEDULED: <2026-10-05 Mon 08:00>
17 * TODO Call the bank
18 SCHEDULED: <2026-10-06 Tue 09:30> DEADLINE: <2026-10-08 Thu>
19 * TODO Renew passport
20 DEADLINE: <2026-10-09 Fri>
21 * TODO Stretch
22 SCHEDULED: <2026-10-05 Mon .+1d>
23 :PROPERTIES:
24 :STYLE: habit
25 :END:
26 * Dentist <2026-10-06 Tue 13:50>
27 """
28
29 static let today = Days.absolute(year: 2026, month: 10, day: 5)
30
31 static func groups(today: Int) -> [AgendaDayGroup] {
32 let source = AgendaSource(path: "/notes/life.org", text: file, defaults: .default)
33 return AgendaRows.groups(Agenda.list([source], start: today, days: 7, today: today, now: (10, 0)), today: today)
34 }
35
36 /// The entries in the agenda's own Overdue section on each later day; an entry past both its
37 /// scheduled day and its deadline has two rows there.
38 @Test func projectsWhatTheAgendaShowsOnLaterDays() {
39 let counts = OverdueBadge.counts(Self.groups(today: Self.today), today: Self.today, days: 7)
40 let actual = (0..<7).map { k in
41 let day = Self.today + k
42 let rows = Self.groups(today: day).first { $0.day == day }?.overdue.filter { !$0.isDone && $0.item?.habit == nil } ?? []
43 return Set(rows.compactMap { $0.item?.headingOffset }).count
44 }
45 #expect(counts == actual)
46 // Send forms; then Water plants and Standup; Call the bank; Renew passport after the 9th.
47 #expect(counts == [1, 3, 4, 4, 4, 5, 5])
48 }
49}