1- import robot = require( "@nut-tree/libnut" ) ;
1+ import libnut = require( "@nut-tree/libnut" ) ;
22import { Region } from "../../region.class" ;
3- import { ScreenAction } from "./robotjs -screen-action.class" ;
3+ import { ScreenAction } from "./libnut -screen-action.class" ;
44
55jest . mock ( "@nut-tree/libnut" ) ;
66
@@ -11,7 +11,7 @@ beforeEach(() => {
1111const screenSize = new Region ( 0 , 0 , 100 , 100 ) ;
1212const screenShotSize = new Region ( 0 , 0 , 200 , 200 ) ;
1313
14- describe ( "robotjs screen action" , ( ) => {
14+ describe ( "libnut screen action" , ( ) => {
1515 describe ( "screen data" , ( ) => {
1616 it ( "should reject when no screenshot data is available" , async ( ) => {
1717 // GIVEN
@@ -22,13 +22,13 @@ describe("robotjs screen action", () => {
2222
2323 // THEN
2424 await expect ( call ( ) ) . rejects . toEqual ( "Unable to fetch screen content." ) ;
25- expect ( robot . screen . capture ) . toBeCalledTimes ( 1 ) ;
25+ expect ( libnut . screen . capture ) . toBeCalledTimes ( 1 ) ;
2626 } ) ;
2727
2828 it ( "should resolve when screenshot data is available" , async ( ) => {
2929 // GIVEN
3030 const SUT = new ScreenAction ( ) ;
31- robot . screen . capture = jest . fn ( ( ) => ( {
31+ libnut . screen . capture = jest . fn ( ( ) => ( {
3232 bitsPerPixel : 0 ,
3333 byteWidth : 0 ,
3434 bytesPerPixel : 0 ,
@@ -38,7 +38,7 @@ describe("robotjs screen action", () => {
3838 width : screenShotSize . width ,
3939 } )
4040 ) ;
41- robot . getScreenSize = jest . fn ( ( ) => ( {
41+ libnut . getScreenSize = jest . fn ( ( ) => ( {
4242 height : screenSize . height ,
4343 width : screenSize . width ,
4444 } )
@@ -52,14 +52,14 @@ describe("robotjs screen action", () => {
5252 expect ( image . height ) . toEqual ( screenShotSize . height ) ;
5353 expect ( image . pixelDensity . scaleX ) . toEqual ( 2 ) ;
5454 expect ( image . pixelDensity . scaleY ) . toEqual ( 2 ) ;
55- expect ( robot . screen . capture ) . toBeCalledTimes ( 1 ) ;
55+ expect ( libnut . screen . capture ) . toBeCalledTimes ( 1 ) ;
5656 } ) ;
5757
5858 it ( "should resolve when screenshot data of a screen region is available" , async ( ) => {
5959 // GIVEN
6060 const screenRegion = new Region ( 0 , 0 , 10 , 10 ) ;
6161 const SUT = new ScreenAction ( ) ;
62- robot . screen . capture = jest . fn ( ( ) => ( {
62+ libnut . screen . capture = jest . fn ( ( ) => ( {
6363 bitsPerPixel : 0 ,
6464 byteWidth : 0 ,
6565 bytesPerPixel : 0 ,
@@ -78,7 +78,7 @@ describe("robotjs screen action", () => {
7878 expect ( image . height ) . toEqual ( screenShotSize . height ) ;
7979 expect ( image . pixelDensity . scaleX ) . toEqual ( 20 ) ;
8080 expect ( image . pixelDensity . scaleY ) . toEqual ( 20 ) ;
81- expect ( robot . screen . capture ) . toBeCalledTimes ( 1 ) ;
81+ expect ( libnut . screen . capture ) . toBeCalledTimes ( 1 ) ;
8282 } ) ;
8383
8484 it ( "should reject when no screenshot of a screen region is available" , async ( ) => {
@@ -91,18 +91,18 @@ describe("robotjs screen action", () => {
9191
9292 // THEN
9393 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 )
9696 . toBeCalledWith ( screenRegion . left , screenRegion . top , screenRegion . width , screenRegion . height ) ;
9797 } ) ;
9898 } ) ;
9999
100100 describe ( "screen size" , ( ) => {
101101 describe ( "screenWidth" , ( ) => {
102- it ( "should determine screen width via robotjs " , async ( ) => {
102+ it ( "should determine screen width via libnut " , async ( ) => {
103103 // GIVEN
104104 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 } ) ) ;
106106
107107 // WHEN
108108 const width = await SUT . screenWidth ( ) ;
@@ -111,11 +111,11 @@ describe("robotjs screen action", () => {
111111 expect ( width ) . toEqual ( screenSize . width ) ;
112112 } ) ;
113113
114- it ( "should reject on robotjs errors" , async ( ) => {
114+ it ( "should reject on libnut errors" , async ( ) => {
115115 // GIVEN
116116 const SUT = new ScreenAction ( ) ;
117117 const error = "Test error" ;
118- robot . getScreenSize = jest . fn ( ( ) => {
118+ libnut . getScreenSize = jest . fn ( ( ) => {
119119 throw new Error ( error ) ;
120120 } ) ;
121121
@@ -127,10 +127,10 @@ describe("robotjs screen action", () => {
127127 } ) ;
128128
129129 describe ( "screenWidth" , ( ) => {
130- it ( "should determine screen height via robotjs " , async ( ) => {
130+ it ( "should determine screen height via libnut " , async ( ) => {
131131 // GIVEN
132132 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 } ) ) ;
134134
135135 // WHEN
136136 const width = await SUT . screenHeight ( ) ;
@@ -139,11 +139,11 @@ describe("robotjs screen action", () => {
139139 expect ( width ) . toEqual ( screenSize . height ) ;
140140 } ) ;
141141
142- it ( "should reject on robotjs errors" , async ( ) => {
142+ it ( "should reject on libnut errors" , async ( ) => {
143143 // GIVEN
144144 const SUT = new ScreenAction ( ) ;
145145 const error = "Test error" ;
146- robot . getScreenSize = jest . fn ( ( ) => {
146+ libnut . getScreenSize = jest . fn ( ( ) => {
147147 throw new Error ( error ) ;
148148 } ) ;
149149
@@ -155,10 +155,10 @@ describe("robotjs screen action", () => {
155155 } ) ;
156156
157157 describe ( "screenWidth" , ( ) => {
158- it ( "should determine screen size via robotjs " , async ( ) => {
158+ it ( "should determine screen size via libnut " , async ( ) => {
159159 // GIVEN
160160 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 } ) ) ;
162162
163163 // WHEN
164164 const size = await SUT . screenSize ( ) ;
@@ -167,11 +167,47 @@ describe("robotjs screen action", () => {
167167 expect ( size ) . toEqual ( screenSize ) ;
168168 } ) ;
169169
170- it ( "should reject on robotjs errors" , async ( ) => {
170+ it ( "should reject on libnut errors" , async ( ) => {
171171 // GIVEN
172172 const SUT = new ScreenAction ( ) ;
173173 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 ( ( ) => {
175211 throw new Error ( error ) ;
176212 } ) ;
177213
0 commit comments