diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-02-03 15:16:35 -1000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-02-03 15:16:35 -1000 |
| commit | 25a5b7ecf9ddd31da54e91f87988b77aea857571 (patch) | |
| tree | 30654edbdd966cea316a5f54a99474aad337cf58 /internal/handlers/timeline_logic_test.go | |
| parent | 9f35f7149d8fb790bbe8e4f0ee74f895aea1fc58 (diff) | |
Add comprehensive test coverage across packages
New test files:
- api/http_test.go: HTTP client and error handling tests
- config/config_test.go: Configuration loading and validation tests
- middleware/security_test.go: Security middleware tests
- models/atom_test.go: Atom model and conversion tests
Expanded test coverage:
- api/todoist_test.go: Todoist API client tests
- api/trello_test.go: Trello API client tests
- auth/auth_test.go: Authentication and CSRF tests
- handlers/timeline_logic_test.go: Timeline building logic tests
- store/sqlite_test.go: SQLite store operations tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/handlers/timeline_logic_test.go')
| -rw-r--r-- | internal/handlers/timeline_logic_test.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/internal/handlers/timeline_logic_test.go b/internal/handlers/timeline_logic_test.go index 5fe995f..9a71741 100644 --- a/internal/handlers/timeline_logic_test.go +++ b/internal/handlers/timeline_logic_test.go @@ -162,3 +162,95 @@ func TestBuildTimeline(t *testing.T) { t.Errorf("Expected item 3 to be Card, got %s", items[3].Type) } } + +func TestCalcCalendarBounds(t *testing.T) { + tests := []struct { + name string + items []models.TimelineItem + currentHour int + wantStart int + wantEnd int + }{ + { + name: "no timed events returns default", + items: []models.TimelineItem{}, + currentHour: -1, + wantStart: 8, + wantEnd: 18, + }, + { + name: "single event at 10am", + items: []models.TimelineItem{ + {Time: time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC)}, + }, + currentHour: -1, + wantStart: 9, // 1 hour buffer before + wantEnd: 11, // 1 hour buffer after + }, + { + name: "includes current hour", + items: []models.TimelineItem{ + {Time: time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC)}, + }, + currentHour: 8, + wantStart: 7, // 1 hour before 8am + wantEnd: 11, // 1 hour after 10am + }, + { + name: "event with end time extends range", + items: []models.TimelineItem{ + { + Time: time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC), + EndTime: timePtr(time.Date(2023, 1, 1, 14, 0, 0, 0, time.UTC)), + }, + }, + currentHour: -1, + wantStart: 9, // 1 hour before 10am + wantEnd: 15, // 1 hour after 2pm end + }, + { + name: "all-day events are skipped", + items: []models.TimelineItem{ + {Time: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC), IsAllDay: true}, + }, + currentHour: -1, + wantStart: 8, + wantEnd: 18, + }, + { + name: "overdue events are skipped", + items: []models.TimelineItem{ + {Time: time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC), IsOverdue: true}, + }, + currentHour: -1, + wantStart: 8, + wantEnd: 18, + }, + { + name: "clamps to 0-23 range", + items: []models.TimelineItem{ + {Time: time.Date(2023, 1, 1, 0, 30, 0, 0, time.UTC)}, + {Time: time.Date(2023, 1, 1, 23, 0, 0, 0, time.UTC)}, + }, + currentHour: -1, + wantStart: 0, // Can't go below 0 + wantEnd: 23, // Can't go above 23 + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + start, end := calcCalendarBounds(tc.items, tc.currentHour) + if start != tc.wantStart { + t.Errorf("Expected start %d, got %d", tc.wantStart, start) + } + if end != tc.wantEnd { + t.Errorf("Expected end %d, got %d", tc.wantEnd, end) + } + }) + } +} + +func timePtr(t time.Time) *time.Time { + return &t +} |
