@@ -36,11 +36,13 @@ describe("Screen.", () => {
36
36
const visionAdapterMock = new VisionAdapter ( ) ;
37
37
38
38
const SUT = new Screen ( visionAdapterMock ) ;
39
- const imagePath = "test/path/to/image.png" ;
40
- await expect ( SUT . find ( imagePath ) ) . resolves . toEqual ( matchResult . location ) ;
39
+ const imageId = "test/path/to/image.png" ;
40
+ const imageData = Buffer . from ( [ ] ) ;
41
+ await expect ( SUT . findImage ( { id : imageId , data : imageData } ) ) . resolves . toEqual ( matchResult . location ) ;
41
42
const matchRequest = new MatchRequest (
42
43
expect . any ( Image ) ,
43
- join ( cwd ( ) , imagePath ) ,
44
+ imageId ,
45
+ imageData ,
44
46
searchRegion ,
45
47
SUT . config . confidence ,
46
48
true ) ;
@@ -56,9 +58,10 @@ describe("Screen.", () => {
56
58
57
59
const SUT = new Screen ( visionAdapterMock ) ;
58
60
const testCallback = jest . fn ( ( ) => Promise . resolve ( ) ) ;
59
- const imagePath = "test/path/to/image.png" ;
60
- SUT . on ( imagePath , testCallback ) ;
61
- await SUT . find ( imagePath ) ;
61
+ const imageId = "test/path/to/image.png" ;
62
+ const imageData = Buffer . from ( [ ] ) ;
63
+ SUT . on ( imageId , testCallback ) ;
64
+ await SUT . findImage ( { id : imageId , data : imageData } ) ;
62
65
expect ( testCallback ) . toBeCalledTimes ( 1 ) ;
63
66
expect ( testCallback ) . toBeCalledWith ( matchResult ) ;
64
67
} ) ;
@@ -73,10 +76,11 @@ describe("Screen.", () => {
73
76
const SUT = new Screen ( visionAdapterMock ) ;
74
77
const testCallback = jest . fn ( ( ) => Promise . resolve ( ) ) ;
75
78
const secondCallback = jest . fn ( ( ) => Promise . resolve ( ) ) ;
76
- const imagePath = "test/path/to/image.png" ;
77
- SUT . on ( imagePath , testCallback ) ;
78
- SUT . on ( imagePath , secondCallback ) ;
79
- await SUT . find ( imagePath ) ;
79
+ const imageId = "test/path/to/image.png" ;
80
+ const imageData = Buffer . from ( [ ] ) ;
81
+ SUT . on ( imageId , testCallback ) ;
82
+ SUT . on ( imageId , secondCallback ) ;
83
+ await SUT . findImage ( { id : imageId , data : imageData } ) ;
80
84
for ( const callback of [ testCallback , secondCallback ] ) {
81
85
expect ( callback ) . toBeCalledTimes ( 1 ) ;
82
86
expect ( callback ) . toBeCalledWith ( matchResult ) ;
@@ -93,10 +97,11 @@ describe("Screen.", () => {
93
97
const visionAdapterMock = new VisionAdapter ( ) ;
94
98
95
99
const SUT = new Screen ( visionAdapterMock ) ;
96
- const imagePath = "test/path/to/image.png" ;
97
- await expect ( SUT . find ( imagePath ) )
100
+ const imageId = "test/path/to/image.png" ;
101
+ const imageData = Buffer . from ( [ ] ) ;
102
+ await expect ( SUT . findImage ( { id : imageId , data : imageData } ) )
98
103
. rejects
99
- . toEqual ( `No match for ${ imagePath } . Required: ${ SUT . config . confidence } , given: ${ matchResult . confidence } ` ) ;
104
+ . toEqual ( `No match for ${ imageId } . Required: ${ SUT . config . confidence } , given: ${ matchResult . confidence } ` ) ;
100
105
} ) ;
101
106
102
107
it ( "should reject when search fails." , async ( ) => {
@@ -108,10 +113,11 @@ describe("Screen.", () => {
108
113
const visionAdapterMock = new VisionAdapter ( ) ;
109
114
110
115
const SUT = new Screen ( visionAdapterMock ) ;
111
- const imagePath = "test/path/to/image.png" ;
112
- await expect ( SUT . find ( imagePath ) )
116
+ const imageId = "test/path/to/image.png" ;
117
+ const imageData = Buffer . from ( [ ] ) ;
118
+ await expect ( SUT . findImage ( { id : imageId , data : imageData } ) )
113
119
. rejects
114
- . toEqual ( `Searching for ${ imagePath } failed. Reason: '${ rejectionReason } '` ) ;
120
+ . toEqual ( `Searching for ${ imageId } failed. Reason: '${ rejectionReason } '` ) ;
115
121
} ) ;
116
122
117
123
it ( "should override default confidence value with parameter." , async ( ) => {
@@ -126,12 +132,14 @@ describe("Screen.", () => {
126
132
127
133
const SUT = new Screen ( visionAdapterMock ) ;
128
134
129
- const imagePath = "test/path/to/image.png" ;
135
+ const imageId = "test/path/to/image.png" ;
136
+ const imageData = Buffer . from ( [ ] ) ;
130
137
const parameters = new LocationParameters ( undefined , minMatch ) ;
131
- await expect ( SUT . find ( imagePath , parameters ) ) . resolves . toEqual ( matchResult . location ) ;
138
+ await expect ( SUT . findImage ( { id : imageId , data : imageData } , parameters ) ) . resolves . toEqual ( matchResult . location ) ;
132
139
const matchRequest = new MatchRequest (
133
140
expect . any ( Image ) ,
134
- join ( cwd ( ) , imagePath ) ,
141
+ imageId ,
142
+ imageData ,
135
143
searchRegion ,
136
144
minMatch ,
137
145
true ) ;
@@ -147,17 +155,19 @@ describe("Screen.", () => {
147
155
} ) ;
148
156
const visionAdapterMock = new VisionAdapter ( ) ;
149
157
const SUT = new Screen ( visionAdapterMock ) ;
150
- const imagePath = "test/path/to/image.png" ;
158
+ const imageId = "test/path/to/image.png" ;
159
+ const imageData = Buffer . from ( [ ] ) ;
151
160
const parameters = new LocationParameters ( customSearchRegion ) ;
152
161
const expectedMatchRequest = new MatchRequest (
153
162
expect . any ( Image ) ,
154
- join ( cwd ( ) , imagePath ) ,
163
+ imageId ,
164
+ imageData ,
155
165
customSearchRegion ,
156
166
SUT . config . confidence ,
157
167
true ) ;
158
168
159
169
// WHEN
160
- await SUT . find ( imagePath , parameters ) ;
170
+ await SUT . findImage ( { id : imageId , data : imageData } , parameters ) ;
161
171
162
172
// THEN
163
173
expect ( visionAdapterMock . findOnScreenRegion ) . toHaveBeenCalledWith ( expectedMatchRequest ) ;
@@ -171,17 +181,19 @@ describe("Screen.", () => {
171
181
} ) ;
172
182
const visionAdapterMock = new VisionAdapter ( ) ;
173
183
const SUT = new Screen ( visionAdapterMock ) ;
174
- const imagePath = "test/path/to/image.png" ;
184
+ const imageId = "test/path/to/image.png" ;
185
+ const imageData = Buffer . from ( [ ] ) ;
175
186
const parameters = new LocationParameters ( searchRegion , undefined , false ) ;
176
187
const expectedMatchRequest = new MatchRequest (
177
188
expect . any ( Image ) ,
178
- join ( cwd ( ) , imagePath ) ,
189
+ imageId ,
190
+ imageData ,
179
191
searchRegion ,
180
192
SUT . config . confidence ,
181
193
false ) ;
182
194
183
195
// WHEN
184
- await SUT . find ( imagePath , parameters ) ;
196
+ await SUT . findImage ( { id : imageId , data : imageData } , parameters ) ;
185
197
186
198
// THEN
187
199
expect ( visionAdapterMock . findOnScreenRegion ) . toHaveBeenCalledWith ( expectedMatchRequest ) ;
@@ -197,17 +209,19 @@ describe("Screen.", () => {
197
209
} ) ;
198
210
const visionAdapterMock = new VisionAdapter ( ) ;
199
211
const SUT = new Screen ( visionAdapterMock ) ;
200
- const imagePath = "test/path/to/image.png" ;
212
+ const imageId = "test/path/to/image.png" ;
213
+ const imageData = Buffer . from ( [ ] ) ;
201
214
const parameters = new LocationParameters ( customSearchRegion , minMatch ) ;
202
215
const expectedMatchRequest = new MatchRequest (
203
216
expect . any ( Image ) ,
204
- join ( cwd ( ) , imagePath ) ,
217
+ imageId ,
218
+ imageData ,
205
219
customSearchRegion ,
206
220
minMatch ,
207
221
true ) ;
208
222
209
223
// WHEN
210
- await SUT . find ( imagePath , parameters ) ;
224
+ await SUT . findImage ( { id : imageId , data : imageData } , parameters ) ;
211
225
212
226
// THEN
213
227
expect ( visionAdapterMock . findOnScreenRegion ) . toHaveBeenCalledWith ( expectedMatchRequest ) ;
@@ -261,8 +275,8 @@ describe("Screen.", () => {
261
275
const SUT = new Screen ( new VisionAdapter ( ) ) ;
262
276
263
277
// WHEN
264
- const matchRegion = await SUT . find (
265
- "test/path/to/image.png" ,
278
+ const matchRegion = await SUT . findImage (
279
+ { id : "test/path/to/image.png" , data : Buffer . from ( [ ] ) } ,
266
280
{
267
281
searchRegion : limitedSearchRegion
268
282
} ) ;
0 commit comments