Skip to content

Commit 9ccc8f1

Browse files
committed
(#160) Added test for result region offset issue
1 parent 3734567 commit 9ccc8f1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/screen.class.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,33 @@ describe("Screen.", () => {
214214
expect(result).toEqual(highlightRegion);
215215
});
216216

217+
it("should add search region offset to result image location", async () => {
218+
219+
// GIVEN
220+
const limitedSearchRegion = new Region(100, 200, 300, 400);
221+
const resultRegion = new Region(50, 100, 150, 200);
222+
const matchResult = new MatchResult(0.99, resultRegion);
223+
224+
const expectedMatchRegion = new Region(
225+
limitedSearchRegion.left + resultRegion.left,
226+
limitedSearchRegion.top + resultRegion.top,
227+
resultRegion.width,
228+
resultRegion.height);
229+
230+
VisionAdapter.prototype.findOnScreenRegion = jest.fn(() => {
231+
return Promise.resolve(matchResult);
232+
});
233+
const SUT = new Screen(new VisionAdapter());
234+
235+
// WHEN
236+
const matchRegion = await SUT.find(
237+
"test/path/to/image.png",
238+
{
239+
searchRegion: limitedSearchRegion
240+
});
241+
242+
// THEN
243+
expect(matchRegion).toEqual(expectedMatchRegion);
244+
})
245+
217246
});

0 commit comments

Comments
 (0)