Add missing GUI unit coverage
This commit is contained in:
parent
f9f8ee2e92
commit
ccc01b408b
4 changed files with 182 additions and 7 deletions
58
pkg/systray/service_config_test.go
Normal file
58
pkg/systray/service_config_test.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// pkg/systray/service_config_test.go
|
||||
package systray
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newConfigTestSystrayService(t *testing.T) (*Service, *Manager) {
|
||||
t.Helper()
|
||||
|
||||
mgr := NewManager(newMockPlatform())
|
||||
return &Service{manager: mgr}, mgr
|
||||
}
|
||||
|
||||
func TestServiceConfig_applyConfig_Good(t *testing.T) {
|
||||
svc, mgr := newConfigTestSystrayService(t)
|
||||
|
||||
svc.applyConfig(map[string]any{
|
||||
"tooltip": "Core Ready",
|
||||
"icon": "assets/tray.png",
|
||||
})
|
||||
|
||||
info := mgr.GetInfo()
|
||||
assert.Equal(t, "Core Ready", info["tooltip"])
|
||||
assert.Equal(t, "Core Ready", info["label"])
|
||||
assert.Equal(t, "assets/tray.png", svc.iconPath)
|
||||
assert.True(t, mgr.IsActive())
|
||||
}
|
||||
|
||||
func TestServiceConfig_applyConfig_Bad(t *testing.T) {
|
||||
svc, mgr := newConfigTestSystrayService(t)
|
||||
|
||||
svc.applyConfig(map[string]any{
|
||||
"tooltip": 123,
|
||||
"icon": true,
|
||||
})
|
||||
|
||||
info := mgr.GetInfo()
|
||||
assert.Equal(t, "Core", info["tooltip"])
|
||||
assert.Equal(t, "Core", info["label"])
|
||||
assert.Empty(t, svc.iconPath)
|
||||
}
|
||||
|
||||
func TestServiceConfig_applyConfig_Ugly(t *testing.T) {
|
||||
svc, mgr := newConfigTestSystrayService(t)
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
svc.applyConfig(nil)
|
||||
})
|
||||
|
||||
info := mgr.GetInfo()
|
||||
assert.Equal(t, "Core", info["tooltip"])
|
||||
assert.Equal(t, "Core", info["label"])
|
||||
assert.Empty(t, svc.iconPath)
|
||||
}
|
||||
79
pkg/window/service_config_test.go
Normal file
79
pkg/window/service_config_test.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// pkg/window/service_config_test.go
|
||||
package window
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newConfigTestWindowService(t *testing.T) (*Service, *Manager) {
|
||||
t.Helper()
|
||||
|
||||
mgr := &Manager{
|
||||
platform: newMockPlatform(),
|
||||
state: NewStateManagerWithDir(t.TempDir()),
|
||||
layout: NewLayoutManagerWithDir(t.TempDir()),
|
||||
windows: make(map[string]PlatformWindow),
|
||||
}
|
||||
|
||||
return &Service{manager: mgr}, mgr
|
||||
}
|
||||
|
||||
func TestServiceConfig_applyConfig_Good(t *testing.T) {
|
||||
svc, mgr := newConfigTestWindowService(t)
|
||||
|
||||
stateFile := filepath.Join(t.TempDir(), "window-state.json")
|
||||
svc.applyConfig(map[string]any{
|
||||
"default_width": 1440,
|
||||
"default_height": 900,
|
||||
"state_file": stateFile,
|
||||
})
|
||||
|
||||
require.Equal(t, stateFile, mgr.State().filePath())
|
||||
|
||||
pw, err := mgr.Open(WithName("main"))
|
||||
require.NoError(t, err)
|
||||
|
||||
width, height := pw.Size()
|
||||
assert.Equal(t, 1440, width)
|
||||
assert.Equal(t, 900, height)
|
||||
|
||||
mgr.State().SetState("main", WindowState{Width: width, Height: height})
|
||||
mgr.State().ForceSync()
|
||||
|
||||
content, err := os.ReadFile(stateFile)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(content), `"main"`)
|
||||
}
|
||||
|
||||
func TestServiceConfig_applyConfig_Bad(t *testing.T) {
|
||||
svc, mgr := newConfigTestWindowService(t)
|
||||
mgr.SetDefaultWidth(1111)
|
||||
mgr.SetDefaultHeight(2222)
|
||||
initialPath := mgr.State().filePath()
|
||||
|
||||
svc.applyConfig(map[string]any{
|
||||
"default_width": "wide",
|
||||
"default_height": true,
|
||||
"state_file": 123,
|
||||
})
|
||||
|
||||
assert.Equal(t, 1111, mgr.defaultWidth)
|
||||
assert.Equal(t, 2222, mgr.defaultHeight)
|
||||
assert.Equal(t, initialPath, mgr.State().filePath())
|
||||
}
|
||||
|
||||
func TestServiceConfig_applyConfig_Ugly(t *testing.T) {
|
||||
svc, mgr := newConfigTestWindowService(t)
|
||||
initialPath := mgr.State().filePath()
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
svc.applyConfig(nil)
|
||||
})
|
||||
|
||||
assert.Equal(t, initialPath, mgr.State().filePath())
|
||||
}
|
||||
|
|
@ -480,15 +480,19 @@ func TestTaskApplyWorkflow_Good(t *testing.T) {
|
|||
|
||||
editor, ok := svc.Manager().Get("editor")
|
||||
require.True(t, ok)
|
||||
x, y := editor.Position()
|
||||
assert.Equal(t, 0, x)
|
||||
assert.Equal(t, 0, y)
|
||||
|
||||
terminal, ok := svc.Manager().Get("terminal")
|
||||
require.True(t, ok)
|
||||
x, y = terminal.Position()
|
||||
assert.Equal(t, 960, x)
|
||||
assert.Equal(t, 0, y)
|
||||
editorX, editorY := editor.Position()
|
||||
terminalX, terminalY := terminal.Position()
|
||||
|
||||
assert.Equal(t, 0, editorY)
|
||||
assert.Equal(t, 0, terminalY)
|
||||
assert.ElementsMatch(t, []int{0, 960}, []int{editorX, terminalX})
|
||||
|
||||
// The assignment order is derived from map iteration, so only the
|
||||
// geometry matters here.
|
||||
assert.Contains(t, []int{editorX, terminalX}, 0)
|
||||
assert.Contains(t, []int{editorX, terminalX}, 960)
|
||||
}
|
||||
|
||||
// --- Zoom ---
|
||||
|
|
|
|||
34
pkg/window/tiling_test.go
Normal file
34
pkg/window/tiling_test.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// pkg/window/tiling_test.go
|
||||
package window
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTiling_SnapPosition_String_Good(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pos SnapPosition
|
||||
want string
|
||||
}{
|
||||
{name: "left", pos: SnapLeft, want: "left"},
|
||||
{name: "right", pos: SnapRight, want: "right"},
|
||||
{name: "center", pos: SnapCenter, want: "center"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.want, tc.pos.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTiling_SnapPosition_String_Bad(t *testing.T) {
|
||||
assert.Empty(t, SnapPosition(123).String())
|
||||
}
|
||||
|
||||
func TestTiling_SnapPosition_String_Ugly(t *testing.T) {
|
||||
assert.Empty(t, SnapPosition(-1).String())
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue