@@ -137,52 +137,54 @@ describe("Screen.", () => {
137137 } ) ;
138138
139139 it ( "should override default search region with parameter." , async ( ) => {
140+ // GIVEN
140141 const customSearchRegion = new Region ( 10 , 10 , 90 , 90 ) ;
141142 const matchResult = new MatchResult ( 0.99 , searchRegion ) ;
142-
143143 VisionAdapter . prototype . findOnScreenRegion = jest . fn ( ( ) => {
144144 return Promise . resolve ( matchResult ) ;
145145 } ) ;
146-
147146 const visionAdapterMock = new VisionAdapter ( ) ;
148-
149147 const SUT = new Screen ( visionAdapterMock ) ;
150-
151148 const imagePath = "test/path/to/image.png" ;
152149 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 ) ;
161162 } ) ;
162163
163164 it ( "should override both confidence and search region with parameter." , async ( ) => {
165+ // GIVEN
164166 const minMatch = 0.8 ;
165167 const customSearchRegion = new Region ( 10 , 10 , 90 , 90 ) ;
166168 const matchResult = new MatchResult ( minMatch , searchRegion ) ;
167-
168169 VisionAdapter . prototype . findOnScreenRegion = jest . fn ( ( ) => {
169170 return Promise . resolve ( matchResult ) ;
170171 } ) ;
171-
172172 const visionAdapterMock = new VisionAdapter ( ) ;
173-
174173 const SUT = new Screen ( visionAdapterMock ) ;
175-
176174 const imagePath = "test/path/to/image.png" ;
177175 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 ) ;
186188 } ) ;
187189
188190 it ( "should return region to highlight for chaining" , async ( ) => {
@@ -214,4 +216,33 @@ describe("Screen.", () => {
214216 expect ( result ) . toEqual ( highlightRegion ) ;
215217 } ) ;
216218
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+
217248} ) ;
0 commit comments