diff --git a/internal/tui/components/core/status_test.go b/internal/tui/components/core/status_test.go new file mode 100644 index 0000000000000000000000000000000000000000..0b24dc321d8863c8bad2bc4fc38e38020230a7f5 --- /dev/null +++ b/internal/tui/components/core/status_test.go @@ -0,0 +1,147 @@ +package core_test + +import ( + "fmt" + "image/color" + "testing" + + "github.com/charmbracelet/crush/internal/tui/components/core" + "github.com/charmbracelet/x/exp/golden" +) + +func TestStatus(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + opts core.StatusOpts + width int + }{ + { + name: "Default", + opts: core.StatusOpts{ + Title: "Status", + Description: "Everything is working fine", + }, + width: 80, + }, + { + name: "WithCustomIcon", + opts: core.StatusOpts{ + Icon: "✓", + Title: "Success", + Description: "Operation completed successfully", + }, + width: 80, + }, + { + name: "NoIcon", + opts: core.StatusOpts{ + NoIcon: true, + Title: "Info", + Description: "This status has no icon", + }, + width: 80, + }, + { + name: "WithColors", + opts: core.StatusOpts{ + Icon: "⚠", + IconColor: color.RGBA{255, 165, 0, 255}, // Orange + Title: "Warning", + TitleColor: color.RGBA{255, 255, 0, 255}, // Yellow + Description: "This is a warning message", + DescriptionColor: color.RGBA{255, 0, 0, 255}, // Red + }, + width: 80, + }, + { + name: "WithExtraContent", + opts: core.StatusOpts{ + Title: "Build", + Description: "Building project", + ExtraContent: "[2/5]", + }, + width: 80, + }, + { + name: "LongDescription", + opts: core.StatusOpts{ + Title: "Processing", + Description: "This is a very long description that should be truncated when the width is too small to display it completely without wrapping", + }, + width: 60, + }, + { + name: "NarrowWidth", + opts: core.StatusOpts{ + Icon: "●", + Title: "Status", + Description: "Short message", + }, + width: 30, + }, + { + name: "VeryNarrowWidth", + opts: core.StatusOpts{ + Icon: "●", + Title: "Test", + Description: "This will be truncated", + }, + width: 20, + }, + { + name: "EmptyDescription", + opts: core.StatusOpts{ + Icon: "●", + Title: "Title Only", + }, + width: 80, + }, + { + name: "AllFieldsWithExtraContent", + opts: core.StatusOpts{ + Icon: "🚀", + IconColor: color.RGBA{0, 255, 0, 255}, // Green + Title: "Deployment", + TitleColor: color.RGBA{0, 0, 255, 255}, // Blue + Description: "Deploying to production environment", + DescriptionColor: color.RGBA{128, 128, 128, 255}, // Gray + ExtraContent: "v1.2.3", + }, + width: 80, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + output := core.Status(tt.opts, tt.width) + golden.RequireEqual(t, []byte(output)) + }) + } +} + +func TestStatusTruncation(t *testing.T) { + t.Parallel() + + opts := core.StatusOpts{ + Icon: "●", + Title: "Very Long Title", + Description: "This is an extremely long description that definitely needs to be truncated", + ExtraContent: "[extra]", + } + + // Test different widths to ensure truncation works correctly + widths := []int{20, 30, 40, 50, 60} + + for _, width := range widths { + t.Run(fmt.Sprintf("Width%d", width), func(t *testing.T) { + t.Parallel() + + output := core.Status(opts, width) + golden.RequireEqual(t, []byte(output)) + }) + } +} diff --git a/internal/tui/components/core/testdata/TestStatus/AllFieldsWithExtraContent.golden b/internal/tui/components/core/testdata/TestStatus/AllFieldsWithExtraContent.golden new file mode 100644 index 0000000000000000000000000000000000000000..e6f7fb0be25997b79c3d39bddedee2f2d7b11b72 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/AllFieldsWithExtraContent.golden @@ -0,0 +1 @@ +🚀 Deployment Deploying to production environment v1.2.3 \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/Default.golden b/internal/tui/components/core/testdata/TestStatus/Default.golden new file mode 100644 index 0000000000000000000000000000000000000000..a0066dedd418dafe54757dc3159b3a6b11d106ca --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/Default.golden @@ -0,0 +1 @@ +● Status Everything is working fine \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/EmptyDescription.golden b/internal/tui/components/core/testdata/TestStatus/EmptyDescription.golden new file mode 100644 index 0000000000000000000000000000000000000000..f9c4d759b50d02598791a6462f8e9cab2e0a0b6d --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/EmptyDescription.golden @@ -0,0 +1 @@ +● Title Only  \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/LongDescription.golden b/internal/tui/components/core/testdata/TestStatus/LongDescription.golden new file mode 100644 index 0000000000000000000000000000000000000000..f008176649f7941b9f1ee6276f6e65fea36d4c52 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/LongDescription.golden @@ -0,0 +1 @@ +● Processing This is a very long description that should be… \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/NarrowWidth.golden b/internal/tui/components/core/testdata/TestStatus/NarrowWidth.golden new file mode 100644 index 0000000000000000000000000000000000000000..5b9efd7dbb74dcf56344567c1918b470f90eace7 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/NarrowWidth.golden @@ -0,0 +1 @@ +● Status Short message \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/NoIcon.golden b/internal/tui/components/core/testdata/TestStatus/NoIcon.golden new file mode 100644 index 0000000000000000000000000000000000000000..09e14574c853264a4b18dfafcfac256b38045a02 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/NoIcon.golden @@ -0,0 +1 @@ +Info This status has no icon \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/VeryNarrowWidth.golden b/internal/tui/components/core/testdata/TestStatus/VeryNarrowWidth.golden new file mode 100644 index 0000000000000000000000000000000000000000..26628ae3bc28acd49e8f30e60f65912fe563c0e6 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/VeryNarrowWidth.golden @@ -0,0 +1 @@ +● Test This will be… \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/WithColors.golden b/internal/tui/components/core/testdata/TestStatus/WithColors.golden new file mode 100644 index 0000000000000000000000000000000000000000..ff0e3a6ec4847c4786387d26c9752f664d78cd51 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/WithColors.golden @@ -0,0 +1 @@ +⚠ Warning This is a warning message \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/WithCustomIcon.golden b/internal/tui/components/core/testdata/TestStatus/WithCustomIcon.golden new file mode 100644 index 0000000000000000000000000000000000000000..6857f0d29dd58886308e15ea50c7e0822834f2ee --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/WithCustomIcon.golden @@ -0,0 +1 @@ +✓ Success Operation completed successfully \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatus/WithExtraContent.golden b/internal/tui/components/core/testdata/TestStatus/WithExtraContent.golden new file mode 100644 index 0000000000000000000000000000000000000000..47b02e81b5ec4fc0d0c5dd54545d9634811b1636 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatus/WithExtraContent.golden @@ -0,0 +1 @@ +● Build Building project [2/5] \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatusTruncation/Width20.golden b/internal/tui/components/core/testdata/TestStatusTruncation/Width20.golden new file mode 100644 index 0000000000000000000000000000000000000000..4437cba67aa068c2597e558000b9b3005478b378 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatusTruncation/Width20.golden @@ -0,0 +1 @@ +● Very Long Title  [extra] \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatusTruncation/Width30.golden b/internal/tui/components/core/testdata/TestStatusTruncation/Width30.golden new file mode 100644 index 0000000000000000000000000000000000000000..b09cc983c97382e4d92719bb5606d22f9dc2301f --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatusTruncation/Width30.golden @@ -0,0 +1 @@ +● Very Long Title Thi… [extra] \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatusTruncation/Width40.golden b/internal/tui/components/core/testdata/TestStatusTruncation/Width40.golden new file mode 100644 index 0000000000000000000000000000000000000000..5113ce07a0b07d1cfddbcbae0c14046546308f2a --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatusTruncation/Width40.golden @@ -0,0 +1 @@ +● Very Long Title This is an ex… [extra] \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatusTruncation/Width50.golden b/internal/tui/components/core/testdata/TestStatusTruncation/Width50.golden new file mode 100644 index 0000000000000000000000000000000000000000..25bd8723b0cd461311364ecaac92a2b93f00ecd9 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatusTruncation/Width50.golden @@ -0,0 +1 @@ +● Very Long Title This is an extremely lo… [extra] \ No newline at end of file diff --git a/internal/tui/components/core/testdata/TestStatusTruncation/Width60.golden b/internal/tui/components/core/testdata/TestStatusTruncation/Width60.golden new file mode 100644 index 0000000000000000000000000000000000000000..0152f1c2d0ac9e011d744e0cd02283c18edc8d03 --- /dev/null +++ b/internal/tui/components/core/testdata/TestStatusTruncation/Width60.golden @@ -0,0 +1 @@ +● Very Long Title This is an extremely long descrip… [extra] \ No newline at end of file