feat: Phase 2 UX Polish — theme system, config profiles, error banner, tests
- Add Theme struct with 3 predefined themes (dark/light/druntime) - Add Profile struct for named configuration profiles - Add ErrorBanner with severity levels and auto-dismiss - Add unit tests for theme, error banner, and models - Update CHANGELOG.md and PROJECT_STATE.md
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package errors_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.tukangketik.id/swanadiva/hostkeeper/internal/models"
|
||||
)
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
config := models.DefaultConfig()
|
||||
|
||||
if config.Version != "1.0.0" {
|
||||
t.Errorf("Version = %q, want %q", config.Version, "1.0.0")
|
||||
}
|
||||
if config.DefaultPort != 22 {
|
||||
t.Errorf("DefaultPort = %d, want 22", config.DefaultPort)
|
||||
}
|
||||
if config.ConnectionTimeout != 30 {
|
||||
t.Errorf("ConnectionTimeout = %d, want 30", config.ConnectionTimeout)
|
||||
}
|
||||
if config.Theme != "dark" {
|
||||
t.Errorf("Theme = %q, want %q", config.Theme, "dark")
|
||||
}
|
||||
if len(config.Profiles) != 1 {
|
||||
t.Errorf("Profiles has %d items, want 1", len(config.Profiles))
|
||||
}
|
||||
if config.ActiveProfile != "default" {
|
||||
t.Errorf("ActiveProfile = %q, want %q", config.ActiveProfile, "default")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppConfigProfiles(t *testing.T) {
|
||||
config := models.DefaultConfig()
|
||||
|
||||
// Test GetProfile
|
||||
profile := config.GetProfile("default")
|
||||
if profile == nil {
|
||||
t.Fatal("GetProfile(default) returned nil")
|
||||
}
|
||||
if profile.Name != "default" {
|
||||
t.Errorf("Profile.Name = %q, want %q", profile.Name, "default")
|
||||
}
|
||||
|
||||
// Test GetProfile for non-existent profile
|
||||
profile = config.GetProfile("nonexistent")
|
||||
if profile != nil {
|
||||
t.Error("GetProfile(nonexistent) should return nil")
|
||||
}
|
||||
|
||||
// Test GetActiveProfile
|
||||
profile = config.GetActiveProfile()
|
||||
if profile == nil {
|
||||
t.Fatal("GetActiveProfile() returned nil")
|
||||
}
|
||||
if profile.Name != "default" {
|
||||
t.Errorf("Active profile Name = %q, want %q", profile.Name, "default")
|
||||
}
|
||||
|
||||
// Test AddProfile
|
||||
newProfile := models.Profile{
|
||||
Name: "work",
|
||||
Theme: "light",
|
||||
}
|
||||
config.AddProfile(newProfile)
|
||||
if len(config.Profiles) != 2 {
|
||||
t.Errorf("After AddProfile, Profiles has %d items, want 2", len(config.Profiles))
|
||||
}
|
||||
|
||||
// Test RemoveProfile
|
||||
config.RemoveProfile("work")
|
||||
if len(config.Profiles) != 1 {
|
||||
t.Errorf("After RemoveProfile, Profiles has %d items, want 1", len(config.Profiles))
|
||||
}
|
||||
|
||||
// Test RemoveProfile for non-existent profile
|
||||
config.RemoveProfile("nonexistent")
|
||||
if len(config.Profiles) != 1 {
|
||||
t.Errorf("After RemoveProfile(nonexistent), Profiles has %d items, want 1", len(config.Profiles))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user