forked from nut-tree/nut.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.e2e.spec.ts
99 lines (89 loc) · 2.77 KB
/
index.e2e.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import {
assert,
Button,
centerOf,
down,
Key,
keyboard,
mouse,
Region,
right,
screen,
sleep,
straightTo
} from "./index";
const openXfceMenu = async () => {
await mouse.move(straightTo(centerOf(screen.find("menu.png"))));
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 () => {
await mouse.move(straightTo(centerOf(screen.find("plus.png"))));
await mouse.leftClick();
await mouse.move(straightTo(centerOf(screen.find("one.png"))));
await mouse.leftClick();
await mouse.move(straightTo(centerOf(screen.find("zero.png"))));
await mouse.leftClick();
await mouse.leftClick();
await keyboard.type(Key.Enter);
};
const close = async () => {
await mouse.move(straightTo(centerOf(screen.find("close.png"))));
await mouse.leftClick();
};
describe("E2E screen test", () => {
it("should throw on invalid images", async () => {
jest.setTimeout(30000);
await expect(screen.find("mouse.png")).rejects.toContain("Failed to load image");
});
});
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 sleep(1500);
await assert.isVisible("calculator.png");
await keyboard.type("525");
await calculate();
await assert.isVisible("result.png");
await close();
});
});
describe("E2E drag & drop demo", () => {
it("should run without throwing", async () => {
jest.setTimeout(60000);
screen.config.resourceDirectory = "./e2e/assets";
const expected = new Region(38, 585, 70, 86);
const maxDiff = 1;
await assert.isVisible("trash.png");
await mouse.move(straightTo(centerOf(screen.find("trash.png"))));
await mouse.drag(down(500));
await mouse.move(right(100));
await mouse.leftClick();
const dest = await screen.find("moved_trash.png");
expect(Math.abs(dest.left - expected.left)).toBeLessThan(maxDiff);
expect(Math.abs(dest.top - expected.top)).toBeLessThan(maxDiff);
expect(Math.abs(dest.width - expected.width)).toBeLessThan(maxDiff);
expect(Math.abs(dest.height - expected.height)).toBeLessThan(maxDiff);
});
});
describe("E2E mouse button demo", () => {
it("should run without throwing", async () => {
jest.setTimeout(60000);
screen.config.resourceDirectory = "./e2e/assets";
for (const btn of [Button.RIGHT, Button.MIDDLE, Button.LEFT]) {
await mouse.pressButton(btn);
await sleep(10);
await mouse.releaseButton(btn);
}
});
});