-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_test.go
More file actions
84 lines (77 loc) · 2.35 KB
/
Copy pathcontext_test.go
File metadata and controls
84 lines (77 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package widgets
import (
"strings"
"testing"
"github.com/yuys13/agystatusline/types"
)
func TestContextBarWidget(t *testing.T) {
RegisterAll()
w := GetWidget("context-bar")
if w == nil {
t.Fatalf("Context bar widget not found")
}
settings := types.DefaultSettings()
pct50 := 50.0
pct65 := 65.0
pct95 := 95.0
tests := []struct {
name string
ctx types.RenderContext
expectedTitle string
bodyContainsText string
expectedBody string
expectedColor string
}{
{
name: "Nil context window",
ctx: types.RenderContext{Data: types.StatusJSON{}},
expectedTitle: "ctx",
expectedBody: "",
expectedColor: "brightWhite",
},
{
name: "50% usage",
ctx: types.RenderContext{Data: types.StatusJSON{ContextWindow: &types.ContextWindowInfo{UsedPercentage: &pct50}}},
expectedTitle: "ctx",
bodyContainsText: "50.0%",
expectedColor: "brightWhite",
},
{
name: "65% usage (yellow warning)",
ctx: types.RenderContext{Data: types.StatusJSON{ContextWindow: &types.ContextWindowInfo{UsedPercentage: &pct65}}},
expectedTitle: "ctx",
bodyContainsText: "65.0%",
expectedColor: "brightYellow",
},
{
name: "95% usage (red critical)",
ctx: types.RenderContext{Data: types.StatusJSON{ContextWindow: &types.ContextWindowInfo{UsedPercentage: &pct95}}},
expectedTitle: "ctx",
bodyContainsText: "95.0%",
expectedColor: "brightRed",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
item := types.WidgetItem{Type: "context-bar"}
title, body, err := w.Render(item, tt.ctx, settings)
if err != nil {
t.Fatalf("Render error: %v", err)
}
if tt.expectedTitle != "" && title != tt.expectedTitle {
t.Errorf("Expected title %q, got %q", tt.expectedTitle, title)
}
if tt.bodyContainsText != "" && !strings.Contains(body, tt.bodyContainsText) {
t.Errorf("Expected body to contain %q, got %q", tt.bodyContainsText, body)
}
if tt.expectedBody != "" && body != tt.expectedBody {
t.Errorf("Expected body %q, got %q", tt.expectedBody, body)
}
if tt.expectedColor != "" {
if color := w.GetBodyColor(item, tt.ctx); color != tt.expectedColor {
t.Errorf("Expected color %q, got %q", tt.expectedColor, color)
}
}
})
}
}