feat(timeline): fix chronology, status resolution, and component history UI

This commit is contained in:
2026-02-16 23:17:22 +03:00
parent b799228960
commit 88503d2457
17 changed files with 882 additions and 506 deletions

View File

@@ -87,18 +87,79 @@ func TestParseComponentStatusEventTime(t *testing.T) {
}
}
func TestTimelineFallbackTime(t *testing.T) {
func TestParseComponentStatusEventTimeFallsBackToStatusCheckedAt(t *testing.T) {
checkedAt := "2026-01-22T09:45:36Z"
component := HardwareComponent{
Status: statusCritical,
StatusCheckedAt: &checkedAt,
}
actual := parseComponentStatusEventTime(component)
if actual == nil {
t.Fatalf("parseComponentStatusEventTime() = nil, want non-nil")
}
want, _ := time.Parse(time.RFC3339, checkedAt)
if !actual.Equal(want.UTC()) {
t.Fatalf("parseComponentStatusEventTime() = %s, want %s", actual.UTC().Format(time.RFC3339), want.UTC().Format(time.RFC3339))
}
}
func TestCollectedFallbackTime(t *testing.T) {
collected, _ := time.Parse(time.RFC3339, "2026-02-10T15:30:00Z")
ingested, _ := time.Parse(time.RFC3339, "2026-02-10T15:40:00Z")
if got := collectedFallbackTime(collected, ingested); !got.Equal(collected.UTC()) {
t.Fatalf("collectedFallbackTime(collected, ingested) = %s, want %s", got.Format(time.RFC3339), collected.UTC().Format(time.RFC3339))
}
if got := collectedFallbackTime(time.Time{}, ingested); !got.Equal(ingested.UTC()) {
t.Fatalf("collectedFallbackTime(zero, ingested) = %s, want %s", got.Format(time.RFC3339), ingested.UTC().Format(time.RFC3339))
}
}
func TestEventFallbackTime(t *testing.T) {
actual, _ := time.Parse(time.RFC3339, "2026-02-10T15:22:00Z")
collected, _ := time.Parse(time.RFC3339, "2026-02-10T15:30:00Z")
ingested, _ := time.Parse(time.RFC3339, "2026-02-10T15:40:00Z")
if got := timelineFallbackTime(&actual, collected, ingested); !got.Equal(actual.UTC()) {
t.Fatalf("timelineFallbackTime(actual, collected, ingested) = %s, want %s", got.Format(time.RFC3339), actual.UTC().Format(time.RFC3339))
if got := eventFallbackTime(&actual, ingested, collected); !got.Equal(actual.UTC()) {
t.Fatalf("eventFallbackTime(actual, ingested, collected) = %s, want %s", got.Format(time.RFC3339), actual.UTC().Format(time.RFC3339))
}
if got := timelineFallbackTime(nil, collected, ingested); !got.Equal(collected.UTC()) {
t.Fatalf("timelineFallbackTime(nil, collected, ingested) = %s, want %s", got.Format(time.RFC3339), collected.UTC().Format(time.RFC3339))
if got := eventFallbackTime(nil, ingested, collected); !got.Equal(ingested.UTC()) {
t.Fatalf("eventFallbackTime(nil, ingested, collected) = %s, want %s", got.Format(time.RFC3339), ingested.UTC().Format(time.RFC3339))
}
if got := timelineFallbackTime(nil, time.Time{}, ingested); !got.Equal(ingested.UTC()) {
t.Fatalf("timelineFallbackTime(nil, zero, ingested) = %s, want %s", got.Format(time.RFC3339), ingested.UTC().Format(time.RFC3339))
if got := eventFallbackTime(nil, time.Time{}, collected); !got.Equal(collected.UTC()) {
t.Fatalf("eventFallbackTime(nil, zero, collected) = %s, want %s", got.Format(time.RFC3339), collected.UTC().Format(time.RFC3339))
}
}
func TestParseComponentFirstSeenTime(t *testing.T) {
changedAt := "2026-02-10T15:22:00Z"
checkedAt := "2026-02-10T15:21:00Z"
component := HardwareComponent{
StatusChangedAt: &changedAt,
StatusCheckedAt: &checkedAt,
StatusHistory: []HardwareStatusHistoryEntry{
{Status: "OK", ChangedAt: "2026-02-10T15:10:00Z"},
{Status: "CRITICAL", ChangedAt: "2026-02-10T15:18:00Z"},
},
}
collected, _ := time.Parse(time.RFC3339, "2026-02-10T15:30:00Z")
ingested, _ := time.Parse(time.RFC3339, "2026-02-10T15:40:00Z")
got := parseComponentFirstSeenTime(component, collected, ingested)
want, _ := time.Parse(time.RFC3339, "2026-02-10T15:10:00Z")
if !got.Equal(want.UTC()) {
t.Fatalf("parseComponentFirstSeenTime() = %s, want %s", got.UTC().Format(time.RFC3339), want.UTC().Format(time.RFC3339))
}
}
func TestParseComponentFirstSeenTimeFallback(t *testing.T) {
component := HardwareComponent{}
collected, _ := time.Parse(time.RFC3339, "2026-02-10T15:30:00Z")
ingested, _ := time.Parse(time.RFC3339, "2026-02-10T15:40:00Z")
got := parseComponentFirstSeenTime(component, collected, ingested)
if !got.Equal(ingested.UTC()) {
t.Fatalf("parseComponentFirstSeenTime() = %s, want %s", got.UTC().Format(time.RFC3339), ingested.UTC().Format(time.RFC3339))
}
}