返回 DeepSeek-Reasonix
windowBounds.test.ts
根目录 / desktop / electron / src / main / windowBounds.test.ts
1 import assert from "node:assert/strict";
2 import test from "node:test";
3 import { persistedWindowRect, restoreWindowRect, type WindowRect } from "./windowBounds.js";
4
5 const NORMAL: WindowRect = { x: 40, y: 50, width: 1240, height: 720 };
6 const FRAME: WindowRect = { x: -7, y: -7, width: 1722, height: 1034 };
7
8 function fakeWindow(state: { maximized?: boolean; minimized?: boolean; fullscreen?: boolean }) {
9 return {
10 isMaximized: () => state.maximized ?? false,
11 isMinimized: () => state.minimized ?? false,
12 isFullScreen: () => state.fullscreen ?? false,
13 getBounds: () => FRAME,
14 getNormalBounds: () => state.maximized || state.minimized || state.fullscreen ? NORMAL : FRAME,
15 };
16 }
17
18 test("normal windows persist their live bounds", () => {
19 assert.deepEqual(persistedWindowRect(fakeWindow({})), FRAME);
20 });
21
22 const SIZE = { width: 1100, height: 700, minWidth: 760, minHeight: 480 };
23 const PRIMARY = { x: 0, y: 0, width: 1707, height: 1019 };
24
25 test("valid custom restore geometry survives a maximized relaunch", () => {
26 assert.deepEqual(restoreWindowRect(SIZE, { x: 40, y: 50 }, PRIMARY), { x: 40, y: 50, width: 1100, height: 700 });
27 });
28
29 test("legacy oversized maximized frame is fitted to the work area", () => {
30 assert.deepEqual(restoreWindowRect({ ...SIZE, ...FRAME }, FRAME, PRIMARY), PRIMARY);
31 });
32
33 test("negative monitor origins and taskbar offsets remain valid DIP coordinates", () => {
34 const area = { x: -1920, y: -1080, width: 1920, height: 1040 };
35 assert.deepEqual(restoreWindowRect(SIZE, { x: -1800, y: -1000 }, area), { x: -1800, y: -1000, width: 1100, height: 700 });
36 });
37
38 test("unplugged display recenters without discarding a usable size", () => {
39 assert.deepEqual(restoreWindowRect(SIZE, { x: -1800, y: -1000 }, PRIMARY), { x: 303, y: 159, width: 1100, height: 700 });
40 });
41
42 test("missing state centers defaults and small work areas bound even the minimum", () => {
43 assert.deepEqual(restoreWindowRect(SIZE, undefined, PRIMARY), { x: 303, y: 159, width: 1100, height: 700 });
44 const small = { x: 0, y: 40, width: 640, height: 400 };
45 assert.deepEqual(restoreWindowRect(SIZE, undefined, small), small);
46 });
47
48 test("changed work area relocates only the overflowing edges", () => {
49 assert.deepEqual(restoreWindowRect(SIZE, { x: 1000, y: 600 }, PRIMARY), { x: 607, y: 319, width: 1100, height: 700 });
50 });
51
52 test("maximized windows persist the restore rectangle, not the maximized frame", () => {
53 assert.deepEqual(persistedWindowRect(fakeWindow({ maximized: true })), NORMAL);
54 });
55
56 test("minimized windows persist the restore rectangle, not the iconic position", () => {
57 assert.deepEqual(persistedWindowRect(fakeWindow({ minimized: true })), NORMAL);
58 });
59
60 test("fullscreen windows persist the restore rectangle", () => {
61 assert.deepEqual(persistedWindowRect(fakeWindow({ fullscreen: true })), NORMAL);
62 });
63
63 lines TYPESCRIPT