1package core_test
  2
  3import (
  4	"fmt"
  5	"image/color"
  6	"testing"
  7
  8	"github.com/charmbracelet/crush/internal/tui/components/core"
  9	"github.com/charmbracelet/x/exp/golden"
 10)
 11
 12func TestStatus(t *testing.T) {
 13	t.Parallel()
 14
 15	tests := []struct {
 16		name  string
 17		opts  core.StatusOpts
 18		width int
 19	}{
 20		{
 21			name: "Default",
 22			opts: core.StatusOpts{
 23				Title:       "Status",
 24				Description: "Everything is working fine",
 25			},
 26			width: 80,
 27		},
 28		{
 29			name: "WithCustomIcon",
 30			opts: core.StatusOpts{
 31				Icon:        "✓",
 32				Title:       "Success",
 33				Description: "Operation completed successfully",
 34			},
 35			width: 80,
 36		},
 37		{
 38			name: "NoIcon",
 39			opts: core.StatusOpts{
 40				Title:       "Info",
 41				Description: "This status has no icon",
 42			},
 43			width: 80,
 44		},
 45		{
 46			name: "WithColors",
 47			opts: core.StatusOpts{
 48				Icon:             "⚠",
 49				Title:            "Warning",
 50				TitleColor:       color.RGBA{255, 255, 0, 255}, // Yellow
 51				Description:      "This is a warning message",
 52				DescriptionColor: color.RGBA{255, 0, 0, 255}, // Red
 53			},
 54			width: 80,
 55		},
 56		{
 57			name: "WithExtraContent",
 58			opts: core.StatusOpts{
 59				Title:        "Build",
 60				Description:  "Building project",
 61				ExtraContent: "[2/5]",
 62			},
 63			width: 80,
 64		},
 65		{
 66			name: "LongDescription",
 67			opts: core.StatusOpts{
 68				Title:       "Processing",
 69				Description: "This is a very long description that should be truncated when the width is too small to display it completely without wrapping",
 70			},
 71			width: 60,
 72		},
 73		{
 74			name: "NarrowWidth",
 75			opts: core.StatusOpts{
 76				Icon:        "●",
 77				Title:       "Status",
 78				Description: "Short message",
 79			},
 80			width: 30,
 81		},
 82		{
 83			name: "VeryNarrowWidth",
 84			opts: core.StatusOpts{
 85				Icon:        "●",
 86				Title:       "Test",
 87				Description: "This will be truncated",
 88			},
 89			width: 20,
 90		},
 91		{
 92			name: "EmptyDescription",
 93			opts: core.StatusOpts{
 94				Icon:  "●",
 95				Title: "Title Only",
 96			},
 97			width: 80,
 98		},
 99		{
100			name: "AllFieldsWithExtraContent",
101			opts: core.StatusOpts{
102				Icon:             "🚀",
103				Title:            "Deployment",
104				TitleColor:       color.RGBA{0, 0, 255, 255}, // Blue
105				Description:      "Deploying to production environment",
106				DescriptionColor: color.RGBA{128, 128, 128, 255}, // Gray
107				ExtraContent:     "v1.2.3",
108			},
109			width: 80,
110		},
111	}
112
113	for _, tt := range tests {
114		t.Run(tt.name, func(t *testing.T) {
115			t.Parallel()
116
117			output := core.Status(tt.opts, tt.width)
118			golden.RequireEqual(t, []byte(output))
119		})
120	}
121}
122
123func TestStatusTruncation(t *testing.T) {
124	t.Parallel()
125
126	opts := core.StatusOpts{
127		Icon:         "●",
128		Title:        "Very Long Title",
129		Description:  "This is an extremely long description that definitely needs to be truncated",
130		ExtraContent: "[extra]",
131	}
132
133	// Test different widths to ensure truncation works correctly
134	widths := []int{20, 30, 40, 50, 60}
135
136	for _, width := range widths {
137		t.Run(fmt.Sprintf("Width%d", width), func(t *testing.T) {
138			t.Parallel()
139
140			output := core.Status(opts, width)
141			golden.RequireEqual(t, []byte(output))
142		})
143	}
144}