Skip to content

Commit 36df50e

Browse files
committed
Updated tests, added E2E tests
1 parent cc85169 commit 36df50e

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

lib/screen.class.e2e.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { existsSync } from "fs";
2+
import { VisionAdapter } from "./adapter/vision.adapter.class";
3+
import { FileType } from "./file-type.enum";
4+
import { Screen } from "./screen.class";
5+
import { sleep } from "./sleep.function";
6+
7+
describe("Screen.", () => {
8+
it("should capture the screen", async () => {
9+
// GIVEN
10+
const visionAdapter = new VisionAdapter();
11+
const SUT = new Screen(visionAdapter);
12+
13+
// WHEN
14+
const filename = await SUT.capture("asdf.txt", FileType.PNG);
15+
16+
// THEN
17+
expect(filename).not.toBeNull();
18+
await sleep(1000);
19+
expect(existsSync(filename)).toBeTruthy();
20+
});
21+
22+
it("should capture the screen and save to JPG", async () => {
23+
// GIVEN
24+
const visionAdapter = new VisionAdapter();
25+
const SUT = new Screen(visionAdapter);
26+
27+
// WHEN
28+
const filename = await SUT.capture("asdf.txt", FileType.JPG);
29+
30+
// THEN
31+
expect(filename).not.toBeNull();
32+
await sleep(1000);
33+
expect(existsSync(filename)).toBeTruthy();
34+
});
35+
});

lib/screen.class.spec.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import {NativeAdapter} from "./adapter/native.adapter.class";
2-
import {VisionAdapter} from "./adapter/vision.adapter.class";
3-
import {Image} from "./image.class";
4-
import {LocationParameters} from "./locationparameters.class";
5-
import {MatchRequest} from "./match-request.class";
6-
import {MatchResult} from "./match-result.class";
7-
import {Region} from "./region.class";
8-
import {Screen} from "./screen.class";
1+
import { VisionAdapter } from "./adapter/vision.adapter.class";
2+
import { Image } from "./image.class";
3+
import { LocationParameters } from "./locationparameters.class";
4+
import { MatchRequest } from "./match-request.class";
5+
import { MatchResult } from "./match-result.class";
6+
import { Region } from "./region.class";
7+
import { Screen } from "./screen.class";
98

109
jest.mock("./adapter/native.adapter.class");
1110
jest.mock("./adapter/vision.adapter.class");
1211

1312
const searchRegion = new Region(0, 0, 100, 100);
1413

1514
beforeAll(() => {
16-
NativeAdapter.prototype.grabScreen = jest.fn(() => {
15+
VisionAdapter.prototype.grabScreen = jest.fn(() => {
1716
return new Image(searchRegion.width, searchRegion.height, new ArrayBuffer(0), 3);
1817
});
1918

20-
NativeAdapter.prototype.screenSize = jest.fn(() => {
19+
VisionAdapter.prototype.screenSize = jest.fn(() => {
2120
return searchRegion;
2221
});
2322
});
@@ -31,9 +30,8 @@ describe("Screen.", () => {
3130
});
3231

3332
const visionAdapterMock = new VisionAdapter();
34-
const nativeAdapterMock = new NativeAdapter();
3533

36-
const SUT = new Screen(visionAdapterMock, nativeAdapterMock);
34+
const SUT = new Screen(visionAdapterMock);
3735
const imagePath = "test/path/to/image.png";
3836
await expect(SUT.findOnScreen(imagePath)).resolves.toEqual(matchResult.location);
3937
const matchRequest = new MatchRequest(
@@ -53,9 +51,8 @@ describe("Screen.", () => {
5351
});
5452

5553
const visionAdapterMock = new VisionAdapter();
56-
const nativeAdapterMock = new NativeAdapter();
5754

58-
const SUT = new Screen(visionAdapterMock, nativeAdapterMock);
55+
const SUT = new Screen(visionAdapterMock);
5956
const imagePath = "test/path/to/image.png";
6057
await expect(SUT.findOnScreen(imagePath))
6158
.rejects
@@ -71,9 +68,8 @@ describe("Screen.", () => {
7168
});
7269

7370
const visionAdapterMock = new VisionAdapter();
74-
const nativeAdapterMock = new NativeAdapter();
7571

76-
const SUT = new Screen(visionAdapterMock, nativeAdapterMock);
72+
const SUT = new Screen(visionAdapterMock);
7773

7874
const imagePath = "test/path/to/image.png";
7975
const parameters = new LocationParameters(undefined, minMatch);
@@ -96,9 +92,8 @@ describe("Screen.", () => {
9692
});
9793

9894
const visionAdapterMock = new VisionAdapter();
99-
const nativeAdapterMock = new NativeAdapter();
10095

101-
const SUT = new Screen(visionAdapterMock, nativeAdapterMock);
96+
const SUT = new Screen(visionAdapterMock);
10297

10398
const imagePath = "test/path/to/image.png";
10499
const parameters = new LocationParameters(customSearchRegion);
@@ -122,9 +117,8 @@ describe("Screen.", () => {
122117
});
123118

124119
const visionAdapterMock = new VisionAdapter();
125-
const nativeAdapterMock = new NativeAdapter();
126120

127-
const SUT = new Screen(visionAdapterMock, nativeAdapterMock);
121+
const SUT = new Screen(visionAdapterMock);
128122

129123
const imagePath = "test/path/to/image.png";
130124
const parameters = new LocationParameters(customSearchRegion, minMatch);

0 commit comments

Comments
 (0)