@@ -283,6 +283,47 @@ describe("Screen.", () => {
283283 // THEN
284284 expect ( matchRegion ) . toEqual ( expectedMatchRegion ) ;
285285 } )
286+
287+ it . each ( [
288+ [ "with negative x coordinate" , new Region ( - 1 , 0 , 100 , 100 ) ] ,
289+ [ "with negative y coordinate" , new Region ( 0 , - 1 , 100 , 100 ) ] ,
290+ [ "with negative width" , new Region ( 0 , 0 , - 100 , 100 ) ] ,
291+ [ "with negative height" , new Region ( 0 , 0 , 100 , - 100 ) ] ,
292+ [ "with region outside screen on x axis" , new Region ( 1100 , 0 , 100 , 100 ) ] ,
293+ [ "with region outside screen on y axis" , new Region ( 0 , 1100 , 100 , 100 ) ] ,
294+ [ "with region bigger than screen on x axis" , new Region ( 0 , 0 , 1100 , 100 ) ] ,
295+ [ "with region bigger than screen on y axis" , new Region ( 0 , 0 , 1000 , 1100 ) ] ,
296+ [ "with region of 1 px width" , new Region ( 0 , 0 , 1 , 1100 ) ] ,
297+ [ "with region of 1 px height" , new Region ( 0 , 0 , 100 , 1 ) ] ,
298+ [ "with region leaving screen on x axis" , new Region ( 600 , 0 , 500 , 100 ) ] ,
299+ [ "with region leaving screen on y axis" , new Region ( 0 , 500 , 100 , 600 ) ] ,
300+ [ "with NaN x coordinate" , new Region ( "a" as unknown as number , 0 , 100 , 100 ) ] ,
301+ [ "with NaN y coordinate" , new Region ( 0 , "a" as unknown as number , 100 , 600 ) ] ,
302+ [ "with NaN on width" , new Region ( 0 , 0 , "a" as unknown as number , 100 ) ] ,
303+ [ "with NaN on height" , new Region ( 0 , 0 , 100 , "a" as unknown as number ) ] ,
304+ ] ) ( "should reject search regions %s" , async ( _ , region ) => {
305+
306+ // GIVEN
307+ const imagePath = "test/path/to/image.png"
308+ const visionAdapterMock = new VisionAdapter ( ) ;
309+
310+ const SUT = new Screen ( visionAdapterMock ) ;
311+
312+ const matchResult = new MatchResult ( 0.99 , region ) ;
313+ VisionAdapter . prototype . findOnScreenRegion = jest . fn ( ( ) => {
314+ return Promise . resolve ( matchResult ) ;
315+ } ) ;
316+
317+ // WHEN
318+ const findPromise = SUT . find (
319+ imagePath ,
320+ {
321+ searchRegion : region
322+ } ) ;
323+
324+ // THEN
325+ await expect ( findPromise ) . rejects . toContain ( `Searching for ${ imagePath } failed. Reason:` ) ;
326+ } )
286327 } ) ;
287328
288329
0 commit comments