forked from asticode/go-astilectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_test.go
30 lines (25 loc) · 1.74 KB
/
menu_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
package astilectron
import (
"context"
"testing"
"github.com/asticode/go-astitools/context"
"github.com/stretchr/testify/assert"
)
func TestMenu_ToEvent(t *testing.T) {
var m = newMenu(nil, targetIDApp, []*MenuItemOptions{{Label: PtrStr("1")}, {Label: PtrStr("2")}}, asticontext.NewCanceller(), newDispatcher(), newIdentifier(), nil)
e := m.toEvent()
assert.Equal(t, &EventMenu{EventSubMenu: &EventSubMenu{ID: "1", Items: []*EventMenuItem{{ID: "2", Options: &MenuItemOptions{Label: PtrStr("1")}, RootID: targetIDApp}, {ID: "3", Options: &MenuItemOptions{Label: PtrStr("2")}, RootID: targetIDApp}}, RootID: targetIDApp}}, e)
}
func TestMenu_Actions(t *testing.T) {
// Init
var c = asticontext.NewCanceller()
var d = newDispatcher()
var i = newIdentifier()
var wrt = &mockedWriter{}
var w = newWriter(wrt)
var m = newMenu(context.Background(), targetIDApp, []*MenuItemOptions{{Label: PtrStr("1")}, {Label: PtrStr("2")}}, c, d, i, w)
// Actions
testObjectAction(t, func() error { return m.Create() }, m.object, wrt, "{\"name\":\""+EventNameMenuCmdCreate+"\",\"targetID\":\""+m.id+"\",\"menu\":{\"id\":\"1\",\"items\":[{\"id\":\"2\",\"options\":{\"label\":\"1\"},\"rootId\":\""+targetIDApp+"\"},{\"id\":\"3\",\"options\":{\"label\":\"2\"},\"rootId\":\""+targetIDApp+"\"}],\"rootId\":\""+targetIDApp+"\"}}\n", EventNameMenuEventCreated)
testObjectAction(t, func() error { return m.Destroy() }, m.object, wrt, "{\"name\":\""+EventNameMenuCmdDestroy+"\",\"targetID\":\""+m.id+"\",\"menu\":{\"id\":\"1\",\"items\":[{\"id\":\"2\",\"options\":{\"label\":\"1\"},\"rootId\":\""+targetIDApp+"\"},{\"id\":\"3\",\"options\":{\"label\":\"2\"},\"rootId\":\""+targetIDApp+"\"}],\"rootId\":\""+targetIDApp+"\"}}\n", EventNameMenuEventDestroyed)
assert.True(t, m.IsDestroyed())
}