forked from asticode/go-astilectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtray_test.go
35 lines (30 loc) · 1.27 KB
/
tray_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package astilectron
import (
"testing"
"github.com/asticode/go-astitools/context"
"github.com/stretchr/testify/assert"
)
func TestTray_Actions(t *testing.T) {
// Init
var c = asticontext.NewCanceller()
var d = newDispatcher()
var i = newIdentifier()
var wrt = &mockedWriter{}
var w = newWriter(wrt)
var tr = newTray(&TrayOptions{
Image: PtrStr("/path/to/image"),
Tooltip: PtrStr("tooltip"),
}, c, d, i, w)
// Actions
testObjectAction(t, func() error { return tr.Create() }, tr.object, wrt, "{\"name\":\""+EventNameTrayCmdCreate+"\",\"targetID\":\""+tr.id+"\",\"trayOptions\":{\"image\":\"/path/to/image\",\"tooltip\":\"tooltip\"}}\n", EventNameTrayEventCreated)
testObjectAction(t, func() error { return tr.SetImage("test") }, tr.object, wrt, "{\"name\":\""+EventNameTrayCmdSetImage+"\",\"targetID\":\""+tr.id+"\",\"image\":\"test\"}\n", EventNameTrayEventImageSet)
testObjectAction(t, func() error { return tr.Destroy() }, tr.object, wrt, "{\"name\":\""+EventNameTrayCmdDestroy+"\",\"targetID\":\""+tr.id+"\"}\n", EventNameTrayEventDestroyed)
assert.True(t, tr.IsDestroyed())
}
func TestTray_NewMenu(t *testing.T) {
a, err := New(Options{})
assert.NoError(t, err)
tr := a.NewTray(&TrayOptions{})
m := tr.NewMenu([]*MenuItemOptions{})
assert.Equal(t, tr.id, m.rootID)
}