@@ -4,6 +4,7 @@ import {FileType} from "./file-type.enum";
4
4
import { ScreenClass } from "./screen.class" ;
5
5
import { sleep } from "./sleep.function" ;
6
6
import AbortController from "node-abort-controller" ;
7
+ import { Region } from "./region.class" ;
7
8
8
9
jest . setTimeout ( 10000 ) ;
9
10
@@ -135,4 +136,35 @@ describe("Screen.", () => {
135
136
} ) ;
136
137
setTimeout ( ( ) => controller . abort ( ) , abortAfterMs ) ;
137
138
} ) ;
139
+
140
+ it ( "should grab the whole screen content and return an Image" , async ( ) => {
141
+ // GIVEN
142
+ const visionAdapter = new VisionAdapter ( ) ;
143
+ const SUT = new ScreenClass ( visionAdapter ) ;
144
+ const screenWidth = await SUT . width ( ) ;
145
+ const screenHeight = await SUT . height ( ) ;
146
+
147
+ // WHEN
148
+ const image = await SUT . grab ( ) ;
149
+
150
+ // THEN
151
+ expect ( image . data ) . not . toBeUndefined ( ) ;
152
+ expect ( image . width / image . pixelDensity . scaleX ) . toBe ( screenWidth ) ;
153
+ expect ( image . height / image . pixelDensity . scaleY ) . toBe ( screenHeight ) ;
154
+ } ) ;
155
+
156
+ it ( "should grab a screen region and return an Image" , async ( ) => {
157
+ // GIVEN
158
+ const visionAdapter = new VisionAdapter ( ) ;
159
+ const SUT = new ScreenClass ( visionAdapter ) ;
160
+ const regionToGrab = new Region ( 0 , 0 , 100 , 100 ) ;
161
+
162
+ // WHEN
163
+ const image = await SUT . grabRegion ( regionToGrab ) ;
164
+
165
+ // THEN
166
+ expect ( image . data ) . not . toBeUndefined ( ) ;
167
+ expect ( image . width / image . pixelDensity . scaleX ) . toBe ( regionToGrab . width ) ;
168
+ expect ( image . height / image . pixelDensity . scaleY ) . toBe ( regionToGrab . height ) ;
169
+ } ) ;
138
170
} ) ;
0 commit comments