Skip to content

Commit

Permalink
Merge pull request #42 from nut-tree/develop
Browse files Browse the repository at this point in the history
release v0.1.0-beta.0
  • Loading branch information
s1hofmann authored Mar 7, 2019
2 parents 7f75cdf + 65215d4 commit 6902b01
Show file tree
Hide file tree
Showing 55 changed files with 2,612 additions and 2,657 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ node_js:
- "lts/dubnium"
cache: npm

notifications:
webhooks: https://outlook.office.com/webhook/b6e4942d-6066-4001-8ba1-428598f3ae13@eb86a0ab-5bd0-4070-b04f-b7bf90ca02c5/TravisCI/ad6b89add60a4d4c8d1a06aa4ee424e8/d6c06c79-667d-43b9-92b6-0e9687d93d0f

addons:
sonarcloud:
organization: "nut-tree"
Expand Down
Binary file removed demo/assets/docker.png
Binary file not shown.
Binary file removed demo/assets/gitlens.png
Binary file not shown.
9 changes: 0 additions & 9 deletions demo/clipboard.js

This file was deleted.

31 changes: 0 additions & 31 deletions demo/mouse.js

This file was deleted.

Binary file added e2e/assets/calculator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/mouse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/xfce-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/assets/zero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions index.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { assert, Key, keyboard, Location, mouse, movement, screen } from "./index";

const openXfceMenu = async () => {
const menu = await screen.find("menu.png");
await mouse.move(await movement.straightTo(Location.centerOf(menu)));
await mouse.leftClick();
await mouse.leftClick();
};

const run = async (cmd: string) => {
await keyboard.type(Key.LeftAlt, Key.F2);
await keyboard.type(cmd);
await keyboard.type(Key.Enter);
};

const calculate = async () => {
const plus = await screen.find("plus.png");
await mouse.move(await movement.straightTo(Location.centerOf(plus)));
await mouse.leftClick();
const one = await screen.find("one.png");
await mouse.move(await movement.straightTo(Location.centerOf(one)));
await mouse.leftClick();
const zero = await screen.find("zero.png");
await mouse.move(await movement.straightTo(Location.centerOf(zero)));
await mouse.leftClick();
await mouse.leftClick();
await keyboard.type(Key.Enter);
};

const close = async () => {
const x = await screen.find("close.png");
await mouse.move(await movement.straightTo(Location.centerOf(x)));
await mouse.leftClick();
};

describe("E2E demo", () => {
it("should run without throwing", async () => {
jest.setTimeout(30000);
screen.config.resourceDirectory = "./e2e/assets";
await assert.isVisible("mouse.png");
await assert.isVisible("desktop.png");
await openXfceMenu();
await run("gnome-calculator");
await assert.isVisible("calculator.png");
await keyboard.type("525");
await calculate();
await assert.isVisible("result.png");
await close();
});
});
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const clipboard = new Clipboard(nativeActions);
const keyboard = new Keyboard(nativeActions);
const mouse = new Mouse(nativeActions);
const movement = new Movement(nativeActions, new LineHelper());
const screen = new Screen(screenActions, nativeActions);
const screen = new Screen(screenActions);
const assert = new Assert(screen);

export { clipboard, keyboard, mouse, movement, screen, assert };
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
roots: ["lib"],
collectCoverageFrom: [
"index.ts",
"lib/**/*.ts",
"!lib/**/*.spec.ts",
"!<rootDir>/node_modules/",
"!<rootDir>/path/to/dir/"
],
testPathIgnorePatterns: [
"/node_modules/",
"/dist/"
],
testMatch: process.env.E2E_TEST ?
[ "**/__tests__/?(e2e)/**/*.[jt]s?(x)", "**/?(*.)?(e2e.)+(spec|test).[jt]s?(x)" ] :
[ "**/__tests__/!(e2e)/**/*.[jt]s?(x)", "**/!(*.e2e.*)+(spec|test).[jt]s?(x)" ]
Expand Down
124 changes: 15 additions & 109 deletions lib/adapter/native.adapter.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,19 @@ import { Point } from "../point.class";
import { ClipboardAction } from "../provider/native/clipboardy-clipboard-action.class";
import { KeyboardAction } from "../provider/native/robotjs-keyboard-action.class";
import { MouseAction } from "../provider/native/robotjs-mouse-action.class";
import { ScreenAction } from "../provider/native/robotjs-screen-action.class";
import { Region } from "../region.class";
import { NativeAdapter } from "./native.adapter.class";

