xonecas.io
60255
Zn

Zoea-Nova / files

Zoea-Nova / internal / tui / timestamp_test.go

3.0 KB
1package tui
2
3import (
4	"testing"
5	"time"
6)
7
8func TestFormatTickTimestamp(t *testing.T) {
9	tests := []struct {
10		name     string
11		tick     int64
12		ts       time.Time
13		expected string
14	}{
15		{
16			name:     "normal_tick_morning",
17			tick:     1234,
18			ts:       time.Date(2026, 2, 5, 9, 41, 23, 0, time.UTC),
19			expected: "T1234 ⬡ [09:41]",
20		},
21		{
22			name:     "normal_tick_afternoon",
23			tick:     5678,
24			ts:       time.Date(2026, 2, 5, 14, 30, 0, 0, time.UTC),
25			expected: "T5678 ⬡ [14:30]",
26		},
27		{
28			name:     "tick_zero",
29			tick:     0,
30			ts:       time.Date(2026, 2, 5, 0, 0, 0, 0, time.UTC),
31			expected: "T0 ⬡ [00:00]",
32		},
33		{
34			name:     "large_tick",
35			tick:     999999,
36			ts:       time.Date(2026, 2, 5, 23, 59, 0, 0, time.UTC),
37			expected: "T999999 ⬡ [23:59]",
38		},
39		{
40			name:     "very_large_tick",
41			tick:     12345678,
42			ts:       time.Date(2026, 2, 5, 12, 0, 0, 0, time.UTC),
43			expected: "T12345678 ⬡ [12:00]",
44		},
45		{
46			name:     "midnight",
47			tick:     100,
48			ts:       time.Date(2026, 2, 5, 0, 0, 0, 0, time.UTC),
49			expected: "T100 ⬡ [00:00]",
50		},
51		{
52			name:     "noon",
53			tick:     200,
54			ts:       time.Date(2026, 2, 5, 12, 0, 0, 0, time.UTC),
55			expected: "T200 ⬡ [12:00]",
56		},
57	}
58
59	for _, tt := range tests {
60		t.Run(tt.name, func(t *testing.T) {
61			result := formatTickTimestamp(tt.tick, tt.ts)
62			if result != tt.expected {
63				t.Errorf("formatTickTimestamp(%d, %v) = %q, expected %q",
64					tt.tick, tt.ts, result, tt.expected)
65			}
66		})
67	}
68}
69
70func TestFormatTickTimestamp_ZeroTime(t *testing.T) {
71	// Edge case: zero time should still format reasonably
72	tick := int64(42)
73	ts := time.Time{}
74	result := formatTickTimestamp(tick, ts)
75	// Zero time in Go is "0001-01-01 00:00:00 +0000 UTC"
76	// When converted to local, it will be whatever the local offset is
77	// Just verify format is correct (T## ⬡ [HH:MM])
78	localTime := ts.Local()
79	expected := "T42 ⬡ [" + localTime.Format("15:04") + "]"
80	if result != expected {
81		t.Errorf("formatTickTimestamp(%d, zero time) = %q, expected %q",
82			tick, result, expected)
83	}
84}
85
86func TestFormatTickTimestamp_NegativeTick(t *testing.T) {
87	// Edge case: negative tick (shouldn't happen in practice but handle gracefully)
88	tick := int64(-1)
89	ts := time.Date(2026, 2, 5, 10, 30, 0, 0, time.UTC)
90	result := formatTickTimestamp(tick, ts)
91	expected := "T-1 ⬡ [10:30]"
92	if result != expected {
93		t.Errorf("formatTickTimestamp(%d, %v) = %q, expected %q",
94			tick, ts, result, expected)
95	}
96}
97
98func TestFormatTickTimestamp_LocalTime(t *testing.T) {
99	// The formatter should convert to local time
100	tick := int64(500)
101	// Create a UTC time
102	utcTime := time.Date(2026, 2, 5, 14, 30, 0, 0, time.UTC)
103
104	// Format should convert to local
105	result := formatTickTimestamp(tick, utcTime)
106
107	// Convert to local for expected value
108	localTime := utcTime.Local()
109	expectedTime := localTime.Format("15:04")
110	expected := "T500 ⬡ [" + expectedTime + "]"
111
112	if result != expected {
113		t.Errorf("formatTickTimestamp(%d, %v) = %q, expected %q",
114			tick, utcTime, result, expected)
115	}
116}