@@ -11,6 +11,7 @@ import {
11
11
ImageFinderInterface ,
12
12
ImageWriter ,
13
13
ImageWriterParameters ,
14
+ LogProviderInterface ,
14
15
ScreenProviderInterface ,
15
16
} from "./provider" ;
16
17
import { OptionalSearchParameters } from "./optionalsearchparameters.class" ;
@@ -25,8 +26,17 @@ import { Point } from "./point.class";
25
26
jest . mock ( "jimp" , ( ) => { } ) ;
26
27
27
28
const searchRegion = new Region ( 0 , 0 , 1000 , 1000 ) ;
29
+ const loggingMock = mockPartial < LogProviderInterface > ( {
30
+ debug : jest . fn ( ) ,
31
+ info : jest . fn ( ) ,
32
+ warn : jest . fn ( ) ,
33
+ error : jest . fn ( ) ,
34
+ } ) ;
28
35
29
36
const providerRegistryMock = mockPartial < ProviderRegistry > ( {
37
+ getLogProvider ( ) : LogProviderInterface {
38
+ return loggingMock ;
39
+ } ,
30
40
getScreen ( ) : ScreenProviderInterface {
31
41
return mockPartial < ScreenProviderInterface > ( {
32
42
grabScreenRegion ( ) : Promise < Image > {
@@ -45,6 +55,12 @@ const providerRegistryMock = mockPartial<ProviderRegistry>({
45
55
screenSize ( ) : Promise < Region > {
46
56
return Promise . resolve ( searchRegion ) ;
47
57
} ,
58
+ screenWidth ( ) : Promise < number > {
59
+ return Promise . resolve ( searchRegion . width ) ;
60
+ } ,
61
+ screenHeight ( ) : Promise < number > {
62
+ return Promise . resolve ( searchRegion . height ) ;
63
+ } ,
48
64
} ) ;
49
65
} ,
50
66
} ) ;
@@ -54,6 +70,32 @@ beforeEach(() => {
54
70
} ) ;
55
71
56
72
describe ( "Screen." , ( ) => {
73
+ describe ( "dimensions" , ( ) => {
74
+ it ( "should return the screen width" , async ( ) => {
75
+ // GIVEN
76
+ const SUT = new ScreenClass ( providerRegistryMock ) ;
77
+
78
+ // WHEN
79
+ const width = await SUT . width ( ) ;
80
+
81
+ // THEN
82
+ expect ( width ) . toEqual ( searchRegion . width ) ;
83
+ expect ( loggingMock . debug ) . toHaveBeenCalledTimes ( 1 ) ;
84
+ } ) ;
85
+
86
+ it ( "should return the screen height" , async ( ) => {
87
+ // GIVEN
88
+ const SUT = new ScreenClass ( providerRegistryMock ) ;
89
+
90
+ // WHEN
91
+ const height = await SUT . height ( ) ;
92
+
93
+ // THEN
94
+ expect ( height ) . toEqual ( searchRegion . height ) ;
95
+ expect ( loggingMock . debug ) . toHaveBeenCalledTimes ( 1 ) ;
96
+ } ) ;
97
+ } ) ;
98
+
57
99
describe ( "find" , ( ) => {
58
100
describe ( "queries" , ( ) => {
59
101
it ( "should choose the correct finder implementation for images" , async ( ) => {
@@ -639,16 +681,16 @@ describe("Screen.", () => {
639
681
} ,
640
682
} ;
641
683
642
- const findMatchMock = jest . fn ( ( ) => Promise . resolve ( matchResult ) ) ;
684
+ const findMatchMock = jest . fn ( ( ) => Promise . resolve ( [ matchResult ] ) ) ;
643
685
providerRegistryMock . getColorFinder = jest . fn ( ( ) =>
644
686
mockPartial < ColorFinderInterface > ( {
645
- findMatch : findMatchMock ,
687
+ findMatches : findMatchMock ,
646
688
} )
647
689
) ;
648
690
providerRegistryMock . getLogProvider = ( ) => new NoopLogProvider ( ) ;
649
691
650
692
// WHEN
651
- await SUT . find ( needle ) ;
693
+ await SUT . findAll ( needle ) ;
652
694
653
695
// THEN
654
696
expect ( findMatchMock ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments