@@ -137,52 +137,54 @@ describe("Screen.", () => {
137
137
} ) ;
138
138
139
139
it ( "should override default search region with parameter." , async ( ) => {
140
+ // GIVEN
140
141
const customSearchRegion = new Region ( 10 , 10 , 90 , 90 ) ;
141
142
const matchResult = new MatchResult ( 0.99 , searchRegion ) ;
142
-
143
143
VisionAdapter . prototype . findOnScreenRegion = jest . fn ( ( ) => {
144
144
return Promise . resolve ( matchResult ) ;
145
145
} ) ;
146
-
147
146
const visionAdapterMock = new VisionAdapter ( ) ;
148
-
149
147
const SUT = new Screen ( visionAdapterMock ) ;
150
-
151
148
const imagePath = "test/path/to/image.png" ;
152
149
const parameters = new LocationParameters ( customSearchRegion ) ;
153
- await expect ( SUT . find ( imagePath , parameters ) ) . resolves . toEqual ( matchResult . location ) ;
154
- const matchRequest = new MatchRequest (
155
- expect . any ( Image ) ,
156
- join ( cwd ( ) , imagePath ) ,
157
- customSearchRegion ,
158
- SUT . config . confidence ,
159
- true ) ;
160
- expect ( visionAdapterMock . findOnScreenRegion ) . toHaveBeenCalledWith ( matchRequest ) ;
150
+ const expectedMatchRequest = new MatchRequest (
151
+ expect . any ( Image ) ,
152
+ join ( cwd ( ) , imagePath ) ,
153
+ customSearchRegion ,
154
+ SUT . config . confidence ,
155
+ true ) ;
156
+
157
+ // WHEN
158
+ await SUT . find ( imagePath , parameters ) ;
159
+
160
+ // THEN
161
+ expect ( visionAdapterMock . findOnScreenRegion ) . toHaveBeenCalledWith ( expectedMatchRequest ) ;
161
162
} ) ;
162
163
163
164
it ( "should override both confidence and search region with parameter." , async ( ) => {
165
+ // GIVEN
164
166
const minMatch = 0.8 ;
165
167
const customSearchRegion = new Region ( 10 , 10 , 90 , 90 ) ;
166
168
const matchResult = new MatchResult ( minMatch , searchRegion ) ;
167
-
168
169
VisionAdapter . prototype . findOnScreenRegion = jest . fn ( ( ) => {
169
170
return Promise . resolve ( matchResult ) ;
170
171
} ) ;
171
-
172
172
const visionAdapterMock = new VisionAdapter ( ) ;
173
-
174
173
const SUT = new Screen ( visionAdapterMock ) ;
175
-
176
174
const imagePath = "test/path/to/image.png" ;
177
175
const parameters = new LocationParameters ( customSearchRegion , minMatch ) ;
178
- await expect ( SUT . find ( imagePath , parameters ) ) . resolves . toEqual ( matchResult . location ) ;
179
- const matchRequest = new MatchRequest (
180
- expect . any ( Image ) ,
181
- join ( cwd ( ) , imagePath ) ,
182
- customSearchRegion ,
183
- minMatch ,
184
- true ) ;
185
- expect ( visionAdapterMock . findOnScreenRegion ) . toHaveBeenCalledWith ( matchRequest ) ;
176
+ const expectedMatchRequest = new MatchRequest (
177
+ expect . any ( Image ) ,
178
+ join ( cwd ( ) , imagePath ) ,
179
+ customSearchRegion ,
180
+ minMatch ,
181
+ true ) ;
182
+
183
+ // WHEN
184
+ await SUT . find ( imagePath , parameters ) ;
185
+
186
+ // THEN
187
+ expect ( visionAdapterMock . findOnScreenRegion ) . toHaveBeenCalledWith ( expectedMatchRequest ) ;
186
188
} ) ;
187
189
188
190
it ( "should return region to highlight for chaining" , async ( ) => {
@@ -214,4 +216,33 @@ describe("Screen.", () => {
214
216
expect ( result ) . toEqual ( highlightRegion ) ;
215
217
} ) ;
216
218
219
+ it ( "should add search region offset to result image location" , async ( ) => {
220
+
221
+ // GIVEN
222
+ const limitedSearchRegion = new Region ( 100 , 200 , 300 , 400 ) ;
223
+ const resultRegion = new Region ( 50 , 100 , 150 , 200 ) ;
224
+ const matchResult = new MatchResult ( 0.99 , resultRegion ) ;
225
+
226
+ const expectedMatchRegion = new Region (
227
+ limitedSearchRegion . left + resultRegion . left ,
228
+ limitedSearchRegion . top + resultRegion . top ,
229
+ resultRegion . width ,
230
+ resultRegion . height ) ;
231
+
232
+ VisionAdapter . prototype . findOnScreenRegion = jest . fn ( ( ) => {
233
+ return Promise . resolve ( matchResult ) ;
234
+ } ) ;
235
+ const SUT = new Screen ( new VisionAdapter ( ) ) ;
236
+
237
+ // WHEN
238
+ const matchRegion = await SUT . find (
239
+ "test/path/to/image.png" ,
240
+ {
241
+ searchRegion : limitedSearchRegion
242
+ } ) ;
243
+
244
+ // THEN
245
+ expect ( matchRegion ) . toEqual ( expectedMatchRegion ) ;
246
+ } )
247
+
217
248
} ) ;
0 commit comments