opencode/packages/tui/internal/theme/theme_test.go

90 lines
1.7 KiB
Go
Raw Normal View History

2025-04-28 21:46:09 +08:00
package theme
import (
"testing"
)
func TestThemeRegistration(t *testing.T) {
// Get list of available themes
availableThemes := AvailableThemes()
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
// Check if "catppuccin" theme is registered
catppuccinFound := false
for _, themeName := range availableThemes {
if themeName == "catppuccin" {
catppuccinFound = true
break
}
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
if !catppuccinFound {
t.Errorf("Catppuccin theme is not registered")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
// Check if "gruvbox" theme is registered
gruvboxFound := false
for _, themeName := range availableThemes {
if themeName == "gruvbox" {
gruvboxFound = true
break
}
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
if !gruvboxFound {
t.Errorf("Gruvbox theme is not registered")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
// Check if "monokai" theme is registered
monokaiFound := false
for _, themeName := range availableThemes {
if themeName == "monokai" {
monokaiFound = true
break
}
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
if !monokaiFound {
t.Errorf("Monokai theme is not registered")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
// Try to get the themes and make sure they're not nil
catppuccin := GetTheme("catppuccin")
if catppuccin == nil {
t.Errorf("Catppuccin theme is nil")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
gruvbox := GetTheme("gruvbox")
if gruvbox == nil {
t.Errorf("Gruvbox theme is nil")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
monokai := GetTheme("monokai")
if monokai == nil {
t.Errorf("Monokai theme is nil")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
// Test switching theme
originalTheme := CurrentThemeName()
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
err := SetTheme("gruvbox")
if err != nil {
t.Errorf("Failed to set theme to gruvbox: %v", err)
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
if CurrentThemeName() != "gruvbox" {
t.Errorf("Theme not properly switched to gruvbox")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
err = SetTheme("monokai")
if err != nil {
t.Errorf("Failed to set theme to monokai: %v", err)
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
if CurrentThemeName() != "monokai" {
t.Errorf("Theme not properly switched to monokai")
}
2025-05-12 23:45:03 +08:00
2025-04-28 21:46:09 +08:00
// Switch back to original theme
_ = SetTheme(originalTheme)
2025-05-12 23:45:03 +08:00
}