on main help sign in
fix: update UI tests to use test workspace
commit2182fc469cdccc517550233d00101bcc7918678d authorAyman Bagabas <ayman.bagabas@gmail.com> dateWed 1 Apr 2026, 14:04 (7 months ago) parentf3fe760
1 file changed+9−21
internal/ui/model/ui_test.go+9−21
internal/ui/model/ui_test.go+9−21
@@ -1,15 +1,13 @@
11package model
22
33import (
4− "reflect"
54 "testing"
6− "unsafe"
75
86 "charm.land/catwalk/pkg/catwalk"
9− "github.com/charmbracelet/crush/internal/app"
107 "github.com/charmbracelet/crush/internal/config"
118 "github.com/charmbracelet/crush/internal/csync"
129 "github.com/charmbracelet/crush/internal/ui/common"
10+ "github.com/charmbracelet/crush/internal/workspace"
1311 "github.com/stretchr/testify/require"
1412)
1513
@@ -79,29 +77,19 @@ func TestCurrentModelSupportsImages(t *testing.T) {
7977func newTestUIWithConfig(t *testing.T, cfg *config.Config) *UI {
8078 t.Helper()
8179
82− store := &config.ConfigStore{}
83− setUnexportedField(t, store, "config", cfg)
84−
85− appInstance := &app.App{}
86− setUnexportedField(t, appInstance, "config", store)
87−
8880 return &UI{
8981 com: &common.Common{
90− App: appInstance,
82+ Workspace: &testWorkspace{cfg: cfg},
9183 },
9284 }
9385}
9486
95−func setUnexportedField(t *testing.T, target any, name string, value any) {
96− t.Helper()
97−
98− v := reflect.ValueOf(target)
99− require.Equal(t, reflect.Pointer, v.Kind())
100− require.False(t, v.IsNil())
101−
102− field := v.Elem().FieldByName(name)
103− require.Truef(t, field.IsValid(), "field %q not found", name)
87+// testWorkspace is a minimal [workspace.Workspace] stub for unit tests.
88+type testWorkspace struct {
89+ workspace.Workspace
90+ cfg *config.Config
91+}
10492
105− fieldValue := reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem()
106− fieldValue.Set(reflect.ValueOf(value))
93+func (w *testWorkspace) Config() *config.Config {
94+ return w.cfg
10795}