Skip to content

Commit

Permalink
(#559) Moved window e2e test into dedicated e2e subpackage
Browse files Browse the repository at this point in the history
  • Loading branch information
s1hofmann committed Feb 16, 2024
1 parent 5155b9f commit 65485cd
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const POS_X = 50;
const POS_Y = 100;
const WIDTH = 400;
const HEIGTH = 300;
const HEIGHT = 300;
const TITLE = "libnut window test";

module.exports = {
POS_X,
POS_Y,
WIDTH,
HEIGTH,
HEIGHT,
TITLE,
};
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/window-test/main.js → e2e/window-test/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { app, ipcMain, BrowserWindow } = require("electron");
const path = require("path");
const { POS_X, POS_Y, WIDTH, HEIGTH } = require("./constants");
const { POS_X, POS_Y, WIDTH, HEIGHT } = require("./constants");

function createWindow() {
const mainWindow = new BrowserWindow({
width: WIDTH,
height: HEIGTH,
height: HEIGHT,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
},
"scripts": {
"pretest": "pnpx playwright install --with-deps",
"test": "jest"
"test": "jest",
"coverage": "jest --coverage --runInBand --logHeapUsage",
"coverage:clean": "rimraf coverage"
},
"devDependencies": {
"@nut-tree/nut-js": "workspace:*",
"@playwright/test": "1.41.2",
"electron": "28.2.3",
"electron": "28.0.0",
"jest": "29.7.0",
"jest-playwright-preset": "4.0.0",
"playwright": "1.41.2"
Expand Down
File renamed without changes.
File renamed without changes.
40 changes: 37 additions & 3 deletions examples/window-test/test.spec.js → e2e/window-test/test.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { _electron: electron } = require("playwright");
const { sleep, getActiveWindow, getWindows } = require("@nut-tree/nut-js");
const { POS_X, POS_Y, WIDTH, HEIGTH, TITLE } = require("./constants");
const { sleep, getActiveWindow, screen, getWindows } = require("@nut-tree/nut-js");
const { POS_X, POS_Y, WIDTH, HEIGHT, TITLE } = require("./constants");

let app;
let page;
Expand Down Expand Up @@ -57,7 +57,7 @@ describe("getActiveWindow", () => {
expect(activeWindowRegion.left).toBe(POS_X);
expect(activeWindowRegion.top).toBe(POS_Y);
expect(activeWindowRegion.width).toBe(WIDTH);
expect(activeWindowRegion.height).toBe(HEIGTH);
expect(activeWindowRegion.height).toBe(HEIGHT);
});

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

describe("window regions", () => {
it("should crop window coordinates on main screen boundaries to the left", async () => {
// GIVEN
const newLeft = -40;

// WHEN
const foregroundWindow = await getActiveWindow();
await foregroundWindow.move({ x: newLeft, y: POS_Y });
await sleep(1000);
const activeWindowRegion = await foregroundWindow.region;

// THEN
expect(activeWindowRegion.left).toBe(0);
expect(activeWindowRegion.width).toBe(WIDTH + newLeft);
});

it("should crop window coordinates on main screen boundaries to the right", async () => {
// GIVEN
const screenWidth = await screen.width();
const delta = 40;
const newLeft = screenWidth - delta;

// WHEN
const foregroundWindow = await getActiveWindow();
await foregroundWindow.move({ x: newLeft, y: POS_Y });
await sleep(1000);
const activeWindowRegion = await foregroundWindow.region;

// THEN
expect(activeWindowRegion.left).toBe(newLeft);
expect(activeWindowRegion.width).toBe(delta);
});
});

afterEach(async () => {
if (app) {
await app.close();
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"workspaces": [
"core/*",
"providers/*",
"examples/*"
"examples/*",
"e2e/*"
],
"dependencies": {},
"devDependencies": {
Expand Down
46 changes: 23 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ packages:
- 'core/*'
- 'providers/*'
- 'examples/*'
- 'e2e/*'

0 comments on commit 65485cd

Please sign in to comment.