Skip to content

Commit 079eca2

Browse files
authored
Merge pull request #277 from nut-tree/feature/269/internal_objects
(#269) Changed export level and renamed classes to be less ambiguous
2 parents bd5468e + 379da07 commit 079eca2

16 files changed

+137
-137
lines changed

index.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { NativeAdapter } from "./lib/adapter/native.adapter.class";
22
import { VisionAdapter } from "./lib/adapter/vision.adapter.class";
3-
import { Assert } from "./lib/assert.class";
4-
import { Clipboard } from "./lib/clipboard.class";
5-
import { Keyboard } from "./lib/keyboard.class";
6-
import { Mouse } from "./lib/mouse.class";
3+
import { AssertClass } from "./lib/assert.class";
4+
import { ClipboardClass } from "./lib/clipboard.class";
5+
import { KeyboardClass } from "./lib/keyboard.class";
6+
import { MouseClass } from "./lib/mouse.class";
77
import { createMovementApi } from "./lib/movement.function";
8-
import { Screen } from "./lib/screen.class";
8+
import { ScreenClass } from "./lib/screen.class";
99
import { LineHelper } from "./lib/util/linehelper.class";
1010
import { createWindowApi } from "./lib/window.function";
1111

12-
export const internal = {
13-
Assert,
14-
Clipboard,
15-
Keyboard,
16-
Mouse,
17-
Screen,
12+
export {
13+
AssertClass,
14+
ClipboardClass,
15+
KeyboardClass,
16+
MouseClass,
17+
ScreenClass,
1818
}
1919

2020
export { jestMatchers } from "./lib/expect/jest.matcher.function";
@@ -34,11 +34,11 @@ const screenActions = new VisionAdapter();
3434
const nativeActions = new NativeAdapter();
3535
const lineHelper = new LineHelper();
3636

37-
const clipboard = new Clipboard(nativeActions);
38-
const keyboard = new Keyboard(nativeActions);
39-
const mouse = new Mouse(nativeActions);
40-
const screen = new Screen(screenActions);
41-
const assert = new Assert(screen);
37+
const clipboard = new ClipboardClass(nativeActions);
38+
const keyboard = new KeyboardClass(nativeActions);
39+
const mouse = new MouseClass(nativeActions);
40+
const screen = new ScreenClass(screenActions);
41+
const assert = new AssertClass(screen);
4242

4343
const {straightTo, up, down, left, right} = createMovementApi(nativeActions, lineHelper);
4444
const {getWindows, getActiveWindow } = createWindowApi(nativeActions);

lib/assert.class.spec.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { VisionAdapter } from "./adapter/vision.adapter.class";
2-
import { Assert } from "./assert.class";
2+
import { AssertClass } from "./assert.class";
33
import { Region } from "./region.class";
4-
import { Screen } from "./screen.class";
4+
import { ScreenClass } from "./screen.class";
55

66
jest.mock("./adapter/native.adapter.class");
77
jest.mock("./adapter/vision.adapter.class");
@@ -10,9 +10,9 @@ jest.mock("./screen.class");
1010
describe("Assert", () => {
1111
it("isVisible should not throw if a match is found.", async () => {
1212
// GIVEN
13-
Screen.prototype.find = jest.fn(() => Promise.resolve(new Region(0, 0, 100, 100)));
14-
const screenMock = new Screen(new VisionAdapter());
15-
const SUT = new Assert(screenMock);
13+
ScreenClass.prototype.find = jest.fn(() => Promise.resolve(new Region(0, 0, 100, 100)));
14+
const screenMock = new ScreenClass(new VisionAdapter());
15+
const SUT = new AssertClass(screenMock);
1616
const needle = "foo";
1717

1818
// WHEN
@@ -23,9 +23,9 @@ describe("Assert", () => {
2323

2424
it("isVisible should throw if a match is found.", async () => {
2525
// GIVEN
26-
Screen.prototype.find = jest.fn(() => Promise.reject("foo"));
27-
const screenMock = new Screen(new VisionAdapter());
28-
const SUT = new Assert(screenMock);
26+
ScreenClass.prototype.find = jest.fn(() => Promise.reject("foo"));
27+
const screenMock = new ScreenClass(new VisionAdapter());
28+
const SUT = new AssertClass(screenMock);
2929
const needle = "foo";
3030

3131
// WHEN
@@ -36,9 +36,9 @@ describe("Assert", () => {
3636

3737
it("isVisible should throw if a match is found.", async () => {
3838
// GIVEN
39-
Screen.prototype.find = jest.fn(() => Promise.reject("foo"));
40-
const screenMock = new Screen(new VisionAdapter());
41-
const SUT = new Assert(screenMock);
39+
ScreenClass.prototype.find = jest.fn(() => Promise.reject("foo"));
40+
const screenMock = new ScreenClass(new VisionAdapter());
41+
const SUT = new AssertClass(screenMock);
4242
const searchRegion = new Region(10, 10, 10, 10);
4343
const needle = "foo";
4444

@@ -53,9 +53,9 @@ describe("Assert", () => {
5353

5454
it("isNotVisible should throw if a match is found.", async () => {
5555
// GIVEN
56-
Screen.prototype.find = jest.fn(() => Promise.resolve(new Region(0, 0, 100, 100)));
57-
const screenMock = new Screen(new VisionAdapter());
58-
const SUT = new Assert(screenMock);
56+
ScreenClass.prototype.find = jest.fn(() => Promise.resolve(new Region(0, 0, 100, 100)));
57+
const screenMock = new ScreenClass(new VisionAdapter());
58+
const SUT = new AssertClass(screenMock);
5959
const needle = "foo";
6060

6161
// WHEN
@@ -66,9 +66,9 @@ describe("Assert", () => {
6666

6767
it("isVisible should throw if a match is found.", async () => {
6868
// GIVEN
69-
Screen.prototype.find = jest.fn(() => Promise.reject("foo"));
70-
const screenMock = new Screen(new VisionAdapter());
71-
const SUT = new Assert(screenMock);
69+
ScreenClass.prototype.find = jest.fn(() => Promise.reject("foo"));
70+
const screenMock = new ScreenClass(new VisionAdapter());
71+
const SUT = new AssertClass(screenMock);
7272
const needle = "foo";
7373

7474
// WHEN

lib/assert.class.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { LocationParameters } from "./locationparameters.class";
22
import { Region } from "./region.class";
3-
import { Screen } from "./screen.class";
3+
import { ScreenClass } from "./screen.class";
44

5-
export class Assert {
6-
constructor(private screen: Screen) {}
5+
export class AssertClass {
6+
constructor(private screen: ScreenClass) {}
77

88
public async isVisible(pathToNeedle: string, searchRegion?: Region, confidence?: number) {
99
try {

lib/clipboard.class.e2e.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {NativeAdapter} from "./adapter/native.adapter.class";
2-
import {Clipboard} from "./clipboard.class";
2+
import {ClipboardClass} from "./clipboard.class";
33

44
describe("Clipboard class", () => {
55
it("should paste copied input from system clipboard.", async () => {
66
const adapterMock = new NativeAdapter();
7-
const SUT = new Clipboard(adapterMock);
7+
const SUT = new ClipboardClass(adapterMock);
88

99
const textToCopy = "bar";
1010

lib/clipboard.class.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {NativeAdapter} from "./adapter/native.adapter.class";
2-
import {Clipboard} from "./clipboard.class";
2+
import {ClipboardClass} from "./clipboard.class";
33

44
jest.mock("./adapter/native.adapter.class");
55

@@ -10,7 +10,7 @@ beforeEach(() => {
1010
describe("Clipboard class", () => {
1111
it("should call the native adapters copy method.", () => {
1212
const adapterMock = new NativeAdapter();
13-
const SUT = new Clipboard(adapterMock);
13+
const SUT = new ClipboardClass(adapterMock);
1414

1515
const textToCopy = "bar";
1616

@@ -21,7 +21,7 @@ describe("Clipboard class", () => {
2121

2222
it("should call the native adapters paste method.", () => {
2323
const adapterMock = new NativeAdapter();
24-
const SUT = new Clipboard(adapterMock);
24+
const SUT = new ClipboardClass(adapterMock);
2525

2626
SUT.paste();
2727
expect(adapterMock.paste).toHaveBeenCalledTimes(1);

lib/clipboard.class.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { NativeAdapter } from "./adapter/native.adapter.class";
22

33
/**
4-
* {@link Clipboard} class gives access to a systems clipboard
4+
* {@link ClipboardClass} class gives access to a systems clipboard
55
*/
6-
export class Clipboard {
6+
export class ClipboardClass {
77
/**
8-
* {@link Clipboard} class constructor
8+
* {@link ClipboardClass} class constructor
99
* @param nativeAdapter {@link NativeAdapter} instance used to access OS API
1010
*/
1111
constructor(private nativeAdapter: NativeAdapter) {

lib/expect/matchers/toBeAt.function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Mouse } from "../../mouse.class";
1+
import { MouseClass } from "../../mouse.class";
22
import { Point } from "../../point.class";
33

4-
export const toBeAt = async (received: Mouse, position: Point) => {
4+
export const toBeAt = async (received: MouseClass, position: Point) => {
55
const currentPosition = await received.getPosition();
66

77
const success =

lib/expect/matchers/toBeIn.function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Mouse } from "../../mouse.class";
1+
import { MouseClass } from "../../mouse.class";
22
import { Region } from "../../region.class";
33

4-
export const toBeIn = async (received: Mouse, region: Region) => {
4+
export const toBeIn = async (received: MouseClass, region: Region) => {
55
const currentPosition = await received.getPosition();
66

77
const inX =

lib/expect/matchers/toShow.function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { LocationParameters } from "../../locationparameters.class";
2-
import { Screen } from "../../screen.class";
2+
import { ScreenClass } from "../../screen.class";
33

44
export const toShow = async (
5-
received: Screen,
5+
received: ScreenClass,
66
needle: string,
77
confidence?: number,
88
) => {

lib/keyboard.class.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NativeAdapter } from "./adapter/native.adapter.class";
22
import { Key } from "./key.enum";
3-
import { Keyboard } from "./keyboard.class";
3+
import { KeyboardClass } from "./keyboard.class";
44

55
jest.mock("./adapter/native.adapter.class");
66
jest.setTimeout(10000);
@@ -13,7 +13,7 @@ describe("Keyboard", () => {
1313
it("should have a default delay of 300 ms", () => {
1414
// GIVEN
1515
const adapterMock = new NativeAdapter();
16-
const SUT = new Keyboard(adapterMock);
16+
const SUT = new KeyboardClass(adapterMock);
1717

1818
// WHEN
1919

@@ -24,7 +24,7 @@ describe("Keyboard", () => {
2424
it("should pass input strings down to the type call.", async () => {
2525
// GIVEN
2626
const adapterMock = new NativeAdapter();
27-
const SUT = new Keyboard(adapterMock);
27+
const SUT = new KeyboardClass(adapterMock);
2828
const payload = "Test input!";
2929

3030
// WHEN
@@ -40,7 +40,7 @@ describe("Keyboard", () => {
4040
it("should pass multiple input strings down to the type call.", async () => {
4141
// GIVEN
4242
const adapterMock = new NativeAdapter();
43-
const SUT = new Keyboard(adapterMock);
43+
const SUT = new KeyboardClass(adapterMock);
4444
const payload = ["Test input!", "Array test2"];
4545

4646
// WHEN
@@ -56,7 +56,7 @@ describe("Keyboard", () => {
5656
it("should pass input keys down to the click call.", async () => {
5757
// GIVEN
5858
const adapterMock = new NativeAdapter();
59-
const SUT = new Keyboard(adapterMock);
59+
const SUT = new KeyboardClass(adapterMock);
6060
const payload = [Key.A, Key.S, Key.D, Key.F];
6161

6262
// WHEN
@@ -70,7 +70,7 @@ describe("Keyboard", () => {
7070
it("should pass a list of input keys down to the click call.", async () => {
7171
// GIVEN
7272
const adapterMock = new NativeAdapter();
73-
const SUT = new Keyboard(adapterMock);
73+
const SUT = new KeyboardClass(adapterMock);
7474
const payload = [Key.A, Key.S, Key.D, Key.F];
7575

7676
// WHEN
@@ -85,7 +85,7 @@ describe("Keyboard", () => {
8585
it("should pass a list of input keys down to the pressKey call.", async () => {
8686
// GIVEN
8787
const adapterMock = new NativeAdapter();
88-
const SUT = new Keyboard(adapterMock);
88+
const SUT = new KeyboardClass(adapterMock);
8989
const payload = [Key.A, Key.S, Key.D, Key.F];
9090

9191
// WHEN
@@ -100,7 +100,7 @@ describe("Keyboard", () => {
100100
it("should pass a list of input keys down to the releaseKey call.", async () => {
101101
// GIVEN
102102
const adapterMock = new NativeAdapter();
103-
const SUT = new Keyboard(adapterMock);
103+
const SUT = new KeyboardClass(adapterMock);
104104
const payload = [Key.A, Key.S, Key.D, Key.F];
105105

106106
// WHEN

lib/keyboard.class.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const inputIsString = (input: (string | Key)[]): input is string[] => {
99
};
1010

1111
/**
12-
* {@link Keyboard} class provides methods to emulate keyboard input
12+
* {@link KeyboardClass} class provides methods to emulate keyboard input
1313
*/
14-
export class Keyboard {
14+
export class KeyboardClass {
1515

1616
/**
17-
* Config object for {@link Keyboard} class
17+
* Config object for {@link KeyboardClass} class
1818
*/
1919
public config = {
2020
/**
@@ -24,7 +24,7 @@ export class Keyboard {
2424
};
2525

2626
/**
27-
* {@link Keyboard} class constructor
27+
* {@link KeyboardClass} class constructor
2828
* @param nativeAdapter {@link NativeAdapter} instance which bundles access to mouse, keyboard and clipboard
2929
*/
3030
constructor(private nativeAdapter: NativeAdapter) {
@@ -41,8 +41,8 @@ export class Keyboard {
4141
*
4242
* @param input Sequence of {@link String} or {@link Key} to type
4343
*/
44-
public type(...input: StringOrKey): Promise<Keyboard> {
45-
return new Promise<Keyboard>(async (resolve, reject) => {
44+
public type(...input: StringOrKey): Promise<KeyboardClass> {
45+
return new Promise<KeyboardClass>(async (resolve, reject) => {
4646
try {
4747
if (inputIsString(input)) {
4848
for (const char of input.join(" ").split("")) {
@@ -70,8 +70,8 @@ export class Keyboard {
7070
*
7171
* @param keys Array of {@link Key}s to press and hold
7272
*/
73-
public pressKey(...keys: Key[]): Promise<Keyboard> {
74-
return new Promise<Keyboard>(async (resolve, reject) => {
73+
public pressKey(...keys: Key[]): Promise<KeyboardClass> {
74+
return new Promise<KeyboardClass>(async (resolve, reject) => {
7575
try {
7676
await this.nativeAdapter.pressKey(...keys);
7777
resolve(this);
@@ -92,8 +92,8 @@ export class Keyboard {
9292
*
9393
* @param keys Array of {@link Key}s to release
9494
*/
95-
public releaseKey(...keys: Key[]): Promise<Keyboard> {
96-
return new Promise<Keyboard>(async (resolve, reject) => {
95+
public releaseKey(...keys: Key[]): Promise<KeyboardClass> {
96+
return new Promise<KeyboardClass>(async (resolve, reject) => {
9797
try {
9898
await this.nativeAdapter.releaseKey(...keys);
9999
resolve(this);

0 commit comments

Comments
 (0)