jest.mock("../provider/native/clipboardy-clipboard-action.class");
jest.mock("../provider/native/robotjs-mouse-action.class");
jest.mock("../provider/native/robotjs-keyboard-action.class");
jest.mock("../provider/native/robotjs-screen-action.class");

describe("Native adapter class", () => {
it("should delegate calls to grabScreen", () => {
// GIVEN
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);

// WHEN
SUT.grabScreen();

// THEN
expect(screenMock.grabScreen).toBeCalledTimes(1);
});

it("should delegate calls to grabScreenRegion", () => {
// GIVEN
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const screenRegion = new Region(0, 0, 100, 100);

// WHEN
SUT.grabScreenRegion(screenRegion);

// THEN
expect(screenMock.grabScreenRegion).toBeCalledTimes(1);
expect(screenMock.grabScreenRegion).toBeCalledWith(screenRegion);
});

describe("NativeAdapter class", () => {
it("should delegate calls to setMouseDelay", () => {
// GIVEN
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const delay = 5;

// WHEN
Expand All @@ -68,8 +32,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const newPosition = new Point(10, 10);

// WHEN
Expand All @@ -85,8 +48,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);

// WHEN
SUT.currentMousePosition();
Expand All @@ -95,58 +57,12 @@ describe("Native adapter class", () => {
expect(mouseMock.currentMousePosition).toBeCalledTimes(1);
});

it("should delegate calls to screenWidth", () => {
// GIVEN
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);

// WHEN
SUT.screenWidth();

// THEN
expect(screenMock.screenWidth).toBeCalledTimes(1);
});

it("should delegate calls to screenHeight", () => {
// GIVEN
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);

// WHEN
SUT.screenHeight();

// THEN
expect(screenMock.screenHeight).toBeCalledTimes(1);
});

it("should delegate calls to screenSize", () => {
// GIVEN
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);

// WHEN
SUT.screenSize();

// THEN
expect(screenMock.screenSize).toBeCalledTimes(1);
});

it("should delegate calls to leftClick", () => {
// GIVEN
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);

// WHEN
SUT.leftClick();
Expand All @@ -160,8 +76,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);

// WHEN
SUT.rightClick();
Expand All @@ -175,8 +90,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);

// WHEN
SUT.middleClick();
Expand All @@ -190,8 +104,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const buttonToPress = Button.LEFT;

// WHEN
Expand All @@ -207,8 +120,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const buttonToRelease = Button.LEFT;

// WHEN
Expand All @@ -224,8 +136,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const keyToPress = Key.A;

// WHEN
Expand All @@ -241,8 +152,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const keyToRelease = Key.A;

// WHEN
Expand All @@ -258,8 +168,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const keyToClick = Key.A;

// WHEN
Expand All @@ -275,8 +184,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const stringToType = "testString";

// WHEN
Expand All @@ -292,8 +200,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);
const stringToCopy = "testString";

// WHEN
Expand All @@ -309,8 +216,7 @@ describe("Native adapter class", () => {
const clipboardMock = new ClipboardAction();
const keyboardMock = new KeyboardAction();
const mouseMock = new MouseAction();
const screenMock = new ScreenAction();
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock, screenMock);
const SUT = new NativeAdapter(clipboardMock, keyboardMock, mouseMock);

// WHEN
SUT.paste();
Expand Down
Loading

0 comments on commit 6902b01

Please sign in to comment.