fix: update UI tests to use test workspace

Ayman Bagabas created

Change summary

internal/ui/model/ui_test.go | 30 +++++++++---------------------
1 file changed, 9 insertions(+), 21 deletions(-)

Detailed changes

internal/ui/model/ui_test.go 🔗

@@ -1,15 +1,13 @@
 package model
 
 import (
-	"reflect"
 	"testing"
-	"unsafe"
 
 	"charm.land/catwalk/pkg/catwalk"
-	"github.com/charmbracelet/crush/internal/app"
 	"github.com/charmbracelet/crush/internal/config"
 	"github.com/charmbracelet/crush/internal/csync"
 	"github.com/charmbracelet/crush/internal/ui/common"
+	"github.com/charmbracelet/crush/internal/workspace"
 	"github.com/stretchr/testify/require"
 )
 
@@ -79,29 +77,19 @@ func TestCurrentModelSupportsImages(t *testing.T) {
 func newTestUIWithConfig(t *testing.T, cfg *config.Config) *UI {
 	t.Helper()
 
-	store := &config.ConfigStore{}
-	setUnexportedField(t, store, "config", cfg)
-
-	appInstance := &app.App{}
-	setUnexportedField(t, appInstance, "config", store)
-
 	return &UI{
 		com: &common.Common{
-			App: appInstance,
+			Workspace: &testWorkspace{cfg: cfg},
 		},
 	}
 }
 
-func setUnexportedField(t *testing.T, target any, name string, value any) {
-	t.Helper()
-
-	v := reflect.ValueOf(target)
-	require.Equal(t, reflect.Pointer, v.Kind())
-	require.False(t, v.IsNil())
-
-	field := v.Elem().FieldByName(name)
-	require.Truef(t, field.IsValid(), "field %q not found", name)
+// testWorkspace is a minimal [workspace.Workspace] stub for unit tests.
+type testWorkspace struct {
+	workspace.Workspace
+	cfg *config.Config
+}
 
-	fieldValue := reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem()
-	fieldValue.Set(reflect.ValueOf(value))
+func (w *testWorkspace) Config() *config.Config {
+	return w.cfg
 }