Skip to content

Commit 65485cd

Browse files
committed
(#559) Moved window e2e test into dedicated e2e subpackage
1 parent 5155b9f commit 65485cd

11 files changed

+71
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const POS_X = 50;
22
const POS_Y = 100;
33
const WIDTH = 400;
4-
const HEIGTH = 300;
4+
const HEIGHT = 300;
55
const TITLE = "libnut window test";
66

77
module.exports = {
88
POS_X,
99
POS_Y,
1010
WIDTH,
11-
HEIGTH,
11+
HEIGHT,
1212
TITLE,
1313
};
File renamed without changes.
File renamed without changes.

Diff for: examples/window-test/main.js renamed to e2e/window-test/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const { app, ipcMain, BrowserWindow } = require("electron");
22
const path = require("path");
3-
const { POS_X, POS_Y, WIDTH, HEIGTH } = require("./constants");
3+
const { POS_X, POS_Y, WIDTH, HEIGHT } = require("./constants");
44

55
function createWindow() {
66
const mainWindow = new BrowserWindow({
77
width: WIDTH,
8-
height: HEIGTH,
8+
height: HEIGHT,
99
alwaysOnTop: true,
1010
webPreferences: {
1111
nodeIntegration: true,

Diff for: examples/window-test/package.json renamed to e2e/window-test/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
},
1212
"scripts": {
1313
"pretest": "pnpx playwright install --with-deps",
14-
"test": "jest"
14+
"test": "jest",
15+
"coverage": "jest --coverage --runInBand --logHeapUsage",
16+
"coverage:clean": "rimraf coverage"
1517
},
1618
"devDependencies": {
1719
"@nut-tree/nut-js": "workspace:*",
1820
"@playwright/test": "1.41.2",
19-
"electron": "28.2.3",
21+
"electron": "28.0.0",
2022
"jest": "29.7.0",
2123
"jest-playwright-preset": "4.0.0",
2224
"playwright": "1.41.2"
File renamed without changes.
File renamed without changes.

Diff for: examples/window-test/test.spec.js renamed to e2e/window-test/test.spec.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { _electron: electron } = require("playwright");
2-
const { sleep, getActiveWindow, getWindows } = require("@nut-tree/nut-js");
3-
const { POS_X, POS_Y, WIDTH, HEIGTH, TITLE } = require("./constants");
2+
const { sleep, getActiveWindow, screen, getWindows } = require("@nut-tree/nut-js");
3+
const { POS_X, POS_Y, WIDTH, HEIGHT, TITLE } = require("./constants");
44

55
let app;
66
let page;
@@ -57,7 +57,7 @@ describe("getActiveWindow", () => {
5757
expect(activeWindowRegion.left).toBe(POS_X);
5858
expect(activeWindowRegion.top).toBe(POS_Y);
5959
expect(activeWindowRegion.width).toBe(WIDTH);
60-
expect(activeWindowRegion.height).toBe(HEIGTH);
60+
expect(activeWindowRegion.height).toBe(HEIGHT);
6161
});
6262

6363
it("should determine correct coordinates for our application after moving the window", async () => {
@@ -93,6 +93,40 @@ describe("getActiveWindow", () => {
9393
});
9494
});
9595

96+
describe("window regions", () => {
97+
it("should crop window coordinates on main screen boundaries to the left", async () => {
98+
// GIVEN
99+
const newLeft = -40;
100+
101+
// WHEN
102+
const foregroundWindow = await getActiveWindow();
103+
await foregroundWindow.move({ x: newLeft, y: POS_Y });
104+
await sleep(1000);
105+
const activeWindowRegion = await foregroundWindow.region;
106+
107+
// THEN
108+
expect(activeWindowRegion.left).toBe(0);
109+
expect(activeWindowRegion.width).toBe(WIDTH + newLeft);
110+
});
111+
112+
it("should crop window coordinates on main screen boundaries to the right", async () => {
113+
// GIVEN
114+
const screenWidth = await screen.width();
115+
const delta = 40;
116+
const newLeft = screenWidth - delta;
117+
118+
// WHEN
119+
const foregroundWindow = await getActiveWindow();
120+
await foregroundWindow.move({ x: newLeft, y: POS_Y });
121+
await sleep(1000);
122+
const activeWindowRegion = await foregroundWindow.region;
123+
124+
// THEN
125+
expect(activeWindowRegion.left).toBe(newLeft);
126+
expect(activeWindowRegion.width).toBe(delta);
127+
});
128+
});
129+
96130
afterEach(async () => {
97131
if (app) {
98132
await app.close();

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"workspaces": [
1616
"core/*",
1717
"providers/*",
18-
"examples/*"
18+
"examples/*",
19+
"e2e/*"
1920
],
2021
"dependencies": {},
2122
"devDependencies": {

Diff for: pnpm-lock.yaml

+23-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pnpm-workspace.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ packages:
22
- 'core/*'
33
- 'providers/*'
44
- 'examples/*'
5+
- 'e2e/*'

0 commit comments

Comments
 (0)