1
- import robot = require( "@nut-tree/libnut" ) ;
1
+ import libnut = require( "@nut-tree/libnut" ) ;
2
2
import { Key } from "../../key.enum" ;
3
- import { KeyboardAction } from "./robotjs -keyboard-action.class" ;
3
+ import { KeyboardAction } from "./libnut -keyboard-action.class" ;
4
4
5
5
jest . mock ( "@nut-tree/libnut" ) ;
6
6
7
7
beforeEach ( ( ) => {
8
8
jest . resetAllMocks ( ) ;
9
9
} ) ;
10
10
11
- describe ( "robotjs keyboard action" , ( ) => {
11
+ describe ( "libnut keyboard action" , ( ) => {
12
12
describe ( "click" , ( ) => {
13
- it ( "should forward the keyTap call to robotjs for a known key" , ( ) => {
13
+ it ( "should forward the keyTap call to libnut for a known key" , ( ) => {
14
14
// GIVEN
15
15
const SUT = new KeyboardAction ( ) ;
16
16
17
17
// WHEN
18
18
SUT . click ( Key . A ) ;
19
19
20
20
// THEN
21
- expect ( robot . keyTap ) . toBeCalledTimes ( 1 ) ;
21
+ expect ( libnut . keyTap ) . toBeCalledTimes ( 1 ) ;
22
22
} ) ;
23
23
24
- it ( "should reject on robotjs errors" , async ( ) => {
24
+ it ( "should reject on libnut errors" , async ( ) => {
25
25
// GIVEN
26
26
const SUT = new KeyboardAction ( ) ;
27
- robot . keyTap = jest . fn ( ( ) => {
27
+ libnut . keyTap = jest . fn ( ( ) => {
28
28
throw new Error ( "Test error" ) ;
29
29
} ) ;
30
30
@@ -34,20 +34,20 @@ describe("robotjs keyboard action", () => {
34
34
expect ( SUT . click ( Key . A ) ) . rejects . toThrowError ( "Test error" ) ;
35
35
} ) ;
36
36
37
- it ( "should not forward the keyTap call to robotjs for an unknown key" , ( ) => {
37
+ it ( "should not forward the keyTap call to libnut for an unknown key" , ( ) => {
38
38
// GIVEN
39
39
const SUT = new KeyboardAction ( ) ;
40
40
41
41
// WHEN
42
42
SUT . click ( Key . Add ) ;
43
43
44
44
// THEN
45
- expect ( robot . keyTap ) . not . toBeCalled ( ) ;
45
+ expect ( libnut . keyTap ) . not . toBeCalled ( ) ;
46
46
} ) ;
47
47
} ) ;
48
48
49
49
describe ( "type" , ( ) => {
50
- it ( "should forward the type call to robotjs " , ( ) => {
50
+ it ( "should forward the type call to libnut " , ( ) => {
51
51
// GIVEN
52
52
const SUT = new KeyboardAction ( ) ;
53
53
const payload = "testInput" ;
@@ -56,14 +56,14 @@ describe("robotjs keyboard action", () => {
56
56
SUT . type ( payload ) ;
57
57
58
58
// THEN
59
- expect ( robot . typeString ) . toBeCalledTimes ( 1 ) ;
60
- expect ( robot . typeString ) . toBeCalledWith ( payload ) ;
59
+ expect ( libnut . typeString ) . toBeCalledTimes ( 1 ) ;
60
+ expect ( libnut . typeString ) . toBeCalledWith ( payload ) ;
61
61
} ) ;
62
62
63
- it ( "should reject on robotjs errors" , async ( ) => {
63
+ it ( "should reject on libnut errors" , async ( ) => {
64
64
// GIVEN
65
65
const SUT = new KeyboardAction ( ) ;
66
- robot . typeString = jest . fn ( ( ) => {
66
+ libnut . typeString = jest . fn ( ( ) => {
67
67
throw new Error ( "Test error" ) ;
68
68
} ) ;
69
69
@@ -75,16 +75,16 @@ describe("robotjs keyboard action", () => {
75
75
} ) ;
76
76
77
77
describe ( "pressKey" , ( ) => {
78
- it ( "should forward the pressKey call to robotjs for a known key" , ( ) => {
78
+ it ( "should forward the pressKey call to libnut for a known key" , ( ) => {
79
79
// GIVEN
80
80
const SUT = new KeyboardAction ( ) ;
81
81
82
82
// WHEN
83
83
SUT . pressKey ( Key . A ) ;
84
84
85
85
// THEN
86
- expect ( robot . keyToggle ) . toBeCalledTimes ( 1 ) ;
87
- expect ( robot . keyToggle ) . toBeCalledWith ( KeyboardAction . keyLookup ( Key . A ) , "down" , [ ] ) ;
86
+ expect ( libnut . keyToggle ) . toBeCalledTimes ( 1 ) ;
87
+ expect ( libnut . keyToggle ) . toBeCalledWith ( KeyboardAction . keyLookup ( Key . A ) , "down" , [ ] ) ;
88
88
} ) ;
89
89
90
90
it ( "should treat a list of keys as modifiers + the actual key to press" , ( ) => {
@@ -95,26 +95,26 @@ describe("robotjs keyboard action", () => {
95
95
SUT . pressKey ( Key . LeftControl , Key . A ) ;
96
96
97
97
// THEN
98
- expect ( robot . keyToggle ) . toBeCalledTimes ( 1 ) ;
99
- expect ( robot . keyToggle )
98
+ expect ( libnut . keyToggle ) . toBeCalledTimes ( 1 ) ;
99
+ expect ( libnut . keyToggle )
100
100
. toBeCalledWith ( KeyboardAction . keyLookup ( Key . A ) , "down" , [ KeyboardAction . keyLookup ( Key . LeftControl ) ] ) ;
101
101
} ) ;
102
102
103
- it ( "should not forward the pressKey call to robotjs for an unknown key" , ( ) => {
103
+ it ( "should not forward the pressKey call to libnut for an unknown key" , ( ) => {
104
104
// GIVEN
105
105
const SUT = new KeyboardAction ( ) ;
106
106
107
107
// WHEN
108
108
SUT . pressKey ( Key . Add ) ;
109
109
110
110
// THEN
111
- expect ( robot . keyToggle ) . not . toBeCalled ( ) ;
111
+ expect ( libnut . keyToggle ) . not . toBeCalled ( ) ;
112
112
} ) ;
113
113
114
- it ( "should reject on robotjs errors" , async ( ) => {
114
+ it ( "should reject on libnut errors" , async ( ) => {
115
115
// GIVEN
116
116
const SUT = new KeyboardAction ( ) ;
117
- robot . keyToggle = jest . fn ( ( ) => {
117
+ libnut . keyToggle = jest . fn ( ( ) => {
118
118
throw new Error ( "Test error" ) ;
119
119
} ) ;
120
120
@@ -126,16 +126,16 @@ describe("robotjs keyboard action", () => {
126
126
} ) ;
127
127
128
128
describe ( "releaseKey" , ( ) => {
129
- it ( "should forward the releaseKey call to robotjs for a known key" , ( ) => {
129
+ it ( "should forward the releaseKey call to libnut for a known key" , ( ) => {
130
130
// GIVEN
131
131
const SUT = new KeyboardAction ( ) ;
132
132
133
133
// WHEN
134
134
SUT . releaseKey ( Key . A ) ;
135
135
136
136
// THEN
137
- expect ( robot . keyToggle ) . toBeCalledTimes ( 1 ) ;
138
- expect ( robot . keyToggle ) . toBeCalledWith ( KeyboardAction . keyLookup ( Key . A ) , "up" , [ ] ) ;
137
+ expect ( libnut . keyToggle ) . toBeCalledTimes ( 1 ) ;
138
+ expect ( libnut . keyToggle ) . toBeCalledWith ( KeyboardAction . keyLookup ( Key . A ) , "up" , [ ] ) ;
139
139
} ) ;
140
140
141
141
it ( "should treat a list of keys as modifiers + the actual key to release" , ( ) => {
@@ -146,26 +146,26 @@ describe("robotjs keyboard action", () => {
146
146
SUT . releaseKey ( Key . LeftControl , Key . A ) ;
147
147
148
148
// THEN
149
- expect ( robot . keyToggle ) . toBeCalledTimes ( 1 ) ;
150
- expect ( robot . keyToggle )
149
+ expect ( libnut . keyToggle ) . toBeCalledTimes ( 1 ) ;
150
+ expect ( libnut . keyToggle )
151
151
. toBeCalledWith ( KeyboardAction . keyLookup ( Key . A ) , "up" , [ KeyboardAction . keyLookup ( Key . LeftControl ) ] ) ;
152
152
} ) ;
153
153
154
- it ( "should not forward the releaseKey call to robotjs for an unknown key" , ( ) => {
154
+ it ( "should not forward the releaseKey call to libnut for an unknown key" , ( ) => {
155
155
// GIVEN
156
156
const SUT = new KeyboardAction ( ) ;
157
157
158
158
// WHEN
159
159
SUT . releaseKey ( Key . Add ) ;
160
160
161
161
// THEN
162
- expect ( robot . keyToggle ) . not . toBeCalled ( ) ;
162
+ expect ( libnut . keyToggle ) . not . toBeCalled ( ) ;
163
163
} ) ;
164
164
165
- it ( "should reject on robotjs errors" , async ( ) => {
165
+ it ( "should reject on libnut errors" , async ( ) => {
166
166
// GIVEN
167
167
const SUT = new KeyboardAction ( ) ;
168
- robot . keyToggle = jest . fn ( ( ) => {
168
+ libnut . keyToggle = jest . fn ( ( ) => {
169
169
throw new Error ( "Test error" ) ;
170
170
} ) ;
171
171
0 commit comments