This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
/
global_shortcuts_test.go
42 lines (35 loc) · 1.61 KB
/
global_shortcuts_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
36
37
38
39
40
41
42
package astilectron
import (
"context"
"fmt"
"testing"
)
func TestGlobalShortcut_Actions(t *testing.T) {
var d = newDispatcher()
var i = newIdentifier()
var wrt = &mockedWriter{}
var w = newWriter(wrt, &logger{})
var gs = newGlobalShortcuts(context.Background(), d, i, w)
// Register
testObjectAction(t, func() error {
_, e := gs.Register("Ctrl+X", func() {})
return e
}, gs.object, wrt, fmt.Sprintf(`{"name":"%s","targetID":"%s","globalShortcuts":{"accelerator":"Ctrl+X"}}%s`, EventNameGlobalShortcutsCmdRegister, gs.id, "\n"),
EventNameGlobalShortcutsEventRegistered, &Event{GlobalShortcuts: &EventGlobalShortcuts{Accelerator: "Ctrl+X", IsRegistered: true}})
// IsRegistered
testObjectAction(t, func() error {
_, e := gs.IsRegistered("Ctrl+Y")
return e
}, gs.object, wrt, fmt.Sprintf(`{"name":"%s","targetID":"%s","globalShortcuts":{"accelerator":"Ctrl+Y"}}%s`, EventNameGlobalShortcutsCmdIsRegistered, gs.id, "\n"),
EventNameGlobalShortcutsEventIsRegistered, &Event{GlobalShortcuts: &EventGlobalShortcuts{Accelerator: "Ctrl+Y", IsRegistered: false}})
// Unregister
testObjectAction(t, func() error {
return gs.Unregister("Ctrl+Z")
}, gs.object, wrt, fmt.Sprintf(`{"name":"%s","targetID":"%s","globalShortcuts":{"accelerator":"Ctrl+Z"}}%s`, EventNameGlobalShortcutsCmdUnregister, gs.id, "\n"),
EventNameGlobalShortcutsEventUnregistered, nil)
// UnregisterAll
testObjectAction(t, func() error {
return gs.UnregisterAll()
}, gs.object, wrt, fmt.Sprintf(`{"name":"%s","targetID":"%s"}%s`, EventNameGlobalShortcutsCmdUnregisterAll, gs.id, "\n"),
EventNameGlobalShortcutsEventUnregisteredAll, nil)
}