Skip to content

Commit 5d626f2

Browse files
committed
test(ui): Improve validation tests for UI config
1 parent 75c1b29 commit 5d626f2

File tree

1 file changed

+104
-33
lines changed

1 file changed

+104
-33
lines changed

config/ui/ui_test.go

Lines changed: 104 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,110 @@ import (
77
)
88

99
func TestConfig_ValidateAndSetDefaults(t *testing.T) {
10-
cfg := &Config{
11-
Title: "",
12-
Description: "",
13-
DashboardHeading: "",
14-
DashboardSubheading: "",
15-
Header: "",
16-
Logo: "",
17-
Link: "",
18-
}
19-
if err := cfg.ValidateAndSetDefaults(); err != nil {
20-
t.Error("expected no error, got", err.Error())
21-
}
22-
if cfg.Title != defaultTitle {
23-
t.Errorf("expected title to be %s, got %s", defaultTitle, cfg.Title)
24-
}
25-
if cfg.Description != defaultDescription {
26-
t.Errorf("expected description to be %s, got %s", defaultDescription, cfg.Description)
27-
}
28-
if cfg.DashboardHeading != defaultDashboardHeading {
29-
t.Errorf("expected DashboardHeading to be %s, got %s", defaultDashboardHeading, cfg.DashboardHeading)
30-
}
31-
if cfg.DashboardSubheading != defaultDashboardSubheading {
32-
t.Errorf("expected DashboardSubheading to be %s, got %s", defaultDashboardSubheading, cfg.DashboardSubheading)
33-
}
34-
if cfg.Header != defaultHeader {
35-
t.Errorf("expected header to be %s, got %s", defaultHeader, cfg.Header)
36-
}
37-
if cfg.DefaultSortBy != defaultSortBy {
38-
t.Errorf("expected defaultSortBy to be %s, got %s", defaultSortBy, cfg.DefaultSortBy)
39-
}
40-
if cfg.DefaultFilterBy != defaultFilterBy {
41-
t.Errorf("expected defaultFilterBy to be %s, got %s", defaultFilterBy, cfg.DefaultFilterBy)
42-
}
10+
t.Run("empty-config", func(t *testing.T) {
11+
cfg := &Config{
12+
Title: "",
13+
Description: "",
14+
DashboardHeading: "",
15+
DashboardSubheading: "",
16+
Header: "",
17+
Logo: "",
18+
Link: "",
19+
}
20+
if err := cfg.ValidateAndSetDefaults(); err != nil {
21+
t.Error("expected no error, got", err.Error())
22+
}
23+
if cfg.Title != defaultTitle {
24+
t.Errorf("expected title to be %s, got %s", defaultTitle, cfg.Title)
25+
}
26+
if cfg.Description != defaultDescription {
27+
t.Errorf("expected description to be %s, got %s", defaultDescription, cfg.Description)
28+
}
29+
if cfg.DashboardHeading != defaultDashboardHeading {
30+
t.Errorf("expected DashboardHeading to be %s, got %s", defaultDashboardHeading, cfg.DashboardHeading)
31+
}
32+
if cfg.DashboardSubheading != defaultDashboardSubheading {
33+
t.Errorf("expected DashboardSubheading to be %s, got %s", defaultDashboardSubheading, cfg.DashboardSubheading)
34+
}
35+
if cfg.Header != defaultHeader {
36+
t.Errorf("expected header to be %s, got %s", defaultHeader, cfg.Header)
37+
}
38+
if cfg.DefaultSortBy != defaultSortBy {
39+
t.Errorf("expected defaultSortBy to be %s, got %s", defaultSortBy, cfg.DefaultSortBy)
40+
}
41+
if cfg.DefaultFilterBy != defaultFilterBy {
42+
t.Errorf("expected defaultFilterBy to be %s, got %s", defaultFilterBy, cfg.DefaultFilterBy)
43+
}
44+
})
45+
t.Run("custom-values", func(t *testing.T) {
46+
cfg := &Config{
47+
Title: "Custom Title",
48+
Description: "Custom Description",
49+
DashboardHeading: "Production Status",
50+
DashboardSubheading: "Monitor all production endpoints",
51+
Header: "My Company",
52+
Logo: "https://example.com/logo.png",
53+
Link: "https://example.com",
54+
DefaultSortBy: "health",
55+
DefaultFilterBy: "failing",
56+
}
57+
if err := cfg.ValidateAndSetDefaults(); err != nil {
58+
t.Error("expected no error, got", err.Error())
59+
}
60+
if cfg.Title != "Custom Title" {
61+
t.Errorf("expected title to be preserved, got %s", cfg.Title)
62+
}
63+
if cfg.Description != "Custom Description" {
64+
t.Errorf("expected description to be preserved, got %s", cfg.Description)
65+
}
66+
if cfg.DashboardHeading != "Production Status" {
67+
t.Errorf("expected DashboardHeading to be preserved, got %s", cfg.DashboardHeading)
68+
}
69+
if cfg.DashboardSubheading != "Monitor all production endpoints" {
70+
t.Errorf("expected DashboardSubheading to be preserved, got %s", cfg.DashboardSubheading)
71+
}
72+
if cfg.Header != "My Company" {
73+
t.Errorf("expected header to be preserved, got %s", cfg.Header)
74+
}
75+
if cfg.Logo != "https://example.com/logo.png" {
76+
t.Errorf("expected logo to be preserved, got %s", cfg.Logo)
77+
}
78+
if cfg.Link != "https://example.com" {
79+
t.Errorf("expected link to be preserved, got %s", cfg.Link)
80+
}
81+
if cfg.DefaultSortBy != "health" {
82+
t.Errorf("expected defaultSortBy to be preserved, got %s", cfg.DefaultSortBy)
83+
}
84+
if cfg.DefaultFilterBy != "failing" {
85+
t.Errorf("expected defaultFilterBy to be preserved, got %s", cfg.DefaultFilterBy)
86+
}
87+
})
88+
t.Run("partial-custom-values", func(t *testing.T) {
89+
cfg := &Config{
90+
Title: "Custom Title",
91+
DashboardHeading: "My Dashboard",
92+
Header: "",
93+
DashboardSubheading: "",
94+
}
95+
if err := cfg.ValidateAndSetDefaults(); err != nil {
96+
t.Error("expected no error, got", err.Error())
97+
}
98+
if cfg.Title != "Custom Title" {
99+
t.Errorf("expected custom title to be preserved, got %s", cfg.Title)
100+
}
101+
if cfg.DashboardHeading != "My Dashboard" {
102+
t.Errorf("expected custom DashboardHeading to be preserved, got %s", cfg.DashboardHeading)
103+
}
104+
if cfg.DashboardSubheading != defaultDashboardSubheading {
105+
t.Errorf("expected DashboardSubheading to use default, got %s", cfg.DashboardSubheading)
106+
}
107+
if cfg.Header != defaultHeader {
108+
t.Errorf("expected header to use default, got %s", cfg.Header)
109+
}
110+
if cfg.Description != defaultDescription {
111+
t.Errorf("expected description to use default, got %s", cfg.Description)
112+
}
113+
})
43114
}
44115

45116
func TestButton_Validate(t *testing.T) {

0 commit comments

Comments
 (0)