1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 16:02:51 -05:00

core: mock wayland context for tests & add i18n guidance to CONTRIBUTING

This commit is contained in:
bbedward
2025-12-11 14:50:02 -05:00
parent 9cac93b724
commit 6d66f93565
25 changed files with 1145 additions and 130 deletions

View File

@@ -27,7 +27,7 @@ import (
wlclient "github.com/AvengeMedia/DankMaterialShell/core/pkg/go-wayland/wayland/client"
)
func NewManager(wlCtx *wlcontext.SharedContext, config Config) (*Manager, error) {
func NewManager(wlCtx wlcontext.WaylandContext, config Config) (*Manager, error) {
if config.Disabled {
return nil, fmt.Errorf("clipboard disabled in config")
}

View File

@@ -2,10 +2,14 @@ package clipboard
import (
"sync"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
mocks_wlcontext "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/wlcontext"
)
func TestEncodeDecodeEntry_Roundtrip(t *testing.T) {
@@ -454,3 +458,74 @@ func TestDefaultConfig(t *testing.T) {
assert.False(t, cfg.DisableHistory)
assert.False(t, cfg.DisablePersist)
}
func TestManager_PostDelegatesToWlContext(t *testing.T) {
mockCtx := mocks_wlcontext.NewMockWaylandContext(t)
var called atomic.Bool
mockCtx.EXPECT().Post(mock.AnythingOfType("func()")).Run(func(fn func()) {
called.Store(true)
fn()
}).Once()
m := &Manager{
wlCtx: mockCtx,
}
executed := false
m.post(func() {
executed = true
})
assert.True(t, called.Load())
assert.True(t, executed)
}
func TestManager_PostExecutesFunctionViaContext(t *testing.T) {
mockCtx := mocks_wlcontext.NewMockWaylandContext(t)
var capturedFn func()
mockCtx.EXPECT().Post(mock.AnythingOfType("func()")).Run(func(fn func()) {
capturedFn = fn
}).Times(3)
m := &Manager{
wlCtx: mockCtx,
}
counter := 0
m.post(func() { counter++ })
m.post(func() { counter += 10 })
m.post(func() { counter += 100 })
assert.NotNil(t, capturedFn)
capturedFn()
assert.Equal(t, 100, counter)
}
func TestManager_ConcurrentPostWithMock(t *testing.T) {
mockCtx := mocks_wlcontext.NewMockWaylandContext(t)
var postCount atomic.Int32
mockCtx.EXPECT().Post(mock.AnythingOfType("func()")).Run(func(fn func()) {
postCount.Add(1)
}).Times(100)
m := &Manager{
wlCtx: mockCtx,
}
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j < 10; j++ {
m.post(func() {})
}
}()
}
wg.Wait()
assert.Equal(t, int32(100), postCount.Load())
}

View File

@@ -115,8 +115,8 @@ type Manager struct {
configMutex sync.RWMutex
configPath string
display *wlclient.Display
wlCtx *wlcontext.SharedContext
display wlclient.WaylandDisplay
wlCtx wlcontext.WaylandContext
registry *wlclient.Registry
dataControlMgr any