summaryrefslogtreecommitdiff
path: root/internal/ui/table_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/ui/table_test.go')
-rw-r--r--internal/ui/table_test.go32
1 files changed, 10 insertions, 22 deletions
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go
index 412a271..1120d27 100644
--- a/internal/ui/table_test.go
+++ b/internal/ui/table_test.go
@@ -75,19 +75,7 @@ func TestAnnotateHotkey(t *testing.T) {
}
func TestFormatDueUsesCalendarDayLabels(t *testing.T) {
- now := time.Now()
- dueOn := func(dayOffset int, hour, minute int) string {
- day := now.AddDate(0, 0, dayOffset)
- due := time.Date(day.Year(), day.Month(), day.Day(), hour, minute, 0, 0, time.UTC)
- return due.Format(task.DateFormat)
- }
- skipIfDateChanged := func() {
- t.Helper()
- later := time.Now()
- if later.Year() != now.Year() || later.YearDay() != now.YearDay() {
- t.Skip("local date changed during due-date boundary test")
- }
- }
+ loc, now := useSofiaLocalTime(t)
m := Model{theme: DefaultTheme()}
tests := []struct {
@@ -97,24 +85,24 @@ func TestFormatDueUsesCalendarDayLabels(t *testing.T) {
overdue bool
}{
{
- name: "late yesterday",
- due: dueOn(-1, 23, 59),
+ name: "taskwarrior date-only yesterday",
+ due: taskwarriorDateOnlyDue(now, loc, -1),
want: "yesterday",
overdue: true,
},
{
- name: "early today",
- due: dueOn(0, 0, 1),
+ name: "taskwarrior date-only today",
+ due: taskwarriorDateOnlyDue(now, loc, 0),
want: "today",
},
{
- name: "late tomorrow",
- due: dueOn(1, 23, 59),
+ name: "taskwarrior date-only tomorrow",
+ due: taskwarriorDateOnlyDue(now, loc, 1),
want: "tomorrow",
},
{
- name: "future day count",
- due: dueOn(3, 23, 59),
+ name: "taskwarrior date-only future day count",
+ due: taskwarriorDateOnlyDue(now, loc, 3),
want: "3d",
},
}
@@ -123,7 +111,7 @@ func TestFormatDueUsesCalendarDayLabels(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
rendered := m.formatDue(tt.due, 12)
got := strings.TrimSpace(ansi.Strip(rendered))
- skipIfDateChanged()
+ skipIfLocalDateChanged(t, loc, now)
if got != tt.want {
t.Fatalf("formatDue() = %q, want %q", got, tt.want)
}