From 36c7cab137019116005f37f6a9cb35bb7c4b442e Mon Sep 17 00:00:00 2001 From: Peter Fajdiga Date: Fri, 7 Mar 2025 17:22:07 +0100 Subject: [PATCH] tests: add test for dragging a tiled window --- src/tests/flows/dragTiled.ts | 34 +++++++++++++++++++++++++ src/tests/utils/Assert.ts | 22 ++++++++++++++++ src/tests/utils/global.ts | 7 +++++ src/tests/utils/mocks/MockKwinClient.ts | 2 +- src/tests/utils/mocks/MockWorkspace.ts | 24 ++++++++++++++++- 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/tests/flows/dragTiled.ts diff --git a/src/tests/flows/dragTiled.ts b/src/tests/flows/dragTiled.ts new file mode 100644 index 0000000..4072367 --- /dev/null +++ b/src/tests/flows/dragTiled.ts @@ -0,0 +1,34 @@ +tests.register("Drag tiled window, untile", 20, () => { + const config = getDefaultConfig(); + config.untileOnDrag = true; + const { qtMock, workspaceMock, world } = init(config); + const clientManager = getClientManager(world); + + const [client0, client1] = workspaceMock.createClients(2); + Assert.tiledClient(clientManager, client0); + Assert.tiledClient(clientManager, client1); + Assert.grid(config, screen, 100, [[client0], [client1]], true); + + workspaceMock.moveWindow(client0, new MockQmlPoint(10, 10)); + Assert.notTiledClient(clientManager, client0); + Assert.tiledClient(clientManager, client1); + Assert.grid(config, screen, 100, [[client1]], true); +}); + +tests.register("Drag tiled window, keep tiled", 20, () => { + const config = getDefaultConfig(); + config.untileOnDrag = false; + const { qtMock, workspaceMock, world } = init(config); + const clientManager = getClientManager(world); + + const [client0, client1] = workspaceMock.createClients(2); + Assert.tiledClient(clientManager, client0); + Assert.tiledClient(clientManager, client1); + Assert.grid(config, screen, 100, [[client0], [client1]], true); + + const move = new MockQmlPoint(10, 10); + workspaceMock.moveWindow(client0, move, move, move, move, move, move, move, move, move); // many moves in order to trigger externalFrameGeometryChangedRateLimiter + Assert.tiledClient(clientManager, client0); + Assert.tiledClient(clientManager, client1); + Assert.grid(config, screen, 100, [[client0], [client1]], true); +}); diff --git a/src/tests/utils/Assert.ts b/src/tests/utils/Assert.ts index 66ba3d9..08ee41b 100644 --- a/src/tests/utils/Assert.ts +++ b/src/tests/utils/Assert.ts @@ -219,4 +219,26 @@ namespace Assert { } equal(columns[columns.length-1].frameGeometry.right, tilingArea.right, options); } + + export function tiledClient( + clientManager: ClientManager, + client: KwinClient, + { message, skip=0 }: Options = {}, + ) { + assert( + clientManager.findTiledWindow(client) !== null, + { message: message, skip: skip+1 }, + ); + } + + export function notTiledClient( + clientManager: ClientManager, + client: KwinClient, + { message, skip=0 }: Options = {}, + ) { + assert( + clientManager.findTiledWindow(client) === null, + { message: message, skip: skip+1 }, + ); + } } diff --git a/src/tests/utils/global.ts b/src/tests/utils/global.ts index 84e8050..adde8de 100644 --- a/src/tests/utils/global.ts +++ b/src/tests/utils/global.ts @@ -44,3 +44,10 @@ function getWindowHeight(windowsInColumn: number) { const totalGaps = (windowsInColumn-1) * gapV; return Math.round((tilingArea.height - totalGaps) / windowsInColumn); } + +function getClientManager(world: World): ClientManager { + // don't do this outside of tests + let clientManager; + world.do((cm, dm) => clientManager = cm); + return clientManager!; +} diff --git a/src/tests/utils/mocks/MockKwinClient.ts b/src/tests/utils/mocks/MockKwinClient.ts index a59145c..46d02a7 100644 --- a/src/tests/utils/mocks/MockKwinClient.ts +++ b/src/tests/utils/mocks/MockKwinClient.ts @@ -7,7 +7,7 @@ class MockKwinClient { public caption = "App"; public minSize: Readonly = new MockQmlSize(0, 0); public readonly transient: boolean; - public readonly move: boolean = false; + public move: boolean = false; public resize: boolean = false; public readonly fullScreenable: boolean = true; public readonly maximizable: boolean = true; diff --git a/src/tests/utils/mocks/MockWorkspace.ts b/src/tests/utils/mocks/MockWorkspace.ts index 283c7ab..8e4c144 100644 --- a/src/tests/utils/mocks/MockWorkspace.ts +++ b/src/tests/utils/mocks/MockWorkspace.ts @@ -62,6 +62,28 @@ class MockWorkspace { }; } + public moveWindow(window: MockKwinClient, ...deltas: QmlPoint[]) { + const frame = window.getFrameGeometryCopy(); + window.move = true; + window.interactiveMoveResizeStarted.fire(); + + for (const delta of deltas) { + if (delta.x !== 0) { + frame.x += delta.x; + } + if (delta.y !== 0) { + frame.y += delta.y; + } + runOneOf( + () => window.frameGeometry.set(frame), + () => window.frameGeometry = frame, + ); + } + + window.move = false; + window.interactiveMoveResizeFinished.fire(); + } + public resizeWindow(window: MockKwinClient, edgeResize: boolean, leftEdge: boolean, topEdge: boolean, ...deltas: QmlSize[]) { const frame = window.getFrameGeometryCopy(); if (edgeResize) { @@ -94,7 +116,7 @@ class MockWorkspace { runOneOf( () => window.frameGeometry.set(frame), () => window.frameGeometry = frame, - ) + ); } window.resize = false;