tests: add user resize tests
This commit is contained in:
72
src/tests/flows/userResize.ts
Normal file
72
src/tests/flows/userResize.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
tests.register("User resize", 1, () => {
|
||||
const config = getDefaultConfig();
|
||||
config.resizeNeighborColumn = true;
|
||||
|
||||
const h = getWindowHeight(2);
|
||||
let clientLeft: MockKwinClient, clientRightTop: MockKwinClient, clientRightBottom: MockKwinClient;
|
||||
function assertSizes(leftWidth: number, rightWidth: number, topHeight: number, bottomHeight: number) {
|
||||
const { left, right } = getGridBounds(clientLeft, clientRightTop);
|
||||
Assert.rect(clientLeft.frameGeometry, left, tilingArea.top, leftWidth, tilingArea.height);
|
||||
Assert.rect(clientRightTop.frameGeometry, left+leftWidth+gapH, tilingArea.top, rightWidth, topHeight);
|
||||
Assert.rect(clientRightBottom.frameGeometry, left+leftWidth+gapH, tilingArea.top+topHeight+gapV, rightWidth, bottomHeight);
|
||||
}
|
||||
|
||||
{
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
[clientLeft, clientRightTop, clientRightBottom] = workspaceMock.createClientsWithWidths(300, 300, 200);
|
||||
qtMock.fireShortcut("karousel-window-move-left");
|
||||
assertSizes(300, 300, h, h);
|
||||
|
||||
workspaceMock.resizeWindow(clientLeft, 10, 20, false, false, false);
|
||||
assertSizes(310, 300, h, h);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightTop, -10, -20, false, false, false);
|
||||
assertSizes(310, 290, h-20, h+20);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightBottom, -10, 20, false, false, false);
|
||||
assertSizes(310, 280, h-20, h+20);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightBottom, 0, 20, false, true, false);
|
||||
assertSizes(310, 280, h-40, h+40);
|
||||
}
|
||||
|
||||
{
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
[clientLeft, clientRightTop, clientRightBottom] = workspaceMock.createClientsWithWidths(300, 300, 200);
|
||||
qtMock.fireShortcut("karousel-window-move-left");
|
||||
assertSizes(300, 300, h, h);
|
||||
|
||||
workspaceMock.resizeWindow(clientLeft, 10, 20, false, false, true);
|
||||
assertSizes(310, 290, h, h);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightTop, -10, -20, false, false, true);
|
||||
assertSizes(310, 280, h-20, h+20);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightBottom, -10, 20, true, false, true);
|
||||
assertSizes(320, 270, h-20, h+20);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightBottom, 0, 20, false, true, true);
|
||||
assertSizes(320, 270, h-40, h+40);
|
||||
}
|
||||
|
||||
{
|
||||
const { qtMock, workspaceMock, world } = init(config);
|
||||
[clientLeft, clientRightTop, clientRightBottom] = workspaceMock.createClientsWithWidths(300, 300, 200);
|
||||
clientRightBottom.minSize = new MockQmlSize(295, h-20);
|
||||
qtMock.fireShortcut("karousel-window-move-left");
|
||||
assertSizes(300, 300, h, h);
|
||||
|
||||
workspaceMock.resizeWindow(clientLeft, 10, 20, false, false, true);
|
||||
assertSizes(310, 295, h, h);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightTop, -10, -20, false, false, true);
|
||||
assertSizes(310, 295, h-20, h+20);
|
||||
|
||||
workspaceMock.resizeWindow(clientRightBottom, -10, 20, true, false, true);
|
||||
assertSizes(320, 295, h-20, h+20);
|
||||
|
||||
// TODO
|
||||
// workspaceMock.resizeWindow(clientRightBottom, 0, -80, false, true, true);
|
||||
// assertSizes(320, 295, h+60, h-20);
|
||||
}
|
||||
});
|
||||
@@ -32,3 +32,15 @@ function init(config: Config) {
|
||||
const world = new World(config);
|
||||
return { qtMock, workspaceMock, world };
|
||||
}
|
||||
|
||||
function getGridBounds(clientLeft: KwinClient, clientRight: KwinClient) {
|
||||
const columnsWidth = clientRight.frameGeometry.right - clientLeft.frameGeometry.left;
|
||||
const left = Math.floor((screen.width - columnsWidth) / 2);
|
||||
const right = left + columnsWidth;
|
||||
return { left, right };
|
||||
}
|
||||
|
||||
function getWindowHeight(windowsInColumn: number) {
|
||||
const totalGaps = (windowsInColumn-1) * gapV;
|
||||
return Math.round((tilingArea.height - totalGaps) / windowsInColumn);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class MockKwinClient {
|
||||
public minSize: Readonly<QmlSize> = new MockQmlSize(0, 0);
|
||||
public readonly transient: boolean;
|
||||
public readonly move: boolean = false;
|
||||
public readonly resize: boolean = false;
|
||||
public resize: boolean = false;
|
||||
public readonly moveable: boolean = true;
|
||||
public readonly resizeable: boolean = true;
|
||||
public readonly fullScreenable: boolean = true;
|
||||
@@ -185,4 +185,8 @@ class MockKwinClient {
|
||||
public unpin() {
|
||||
this.tile = null;
|
||||
}
|
||||
|
||||
public getFrameGeometryCopy() {
|
||||
return this._frameGeometry.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,40 @@ class MockWorkspace {
|
||||
return this.createClientsWithFrames(...widths.map(width => new MockQmlRect(randomInt(100), randomInt(100), width, 100+randomInt(400))));
|
||||
}
|
||||
|
||||
public resizeWindow(window: MockKwinClient, widthDelta: number, heightDelta: number, leftEdge: boolean, topEdge: boolean, edgeResize: boolean) {
|
||||
const frame = window.getFrameGeometryCopy();
|
||||
if (edgeResize) {
|
||||
this.cursorPos = new MockQmlPoint(
|
||||
leftEdge ? frame.left : frame.right,
|
||||
topEdge ? frame.top : frame.bottom,
|
||||
);
|
||||
} else {
|
||||
this.cursorPos = new MockQmlPoint(
|
||||
Math.round(frame.x + frame.width/2),
|
||||
Math.round(frame.y + frame.height/2),
|
||||
);
|
||||
}
|
||||
window.resize = true;
|
||||
window.interactiveMoveResizeStarted.fire();
|
||||
|
||||
if (widthDelta !== 0) {
|
||||
frame.width += widthDelta;
|
||||
if (leftEdge) {
|
||||
frame.x -= widthDelta;
|
||||
}
|
||||
}
|
||||
if (heightDelta !== 0) {
|
||||
frame.height += heightDelta;
|
||||
if (topEdge) {
|
||||
frame.y -= heightDelta;
|
||||
}
|
||||
}
|
||||
window.frameGeometry = frame;
|
||||
|
||||
window.resize = false;
|
||||
window.interactiveMoveResizeFinished.fire();
|
||||
}
|
||||
|
||||
public get activeWindow() {
|
||||
return this._activeWindow;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user