gui/pkg/clipboard/service_test.go
Claude 18a455b460
Some checks failed
Security Scan / security (push) Failing after 25s
refactor: migrate entire gui to Core v0.8.0 API
- Import paths: forge.lthn.ai/core/go → dappco.re/go/core
- Import paths: forge.lthn.ai/core/go-log → dappco.re/go/core/log
- Import paths: forge.lthn.ai/core/go-io → dappco.re/go/core/io
- RegisterTask → c.Action("name", handler) across all 15 services
- QueryHandler signature: (any, bool, error) → core.Result
- PERFORM(task) → Action.Run(ctx, opts)
- QUERY returns single core.Result (not 3 values)
- All 17 packages build and test clean on v0.8.0-alpha.1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 16:14:19 +01:00

79 lines
1.9 KiB
Go

// pkg/clipboard/service_test.go
package clipboard
import (
"context"
"testing"
core "dappco.re/go/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type mockPlatform struct {
text string
ok bool
}
func (m *mockPlatform) Text() (string, bool) { return m.text, m.ok }
func (m *mockPlatform) SetText(text string) bool {
m.text = text
m.ok = text != ""
return true
}
func newTestService(t *testing.T) (*Service, *core.Core) {
t.Helper()
c := core.New(
core.WithService(Register(&mockPlatform{text: "hello", ok: true})),
core.WithServiceLock(),
)
require.True(t, c.ServiceStartup(context.Background(), nil).OK)
svc := core.MustServiceFor[*Service](c, "clipboard")
return svc, c
}
func TestRegister_Good(t *testing.T) {
svc, _ := newTestService(t)
assert.NotNil(t, svc)
}
func TestQueryText_Good(t *testing.T) {
_, c := newTestService(t)
r := c.QUERY(QueryText{})
require.True(t, r.OK)
content := r.Value.(ClipboardContent)
assert.Equal(t, "hello", content.Text)
assert.True(t, content.HasContent)
}
func TestQueryText_Bad(t *testing.T) {
// No clipboard service registered
c := core.New(core.WithServiceLock())
r := c.QUERY(QueryText{})
assert.False(t, r.OK)
}
func TestTaskSetText_Good(t *testing.T) {
_, c := newTestService(t)
r := c.Action("clipboard.setText").Run(context.Background(), core.NewOptions(
core.Option{Key: "text", Value: "world"},
))
require.True(t, r.OK)
assert.Equal(t, true, r.Value)
// Verify via query
qr := c.QUERY(QueryText{})
assert.Equal(t, "world", qr.Value.(ClipboardContent).Text)
}
func TestTaskClear_Good(t *testing.T) {
_, c := newTestService(t)
r := c.Action("clipboard.clear").Run(context.Background(), core.NewOptions())
require.True(t, r.OK)
// Verify empty
qr := c.QUERY(QueryText{})
assert.Equal(t, "", qr.Value.(ClipboardContent).Text)
assert.False(t, qr.Value.(ClipboardContent).HasContent)
}