-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuilder_test.go
More file actions
218 lines (189 loc) · 5.55 KB
/
builder_test.go
File metadata and controls
218 lines (189 loc) · 5.55 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package goaster
import (
"testing"
)
func TestToasterBuilder_Defaults(t *testing.T) {
toaster := NewToasterBuilder().Build()
if toaster == nil {
t.Fatal("expected toaster instance, got nil")
}
t.Run("default position", func(t *testing.T) {
if toaster.Position != BottomRight {
t.Errorf("expected default position to be BottomRight, got %v", toaster.Position)
}
})
t.Run("default icons", func(t *testing.T) {
if len(toaster.Icons) == 0 {
t.Errorf("expected default icons to be set")
}
})
t.Run("queue initialized", func(t *testing.T) {
if toaster.Queue() == nil {
t.Errorf("expected queue to be initialized")
}
})
}
func TestToasterBuilder_CustomConfig(t *testing.T) {
toaster := NewToasterBuilder().
WithPosition(TopLeft).
WithBorder(false).
WithAutoDismiss(false).
Build()
if toaster.Position != TopLeft {
t.Errorf("expected position TopLeft, got %v", toaster.Position)
}
if toaster.Border != false {
t.Errorf("expected Border=false, got %v", toaster.Border)
}
if toaster.AutoDismiss != false {
t.Errorf("expected AutoDismiss=false, got %v", toaster.AutoDismiss)
}
}
func TestToasterBuilder_WithAllOptions(t *testing.T) {
toaster := NewToasterBuilder().
WithVariant(AccentLight).
WithBorder(false).
WithRounded(true).
WithShowIcon(false).
WithButton(false).
WithAutoDismiss(false).
WithAnimation(false).
WithProgressBar(false).
WithPosition(TopCenter).
WithIcon(ErrorLevel, "<svg>Error</svg>").
Build()
if toaster.Variant != AccentLight {
t.Errorf("expected Variant to be AccentLight, got %v", toaster.Variant)
}
if toaster.Border {
t.Errorf("expected Border=false")
}
if !toaster.Rounded {
t.Errorf("expected Rounded=true")
}
if toaster.ShowIcon {
t.Errorf("expected ShowIcon=false")
}
if toaster.Button {
t.Errorf("expected Button=false")
}
if toaster.AutoDismiss {
t.Errorf("expected AutoDismiss=false")
}
if toaster.Animation {
t.Errorf("expected Animation=false")
}
if toaster.ProgressBar {
t.Errorf("expected ProgressBar=false")
}
if toaster.Position != TopCenter {
t.Errorf("expected Position=TopCenter, got %v", toaster.Position)
}
if icon, ok := toaster.Icons[ErrorLevel]; !ok || icon != "<svg>Error</svg>" {
t.Errorf("expected custom ErrorLevel icon to be set, got %q", icon)
}
}
func TestToasterBuilder_WithOptionsMerge(t *testing.T) {
builder := NewToasterBuilder().
WithBorder(false)
// Apply additional options
toaster := builder.WithOptions(
WithAutoDismiss(false),
WithAnimation(false),
).Build()
if toaster.Border != false {
t.Errorf("expected Border=false after builder chain")
}
if toaster.AutoDismiss != false {
t.Errorf("expected AutoDismiss=false via WithOptions")
}
if toaster.Animation != false {
t.Errorf("expected Animation=false via WithOptions")
}
}
func TestToasterBuilder_WithIconNilMap(t *testing.T) {
// Start fresh with a builder whose Icons map will be replaced
builder := NewToasterBuilder()
// Set new icon — this should work correctly with the map
toaster := builder.WithIcon(WarningLevel, "<svg>Warning</svg>").Build()
icon, ok := toaster.Icons[WarningLevel]
if !ok || icon != "<svg>Warning</svg>" {
t.Errorf("expected WarningLevel icon to be set correctly, got %q", icon)
}
}
func TestToasterBuilder_Build_FallbackToDefaultPosition(t *testing.T) {
// Simulate missing Position by setting it on the builder
builder := NewToasterBuilder().WithPosition("")
toaster := builder.Build()
if toaster.Position != BottomRight {
t.Errorf("expected fallback Position to be BottomRight, got %v", toaster.Position)
}
}
func TestToasterBuilder_Build_FallbackToDefaultIcons(t *testing.T) {
builder := NewToasterBuilder()
toaster := builder.Build()
if len(toaster.Icons) == 0 {
t.Errorf("expected fallback Icons to be set")
}
}
func TestToasterBuilder_Build_FallbackToNewQueue_Clean(t *testing.T) {
builder := NewToasterBuilder()
toaster := builder.Build()
// Attempt to dequeue from an empty queue
_, err := toaster.Queue().Dequeue()
if err == nil {
t.Errorf("expected error when dequeuing from an empty queue, got nil")
}
// Make sure the queue is initialized
if toaster.Queue() == nil {
t.Errorf("expected Queue to be initialized")
}
}
func TestToasterBuilder_Build_SetsDefaultPositionIfEmpty(t *testing.T) {
builder := NewToasterBuilder().WithPosition("")
toaster := builder.Build()
if toaster.Position != BottomRight {
t.Errorf("expected Position to default to BottomRight, got %v", toaster.Position)
}
}
func TestToasterBuilder_Build_SetsDefaultIconsIfNil(t *testing.T) {
builder := NewToasterBuilder()
toaster := builder.Build()
if len(toaster.Icons) == 0 {
t.Errorf("expected Icons to be initialized with defaults")
}
}
func TestToasterBuilder_WithVariant(t *testing.T) {
tests := []struct {
name string
variant Variant
}{
{"Filled", Filled},
{"Outlined", Outlined},
{"Soft", Soft},
{"Minimal", Minimal},
{"Brutalist", Brutalist},
{"Retro", Retro},
{"Neon", Neon},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
toaster := NewToasterBuilder().WithVariant(tt.variant).Build()
if toaster.Variant != tt.variant {
t.Errorf("expected Variant to be %q, got %q", tt.variant, toaster.Variant)
}
})
}
}
func TestToasterBuilder_Build_InitializesQueueIfNil(t *testing.T) {
builder := NewToasterBuilder()
toaster := builder.Build()
if toaster.Queue() == nil {
t.Errorf("expected Queue to be initialized, got nil")
}
// Ensure it functions properly
_, err := toaster.Queue().Dequeue()
if err == nil {
t.Errorf("expected error when dequeuing from empty queue, got nil")
}
}