verstak/internal/core/templates/registry_test.go

75 lines
1.5 KiB
Go

package templates
import (
"testing"
)
func TestNewRegistry(t *testing.T) {
r := NewRegistry()
if r == nil {
t.Fatal("expected non-nil registry")
}
}
func TestLoadSystem(t *testing.T) {
r := NewRegistry()
if err := r.LoadSystem(); err != nil {
t.Fatalf("LoadSystem: %v", err)
}
// Check we have system templates
templates := r.All()
if len(templates) == 0 {
t.Fatal("expected at least one system template")
}
}
func TestEnabled(t *testing.T) {
r := NewRegistry()
if err := r.LoadSystem(); err != nil {
t.Fatalf("LoadSystem: %v", err)
}
enabled := r.Enabled()
if len(enabled) == 0 {
t.Fatal("expected at least one enabled template")
}
}
func TestGet(t *testing.T) {
r := NewRegistry()
if err := r.LoadSystem(); err != nil {
t.Fatalf("LoadSystem: %v", err)
}
tmpl, ok := r.Get("folder.default")
if !ok {
t.Fatal("expected to find folder.default template")
}
if tmpl.Type != "folder" {
t.Errorf("expected type 'folder', got %q", tmpl.Type)
}
if !tmpl.Enabled {
t.Error("expected folder.default to be enabled")
}
}
func TestEnabledForParent(t *testing.T) {
r := NewRegistry()
if err := r.LoadSystem(); err != nil {
t.Fatalf("LoadSystem: %v", err)
}
// folder template should be allowed in "root"
forParent := r.EnabledForParent("root")
if len(forParent) == 0 {
t.Fatal("expected templates for parent type 'root'")
}
// All templates should be allowed for root
all := r.Enabled()
if len(forParent) != len(all) {
t.Errorf("expected %d templates for root, got %d", len(all), len(forParent))
}
}