@@ -7,7 +7,7 @@ import {Region} from "./region.class";
7
7
import { ScreenClass } from "./screen.class" ;
8
8
import { mockPartial } from "sneer" ;
9
9
import { ProviderRegistry } from "./provider/provider-registry.class" ;
10
- import { ImageFinderInterface , ImageWriter , ScreenProviderInterface } from "./provider" ;
10
+ import { ImageFinderInterface , ImageWriter , ImageWriterParameters , ScreenProviderInterface } from "./provider" ;
11
11
import { OptionalSearchParameters } from "./optionalsearchparameters.class" ;
12
12
13
13
jest . mock ( 'jimp' , ( ) => {
@@ -19,7 +19,7 @@ const providerRegistryMock = mockPartial<ProviderRegistry>({
19
19
getScreen ( ) : ScreenProviderInterface {
20
20
return mockPartial < ScreenProviderInterface > ( {
21
21
grabScreenRegion ( ) : Promise < Image > {
22
- return Promise . resolve ( new Image ( searchRegion . width , searchRegion . height , new ArrayBuffer ( 0 ) , 3 , "needle_image" ) ) ;
22
+ return Promise . resolve ( new Image ( searchRegion . width , searchRegion . height , Buffer . from ( [ ] ) , 3 , "needle_image" ) ) ;
23
23
} ,
24
24
screenSize ( ) : Promise < Region > {
25
25
return Promise . resolve ( searchRegion ) ;
@@ -614,7 +614,7 @@ describe("Screen.", () => {
614
614
describe ( "capture" , ( ) => {
615
615
it ( "should capture the whole screen and save image" , async ( ) => {
616
616
// GIVEN
617
- const screenshot = mockPartial < Image > ( { data : "pretty pretty image" } ) ;
617
+ const screenshot = mockPartial < Image > ( { data : Buffer . from ( [ ] ) } ) ;
618
618
const grabScreenMock = jest . fn ( ( ) => Promise . resolve ( screenshot ) ) ;
619
619
const saveImageMock = jest . fn ( ) ;
620
620
providerRegistryMock . getScreen = jest . fn ( ( ) => mockPartial < ScreenProviderInterface > ( {
@@ -627,21 +627,22 @@ describe("Screen.", () => {
627
627
const SUT = new ScreenClass ( providerRegistryMock ) ;
628
628
const imageName = "foobar.png"
629
629
const expectedImagePath = join ( cwd ( ) , imageName )
630
+ const expectedData : ImageWriterParameters = { image : screenshot , path : expectedImagePath }
630
631
631
632
// WHEN
632
633
const imagePath = await SUT . capture ( imageName )
633
634
634
635
// THEN
635
636
expect ( imagePath ) . toBe ( expectedImagePath )
636
637
expect ( grabScreenMock ) . toHaveBeenCalled ( )
637
- expect ( saveImageMock ) . toHaveBeenCalledWith ( { data : screenshot , path : expectedImagePath } )
638
+ expect ( saveImageMock ) . toHaveBeenCalledWith ( expectedData ) ;
638
639
} ) ;
639
640
} )
640
641
641
642
describe ( "captureRegion" , ( ) => {
642
643
it ( "should capture the specified region of the screen and save image" , async ( ) => {
643
644
// GIVEN
644
- const screenshot = mockPartial < Image > ( { data : "pretty partial image" } ) ;
645
+ const screenshot = mockPartial < Image > ( { data : Buffer . from ( [ ] ) } ) ;
645
646
const regionToCapture = mockPartial < Region > ( { top : 42 , left : 9 , height : 10 , width : 3.14159265359 } )
646
647
const grabScreenMock = jest . fn ( ( ) => Promise . resolve ( screenshot ) ) ;
647
648
const saveImageMock = jest . fn ( ) ;
@@ -655,14 +656,15 @@ describe("Screen.", () => {
655
656
const SUT = new ScreenClass ( providerRegistryMock ) ;
656
657
const imageName = "foobar.png"
657
658
const expectedImagePath = join ( cwd ( ) , imageName )
659
+ const expectedData : ImageWriterParameters = { image : screenshot , path : expectedImagePath }
658
660
659
661
// WHEN
660
662
const imagePath = await SUT . captureRegion ( imageName , regionToCapture )
661
663
662
664
// THEN
663
665
expect ( imagePath ) . toBe ( expectedImagePath )
664
666
expect ( grabScreenMock ) . toHaveBeenCalledWith ( regionToCapture )
665
- expect ( saveImageMock ) . toHaveBeenCalledWith ( { data : screenshot , path : expectedImagePath } )
667
+ expect ( saveImageMock ) . toHaveBeenCalledWith ( expectedData ) ;
666
668
} ) ;
667
669
} ) ;
668
670
} ) ;
0 commit comments