forked from nut-tree/nut.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.e2e.spec.ts
86 lines (75 loc) · 2.45 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
import {
assert,
centerOf,
down,
Key,
keyboard,
mouse,
Region,
right,
screen,
sleep,
straightTo,
} from "./index";
jest.setTimeout(60000);
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 mouse.move(straightTo(centerOf(screen.find("equals.png"))));
await mouse.leftClick();
};
const close = async () => {
await mouse.move(straightTo(centerOf(screen.find("close.png"))));
await mouse.leftClick();
};
describe("E2E tests", () => {
afterEach(async () => {
await keyboard.type(Key.LeftControl, Key.LeftAlt, Key.Left);
});
it("should throw on invalid images", async () => {
await expect(screen.find("mouse.png")).rejects.toContain("Failed to load image");
});
it("should perform some calculations", async () => {
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 screen.waitFor("result.png");
await close();
});
it("drag & drop", async () => {
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.waitFor("moved_trash.png");
expect(Math.abs(dest.left - expected.left)).toBeLessThanOrEqual(maxDiff);
expect(Math.abs(dest.top - expected.top)).toBeLessThanOrEqual(maxDiff);
expect(Math.abs(dest.width - expected.width)).toBeLessThanOrEqual(maxDiff);
expect(Math.abs(dest.height - expected.height)).toBeLessThanOrEqual(maxDiff);
});
});