Skip to content

Commit c790569

Browse files
committed
(#17) Added integration test
1 parent d96afeb commit c790569

File tree

7 files changed

+771
-0
lines changed

7 files changed

+771
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
body {
2+
width: 100vw;
3+
height: 100vh;
4+
}
5+
6+
#content {
7+
display: flex;
8+
flex-direction: row;
9+
align-items: center;
10+
justify-content: center;
11+
height: 100vh;
12+
width: 100vw;
13+
}
14+
15+
#exit {
16+
color: white;
17+
font-size: 1.5rem;
18+
background: darkblue;
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
6+
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
7+
<link href="index.css" rel="stylesheet"/>
8+
<title>libnut window test</title>
9+
</head>
10+
<body style="width: 100%; height: 100%">
11+
<div id="content">
12+
<button id="exit">Click me!</button>
13+
</div>
14+
<script src="renderer.js"></script>
15+
</body>
16+
</html>

test/window-integration-tests/main.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const {app, ipcMain, BrowserWindow} = require('electron')
2+
const libnut = require("../..");
3+
const path = require('path');
4+
5+
const POS_X = 50;
6+
const POS_Y = 100;
7+
const WIDTH = 800;
8+
const HEIGTH = 600;
9+
10+
function test(description, assertion) {
11+
console.log(`${description}: ${assertion}`);
12+
if (!assertion) {
13+
process.exit(1);
14+
}
15+
}
16+
17+
function createWindow() {
18+
const mainWindow = new BrowserWindow({
19+
width: WIDTH,
20+
height: HEIGTH,
21+
webPreferences: {
22+
nodeIntegration: true,
23+
preload: path.join(__dirname, 'preload.js')
24+
}
25+
});
26+
mainWindow.loadFile(path.join(__dirname, "index.html"));
27+
mainWindow.setPosition(POS_X, POS_Y);
28+
29+
setTimeout(() => {
30+
const windowNames = libnut.getWindows().map(
31+
handle => libnut.getWindowTitle(handle)
32+
);
33+
test("list windows", windowNames.includes("libnut window test"));
34+
35+
const activeWindow = libnut.getActiveWindow();
36+
const activeWindowRect = libnut.getWindowRect(activeWindow);
37+
const activeWindowTitle = libnut.getWindowTitle(activeWindow);
38+
test("title", activeWindowTitle === "libnut window test");
39+
test("posX", activeWindowRect.x === POS_X);
40+
test("posY", activeWindowRect.y === POS_Y);
41+
test("width", activeWindowRect.width === WIDTH);
42+
test("height", activeWindowRect.height === HEIGTH);
43+
process.exit(0);
44+
}, 5000);
45+
}
46+
47+
ipcMain.on("main", (event, args) => {
48+
if (args === "quit") {
49+
app.quit();
50+
}
51+
});
52+
53+
app.whenReady().then(() => {
54+
setTimeout(() => process.exit(1), 15000);
55+
createWindow()
56+
57+
app.on('activate', function () {
58+
if (BrowserWindow.getAllWindows().length === 0) createWindow()
59+
})
60+
})
61+
62+
app.on('window-all-closed', function () {
63+
console.log("Bye!");
64+
app.quit();
65+
})

0 commit comments

Comments
 (0)