1
- import robot = require( "@nut-tree/libnut" ) ;
1
+ import libnut = require( "@nut-tree/libnut" ) ;
2
2
import { Region } from "../../region.class" ;
3
- import { ScreenAction } from "./robotjs -screen-action.class" ;
3
+ import { ScreenAction } from "./libnut -screen-action.class" ;
4
4
5
5
jest . mock ( "@nut-tree/libnut" ) ;
6
6
@@ -11,7 +11,7 @@ beforeEach(() => {
11
11
const screenSize = new Region ( 0 , 0 , 100 , 100 ) ;
12
12
const screenShotSize = new Region ( 0 , 0 , 200 , 200 ) ;
13
13
14
- describe ( "robotjs screen action" , ( ) => {
14
+ describe ( "libnut screen action" , ( ) => {
15
15
describe ( "screen data" , ( ) => {
16
16
it ( "should reject when no screenshot data is available" , async ( ) => {
17
17
// GIVEN
@@ -22,13 +22,13 @@ describe("robotjs screen action", () => {
22
22
23
23
// THEN
24
24
await expect ( call ( ) ) . rejects . toEqual ( "Unable to fetch screen content." ) ;
25
- expect ( robot . screen . capture ) . toBeCalledTimes ( 1 ) ;
25
+ expect ( libnut . screen . capture ) . toBeCalledTimes ( 1 ) ;
26
26
} ) ;
27
27
28
28
it ( "should resolve when screenshot data is available" , async ( ) => {
29
29
// GIVEN
30
30
const SUT = new ScreenAction ( ) ;
31
- robot . screen . capture = jest . fn ( ( ) => ( {
31
+ libnut . screen . capture = jest . fn ( ( ) => ( {
32
32
bitsPerPixel : 0 ,
33
33
byteWidth : 0 ,
34
34
bytesPerPixel : 0 ,
@@ -38,7 +38,7 @@ describe("robotjs screen action", () => {
38
38
width : screenShotSize . width ,
39
39
} )
40
40
) ;
41
- robot . getScreenSize = jest . fn ( ( ) => ( {
41
+ libnut . getScreenSize = jest . fn ( ( ) => ( {
42
42
height : screenSize . height ,
43
43
width : screenSize . width ,
44
44
} )
@@ -52,14 +52,14 @@ describe("robotjs screen action", () => {
52
52
expect ( image . height ) . toEqual ( screenShotSize . height ) ;
53
53
expect ( image . pixelDensity . scaleX ) . toEqual ( 2 ) ;
54
54
expect ( image . pixelDensity . scaleY ) . toEqual ( 2 ) ;
55
- expect ( robot . screen . capture ) . toBeCalledTimes ( 1 ) ;
55
+ expect ( libnut . screen . capture ) . toBeCalledTimes ( 1 ) ;
56
56
} ) ;
57
57
58
58
it ( "should resolve when screenshot data of a screen region is available" , async ( ) => {
59
59
// GIVEN
60
60
const screenRegion = new Region ( 0 , 0 , 10 , 10 ) ;
61
61
const SUT = new ScreenAction ( ) ;
62
- robot . screen . capture = jest . fn ( ( ) => ( {
62
+ libnut . screen . capture = jest . fn ( ( ) => ( {
63
63
bitsPerPixel : 0 ,
64
64
byteWidth : 0 ,
65
65
bytesPerPixel : 0 ,
@@ -78,7 +78,7 @@ describe("robotjs screen action", () => {
78
78
expect ( image . height ) . toEqual ( screenShotSize . height ) ;
79
79
expect ( image . pixelDensity . scaleX ) . toEqual ( 20 ) ;
80
80
expect ( image . pixelDensity . scaleY ) . toEqual ( 20 ) ;
81
- expect ( robot . screen . capture ) . toBeCalledTimes ( 1 ) ;
81
+ expect ( libnut . screen . capture ) . toBeCalledTimes ( 1 ) ;
82
82
} ) ;
83
83
84
84
it ( "should reject when no screenshot of a screen region is available" , async ( ) => {
@@ -91,18 +91,18 @@ describe("robotjs screen action", () => {
91
91
92
92
// THEN
93
93
await expect ( call ( screenRegion ) ) . rejects . toEqual ( "Unable to fetch screen content." ) ;
94
- expect ( robot . screen . capture ) . toBeCalledTimes ( 1 ) ;
95
- expect ( robot . screen . capture )
94
+ expect ( libnut . screen . capture ) . toBeCalledTimes ( 1 ) ;
95
+ expect ( libnut . screen . capture )
96
96
. toBeCalledWith ( screenRegion . left , screenRegion . top , screenRegion . width , screenRegion . height ) ;
97
97
} ) ;
98
98
} ) ;
99
99
100
100
describe ( "screen size" , ( ) => {
101
101
describe ( "screenWidth" , ( ) => {
102
- it ( "should determine screen width via robotjs " , async ( ) => {
102
+ it ( "should determine screen width via libnut " , async ( ) => {
103
103
// GIVEN
104
104
const SUT = new ScreenAction ( ) ;
105
- robot . getScreenSize = jest . fn ( ( ) => ( { width : screenSize . width , height : screenSize . height } ) ) ;
105
+ libnut . getScreenSize = jest . fn ( ( ) => ( { width : screenSize . width , height : screenSize . height } ) ) ;
106
106
107
107
// WHEN
108
108
const width = await SUT . screenWidth ( ) ;
@@ -111,11 +111,11 @@ describe("robotjs screen action", () => {
111
111
expect ( width ) . toEqual ( screenSize . width ) ;
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 ScreenAction ( ) ;
117
117
const error = "Test error" ;
118
- robot . getScreenSize = jest . fn ( ( ) => {
118
+ libnut . getScreenSize = jest . fn ( ( ) => {
119
119
throw new Error ( error ) ;
120
120
} ) ;
121
121
@@ -127,10 +127,10 @@ describe("robotjs screen action", () => {
127
127
} ) ;
128
128
129
129
describe ( "screenWidth" , ( ) => {
130
- it ( "should determine screen height via robotjs " , async ( ) => {
130
+ it ( "should determine screen height via libnut " , async ( ) => {
131
131
// GIVEN
132
132
const SUT = new ScreenAction ( ) ;
133
- robot . getScreenSize = jest . fn ( ( ) => ( { width : screenSize . width , height : screenSize . height } ) ) ;
133
+ libnut . getScreenSize = jest . fn ( ( ) => ( { width : screenSize . width , height : screenSize . height } ) ) ;
134
134
135
135
// WHEN
136
136
const width = await SUT . screenHeight ( ) ;
@@ -139,11 +139,11 @@ describe("robotjs screen action", () => {
139
139
expect ( width ) . toEqual ( screenSize . height ) ;
140
140
} ) ;
141
141
142
- it ( "should reject on robotjs errors" , async ( ) => {
142
+ it ( "should reject on libnut errors" , async ( ) => {
143
143
// GIVEN
144
144
const SUT = new ScreenAction ( ) ;
145
145
const error = "Test error" ;
146
- robot . getScreenSize = jest . fn ( ( ) => {
146
+ libnut . getScreenSize = jest . fn ( ( ) => {
147
147
throw new Error ( error ) ;
148
148
} ) ;
149
149
@@ -155,10 +155,10 @@ describe("robotjs screen action", () => {
155
155
} ) ;
156
156
157
157
describe ( "screenWidth" , ( ) => {
158
- it ( "should determine screen size via robotjs " , async ( ) => {
158
+ it ( "should determine screen size via libnut " , async ( ) => {
159
159
// GIVEN
160
160
const SUT = new ScreenAction ( ) ;
161
- robot . getScreenSize = jest . fn ( ( ) => ( { width : screenSize . width , height : screenSize . height } ) ) ;
161
+ libnut . getScreenSize = jest . fn ( ( ) => ( { width : screenSize . width , height : screenSize . height } ) ) ;
162
162
163
163
// WHEN
164
164
const size = await SUT . screenSize ( ) ;
@@ -167,11 +167,47 @@ describe("robotjs screen action", () => {
167
167
expect ( size ) . toEqual ( screenSize ) ;
168
168
} ) ;
169
169
170
- it ( "should reject on robotjs errors" , async ( ) => {
170
+ it ( "should reject on libnut errors" , async ( ) => {
171
171
// GIVEN
172
172
const SUT = new ScreenAction ( ) ;
173
173
const error = "Test error" ;
174
- robot . getScreenSize = jest . fn ( ( ) => {
174
+ libnut . getScreenSize = jest . fn ( ( ) => {
175
+ throw new Error ( error ) ;
176
+ } ) ;
177
+
178
+ // WHEN
179
+
180
+ // THEN
181
+ expect ( SUT . screenSize ( ) ) . rejects . toThrowError ( error ) ;
182
+ } ) ;
183
+ } ) ;
184
+
185
+ describe ( "highlight" , ( ) => {
186
+ it ( "should highlight a screen region via libnut" , async ( ) => {
187
+ // GIVEN
188
+ const SUT = new ScreenAction ( ) ;
189
+ libnut . screen . highlight = jest . fn ( ( ) => { } ) ;
190
+ const x = 10 ;
191
+ const y = 20 ;
192
+ const w = 30 ;
193
+ const h = 40 ;
194
+ const testRegion = new Region ( x , y , w , h ) ;
195
+ const highlightDuration = 10 ;
196
+ const highlightOpacity = 1.0 ;
197
+
198
+ // WHEN
199
+ await SUT . highlightScreenRegion ( testRegion , highlightDuration , highlightOpacity ) ;
200
+
201
+ // THEN
202
+ expect ( libnut . screen . highlight ) . toBeCalledTimes ( 1 ) ;
203
+ expect ( libnut . screen . highlight ) . toBeCalledWith ( x , y , w , h , highlightDuration , highlightOpacity ) ;
204
+ } ) ;
205
+
206
+ it ( "should reject on libnut errors" , async ( ) => {
207
+ // GIVEN
208
+ const SUT = new ScreenAction ( ) ;
209
+ const error = "Test error" ;
210
+ libnut . getScreenSize = jest . fn ( ( ) => {
175
211
throw new Error ( error ) ;
176
212
} ) ;
177
213
0 commit comments