408681c8e4
- 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
96 lines
2.2 KiB
Go
96 lines
2.2 KiB
Go
package tui_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.tukangketik.id/swanadiva/hostkeeper/pkg/tui"
|
|
)
|
|
|
|
func TestErrorBannerShowHide(t *testing.T) {
|
|
banner := tui.NewErrorBanner(tui.SevError)
|
|
|
|
// Initially not visible
|
|
if banner.IsVisible() {
|
|
t.Error("Banner should not be visible initially")
|
|
}
|
|
|
|
// Show the banner
|
|
banner.Show("Test Error", "Something went wrong", "Check logs", "Restart app")
|
|
if !banner.IsVisible() {
|
|
t.Error("Banner should be visible after Show()")
|
|
}
|
|
|
|
// Verify content
|
|
if banner.Title != "Test Error" {
|
|
t.Errorf("Title = %q, want %q", banner.Title, "Test Error")
|
|
}
|
|
if banner.Detail != "Something went wrong" {
|
|
t.Errorf("Detail = %q, want %q", banner.Detail, "Something went wrong")
|
|
}
|
|
if len(banner.Hints) != 2 {
|
|
t.Errorf("Hints has %d items, want 2", len(banner.Hints))
|
|
}
|
|
|
|
// Hide the banner
|
|
banner.Hide()
|
|
if banner.IsVisible() {
|
|
t.Error("Banner should not be visible after Hide()")
|
|
}
|
|
}
|
|
|
|
func TestErrorBannerAutoDismiss(t *testing.T) {
|
|
banner := tui.NewErrorBanner(tui.SevWarning)
|
|
banner.AutoDismiss = true
|
|
banner.DismissAfter = 100 * time.Millisecond
|
|
|
|
banner.Show("Test Warning", "Something")
|
|
if !banner.IsVisible() {
|
|
t.Error("Banner should be visible after Show()")
|
|
}
|
|
|
|
// Wait for auto-dismiss
|
|
time.Sleep(150 * time.Millisecond)
|
|
banner.Update()
|
|
|
|
if banner.IsVisible() {
|
|
t.Error("Banner should be auto-dismissed after delay")
|
|
}
|
|
}
|
|
|
|
func TestErrorBannerSeverity(t *testing.T) {
|
|
tests := []struct {
|
|
severity tui.ErrorSeverity
|
|
name string
|
|
}{
|
|
{tui.SevError, "error"},
|
|
{tui.SevWarning, "warning"},
|
|
{tui.SevInfo, "info"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
banner := tui.NewErrorBanner(tt.severity)
|
|
if banner.Severity != tt.severity {
|
|
t.Errorf("NewErrorBanner(%v).Severity = %v, want %v", tt.name, banner.Severity, tt.severity)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestErrorBannerView(t *testing.T) {
|
|
banner := tui.NewErrorBanner(tui.SevError)
|
|
banner.Show("Error Title", "Error detail", "Hint 1", "Hint 2")
|
|
|
|
// Test that View returns non-empty string
|
|
output := banner.View(80)
|
|
if output == "" {
|
|
t.Error("View() returned empty string")
|
|
}
|
|
|
|
// Test that View returns empty string when not visible
|
|
banner.Hide()
|
|
output = banner.View(80)
|
|
if output != "" {
|
|
t.Error("View() should return empty string when not visible")
|
|
}
|
|
}
|