add Block + Component, add TextComponent with min, max and regex validators and early NumberComponent
This commit is contained in:
35
internal/block/validation/required_test.go
Normal file
35
internal/block/validation/required_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRequired(t *testing.T) {
|
||||
cfg := &ComponentConfig{}
|
||||
Required()(cfg)
|
||||
|
||||
if len(cfg.Validators) != 1 {
|
||||
t.Fatalf("expect 1 validator, got %d", len(cfg.Validators))
|
||||
}
|
||||
|
||||
validate := cfg.Validators[0]
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value any
|
||||
wantErr bool
|
||||
}{
|
||||
{"nil value", nil, true},
|
||||
{"empty string", "", true},
|
||||
{"non-empty string", "hello", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := validate(tt.value)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("validate(%v) error = %v, wantErr %v", tt.value, err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user