-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtest.js
103 lines (84 loc) · 3 KB
/
test.js
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
100
101
102
103
const Application = require("spectron").Application;
const electronPath = require("electron");
const libnut = require("../..");
const { POS_X, POS_Y, WIDTH, HEIGTH, TITLE } = require("./constants");
const sleep = async (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
};
let app;
const APP_TIMEOUT = 10000;
jest.setTimeout(3 * APP_TIMEOUT)
beforeEach(async () => {
app = new Application({
path: electronPath,
args: ['main.js'],
startTimeout: APP_TIMEOUT,
waitTimeout: APP_TIMEOUT,
});
await app.start();
await app.client.waitUntilWindowLoaded();
await app.browserWindow.minimize();
await app.browserWindow.restore();
await app.browserWindow.focus();
});
describe("getWindows", () => {
it("should list our started application window", () => {
// GIVEN
// WHEN
const windowNames = libnut.getWindows().map(handle => libnut.getWindowTitle(handle));
// THEN
expect(windowNames).toContain(TITLE);
});
});
describe("getActiveWindow", () => {
it("should return our started application window", () => {
// GIVEN
// WHEN
const activeWindowHandle = libnut.getActiveWindow();
const activeWindowName = libnut.getWindowTitle(activeWindowHandle);
// THEN
expect(activeWindowName).toBe(TITLE);
});
it("should determine correct coordinates for our application", () => {
// GIVEN
// WHEN
const activeWindowHandle = libnut.getActiveWindow();
const activeWindowRect = libnut.getWindowRect(activeWindowHandle);
// THEN
expect(activeWindowRect.x).toBe(POS_X);
expect(activeWindowRect.y).toBe(POS_Y);
expect(activeWindowRect.width).toBe(WIDTH);
expect(activeWindowRect.height).toBe(HEIGTH);
});
it("should determine correct coordinates for our application after moving the window", async () => {
// GIVEN
const xPosition = 42;
const yPosition = 25;
await app.browserWindow.setPosition(xPosition, yPosition);
await sleep(1000);
// WHEN
const activeWindowHandle = libnut.getActiveWindow();
const activeWindowRect = libnut.getWindowRect(activeWindowHandle);
// THEN
expect(activeWindowRect.x).toBe(xPosition);
expect(activeWindowRect.y).toBe(yPosition);
});
it("should determine correct window size for our application after resizing the window", async () => {
// GIVEN
const newWidth = 400;
const newHeight = 250;
await app.browserWindow.setSize(newWidth, newHeight);
await sleep(1000);
// WHEN
const activeWindowHandle = libnut.getActiveWindow();
const activeWindowRect = libnut.getWindowRect(activeWindowHandle);
// THEN
expect(activeWindowRect.width).toBe(newWidth);
expect(activeWindowRect.height).toBe(newHeight);
});
});
afterEach(async () => {
if (app && app.isRunning()) {
await app.stop();
}
});