tests: extract assertGrid
This commit is contained in:
@@ -34,107 +34,87 @@ tests.register("Focus and move windows", 1, () => {
|
||||
});
|
||||
assert(workspaceMock.activeWindow === client3);
|
||||
|
||||
function getRectInGrid(column: number, window: number, nColumns: number, nWindows: number) {
|
||||
const columnHeight = screenHeight - config.gapsOuterTop - config.gapsOuterBottom;
|
||||
const columnsWidth = nColumns * 100 + (nColumns-1) * config.gapsInnerHorizontal;
|
||||
const windowHeight = (columnHeight - config.gapsInnerVertical * (nWindows-1)) / nWindows;
|
||||
return new MockQmlRect(
|
||||
column * (100 + config.gapsInnerHorizontal) + (screenWidth-columnsWidth) / 2,
|
||||
config.gapsOuterTop + (windowHeight + config.gapsInnerVertical) * window,
|
||||
100,
|
||||
(columnHeight - config.gapsInnerVertical * (nWindows-1)) / nWindows,
|
||||
);
|
||||
}
|
||||
|
||||
function assertGrid(shortcutName: string, grid: KwinClient[][]) {
|
||||
function testLayout(shortcutName: string, grid: KwinClient[][]) {
|
||||
qtMock.fireShortcut(shortcutName);
|
||||
|
||||
const nColumns = grid.length;
|
||||
for (let iColumn = 0; iColumn < nColumns; iColumn++) {
|
||||
const column = grid[iColumn];
|
||||
const nWindows = column.length;
|
||||
for (let iWindow = 0; iWindow < nWindows; iWindow++) {
|
||||
const window = column[iWindow];
|
||||
assertRectEqual(window.frameGeometry, getRectInGrid(iColumn, iWindow, nColumns, nWindows), 1);
|
||||
}
|
||||
}
|
||||
const screen = new MockQmlRect(0, 0, screenWidth, screenHeight);
|
||||
assertGrid(config, screen, grid, 1);
|
||||
}
|
||||
|
||||
function assertFocus(shortcutName: string, expectedFocus: KwinClient) {
|
||||
function testFocus(shortcutName: string, expectedFocus: KwinClient) {
|
||||
qtMock.fireShortcut(shortcutName);
|
||||
assert(workspaceMock.activeWindow === expectedFocus, `wrong activeWindow: ${workspaceMock.activeWindow?.pid}`, 1);
|
||||
};
|
||||
|
||||
assertGrid("karousel-column-move-right", [ [client1], [client2], [client3] ]);
|
||||
testLayout("karousel-column-move-right", [ [client1], [client2], [client3] ]);
|
||||
|
||||
assertGrid("karousel-window-move-left", [ [client1], [client2,client3] ]);
|
||||
assertGrid("karousel-window-move-left", [ [client1], [client3], [client2] ]);
|
||||
assertGrid("karousel-window-move-left", [ [client1,client3], [client2] ]);
|
||||
assertFocus("karousel-focus-right", client2);
|
||||
assertGrid("karousel-window-move-left", [ [client1,client3,client2] ]);
|
||||
assertGrid("karousel-window-move-left", [ [client2], [client1,client3] ]);
|
||||
assertGrid("karousel-window-move-left", [ [client2], [client1,client3] ]);
|
||||
assertFocus("karousel-focus-2", client3);
|
||||
assertFocus("karousel-focus-up", client1);
|
||||
assertGrid("karousel-column-move-left", [ [client1,client3], [client2] ]);
|
||||
assertGrid("karousel-window-move-right", [ [client3], [client1], [client2] ]);
|
||||
testLayout("karousel-window-move-left", [ [client1], [client2,client3] ]);
|
||||
testLayout("karousel-window-move-left", [ [client1], [client3], [client2] ]);
|
||||
testLayout("karousel-window-move-left", [ [client1,client3], [client2] ]);
|
||||
testFocus("karousel-focus-right", client2);
|
||||
testLayout("karousel-window-move-left", [ [client1,client3,client2] ]);
|
||||
testLayout("karousel-window-move-left", [ [client2], [client1,client3] ]);
|
||||
testLayout("karousel-window-move-left", [ [client2], [client1,client3] ]);
|
||||
testFocus("karousel-focus-2", client3);
|
||||
testFocus("karousel-focus-up", client1);
|
||||
testLayout("karousel-column-move-left", [ [client1,client3], [client2] ]);
|
||||
testLayout("karousel-window-move-right", [ [client3], [client1], [client2] ]);
|
||||
|
||||
assertFocus("karousel-focus-3", client2);
|
||||
assertGrid("karousel-window-move-start", [ [client2], [client3], [client1] ]);
|
||||
assertGrid("karousel-window-move-to-column-3", [ [client3], [client1,client2] ]);
|
||||
assertGrid("karousel-column-move-left", [ [client1,client2], [client3] ]);
|
||||
assertGrid("karousel-column-move-end", [ [client3], [client1,client2] ]);
|
||||
assertGrid("karousel-column-move-to-column-1", [ [client1,client2], [client3] ]);
|
||||
assertGrid("karousel-column-move-right", [ [client3], [client1,client2] ]);
|
||||
testFocus("karousel-focus-3", client2);
|
||||
testLayout("karousel-window-move-start", [ [client2], [client3], [client1] ]);
|
||||
testLayout("karousel-window-move-to-column-3", [ [client3], [client1,client2] ]);
|
||||
testLayout("karousel-column-move-left", [ [client1,client2], [client3] ]);
|
||||
testLayout("karousel-column-move-end", [ [client3], [client1,client2] ]);
|
||||
testLayout("karousel-column-move-to-column-1", [ [client1,client2], [client3] ]);
|
||||
testLayout("karousel-column-move-right", [ [client3], [client1,client2] ]);
|
||||
|
||||
assertGrid("karousel-window-move-previous", [ [client3], [client2,client1] ]);
|
||||
assertGrid("karousel-window-move-previous", [ [client3], [client2], [client1] ]);
|
||||
assertGrid("karousel-window-move-previous", [ [client3,client2], [client1] ]);
|
||||
assertGrid("karousel-window-move-previous", [ [client2,client3], [client1] ]);
|
||||
assertGrid("karousel-window-move-previous", [ [client2], [client3], [client1] ]);
|
||||
assertGrid("karousel-window-move-previous", [ [client2], [client3], [client1] ]);
|
||||
assertGrid("karousel-window-move-next", [ [client2,client3], [client1] ]);
|
||||
assertGrid("karousel-window-move-next", [ [client3,client2], [client1] ]);
|
||||
assertGrid("karousel-window-move-next", [ [client3], [client2], [client1] ]);
|
||||
assertGrid("karousel-window-move-next", [ [client3], [client2,client1] ]);
|
||||
assertGrid("karousel-window-move-next", [ [client3], [client1,client2] ]);
|
||||
assertGrid("karousel-window-move-next", [ [client3], [client1], [client2] ]);
|
||||
assertGrid("karousel-window-move-next", [ [client3], [client1], [client2] ]);
|
||||
assertGrid("karousel-window-move-left", [ [client3], [client1,client2] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client3], [client2,client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client3], [client2], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client3,client2], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client2,client3], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client2], [client3], [client1] ]);
|
||||
testLayout("karousel-window-move-previous", [ [client2], [client3], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client2,client3], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3,client2], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client2], [client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client2,client1] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client1,client2] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client1], [client2] ]);
|
||||
testLayout("karousel-window-move-next", [ [client3], [client1], [client2] ]);
|
||||
testLayout("karousel-window-move-left", [ [client3], [client1,client2] ]);
|
||||
|
||||
const col1Win1 = client3;
|
||||
const col2Win1 = client1;
|
||||
const col2Win2 = client2;
|
||||
|
||||
assertFocus("karousel-focus-up", col2Win1);
|
||||
assertFocus("karousel-focus-up", col2Win1);
|
||||
assertFocus("karousel-focus-down", col2Win2);
|
||||
assertFocus("karousel-focus-left", col1Win1);
|
||||
assertFocus("karousel-focus-left", col1Win1);
|
||||
assertFocus("karousel-focus-right", col2Win2);
|
||||
assertFocus("karousel-focus-right", col2Win2);
|
||||
testFocus("karousel-focus-up", col2Win1);
|
||||
testFocus("karousel-focus-up", col2Win1);
|
||||
testFocus("karousel-focus-down", col2Win2);
|
||||
testFocus("karousel-focus-left", col1Win1);
|
||||
testFocus("karousel-focus-left", col1Win1);
|
||||
testFocus("karousel-focus-right", col2Win2);
|
||||
testFocus("karousel-focus-right", col2Win2);
|
||||
|
||||
assertFocus("karousel-focus-2", col2Win2);
|
||||
assertFocus("karousel-focus-1", col1Win1);
|
||||
assertFocus("karousel-focus-2", col2Win2);
|
||||
assertFocus("karousel-focus-start", col1Win1);
|
||||
assertFocus("karousel-focus-end", col2Win2);
|
||||
testFocus("karousel-focus-2", col2Win2);
|
||||
testFocus("karousel-focus-1", col1Win1);
|
||||
testFocus("karousel-focus-2", col2Win2);
|
||||
testFocus("karousel-focus-start", col1Win1);
|
||||
testFocus("karousel-focus-end", col2Win2);
|
||||
|
||||
assertFocus("karousel-focus-up", col2Win1);
|
||||
assertFocus("karousel-focus-left", col1Win1);
|
||||
assertFocus("karousel-focus-right", col2Win1);
|
||||
assertFocus("karousel-focus-2", col2Win1);
|
||||
assertFocus("karousel-focus-1", col1Win1);
|
||||
assertFocus("karousel-focus-2", col2Win1);
|
||||
assertFocus("karousel-focus-start", col1Win1);
|
||||
assertFocus("karousel-focus-end", col2Win1);
|
||||
testFocus("karousel-focus-up", col2Win1);
|
||||
testFocus("karousel-focus-left", col1Win1);
|
||||
testFocus("karousel-focus-right", col2Win1);
|
||||
testFocus("karousel-focus-2", col2Win1);
|
||||
testFocus("karousel-focus-1", col1Win1);
|
||||
testFocus("karousel-focus-2", col2Win1);
|
||||
testFocus("karousel-focus-start", col1Win1);
|
||||
testFocus("karousel-focus-end", col2Win1);
|
||||
|
||||
assertFocus("karousel-focus-down", col2Win2);
|
||||
assertFocus("karousel-focus-start", col1Win1);
|
||||
assertFocus("karousel-focus-next", col2Win1);
|
||||
assertFocus("karousel-focus-next", col2Win2);
|
||||
assertFocus("karousel-focus-next", col2Win2);
|
||||
assertFocus("karousel-focus-previous", col2Win1);
|
||||
assertFocus("karousel-focus-previous", col1Win1);
|
||||
assertFocus("karousel-focus-previous", col1Win1);
|
||||
testFocus("karousel-focus-down", col2Win2);
|
||||
testFocus("karousel-focus-start", col1Win1);
|
||||
testFocus("karousel-focus-next", col2Win1);
|
||||
testFocus("karousel-focus-next", col2Win2);
|
||||
testFocus("karousel-focus-next", col2Win2);
|
||||
testFocus("karousel-focus-previous", col2Win1);
|
||||
testFocus("karousel-focus-previous", col1Win1);
|
||||
testFocus("karousel-focus-previous", col1Win1);
|
||||
});
|
||||
|
||||
@@ -28,61 +28,37 @@ tests.register("Pin", 20, () => {
|
||||
new MockQmlRect(10, 20, 100, 200),
|
||||
);
|
||||
|
||||
function getRectInGrid(screen: QmlRect, column: number, window: number, nColumns: number, nWindows: number) {
|
||||
const columnHeight = screen.height - config.gapsOuterTop - config.gapsOuterBottom;
|
||||
const columnsWidth = nColumns * 100 + (nColumns-1) * config.gapsInnerHorizontal;
|
||||
const windowHeight = (columnHeight - config.gapsInnerVertical * (nWindows-1)) / nWindows;
|
||||
return new MockQmlRect(
|
||||
screen.x + column * (100 + config.gapsInnerHorizontal) + (screen.width-columnsWidth) / 2,
|
||||
screen.y + config.gapsOuterTop + (windowHeight + config.gapsInnerVertical) * window,
|
||||
100,
|
||||
(columnHeight - config.gapsInnerVertical * (nWindows-1)) / nWindows,
|
||||
);
|
||||
}
|
||||
|
||||
function assertGrid(screen: QmlRect, grid: KwinClient[][]) {
|
||||
const nColumns = grid.length;
|
||||
for (let iColumn = 0; iColumn < nColumns; iColumn++) {
|
||||
const column = grid[iColumn];
|
||||
const nWindows = column.length;
|
||||
for (let iWindow = 0; iWindow < nWindows; iWindow++) {
|
||||
const window = column[iWindow];
|
||||
assertRectEqual(window.frameGeometry, getRectInGrid(screen, iColumn, iWindow, nColumns, nWindows), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
workspaceMock.createWindow(pinned);
|
||||
workspaceMock.createWindow(tiled1);
|
||||
workspaceMock.createWindow(tiled2);
|
||||
assertGrid(screenFull, [ [pinned], [tiled1], [tiled2] ]);
|
||||
assertGrid(config, screenFull, [ [pinned], [tiled1], [tiled2] ]);
|
||||
|
||||
pinned.pin(screenHalfLeft);
|
||||
assertRectEqual(pinned.frameGeometry, screenHalfLeft);
|
||||
assertGrid(screenHalfRight, [ [tiled1], [tiled2] ]);
|
||||
assertGrid(config, screenHalfRight, [ [tiled1], [tiled2] ]);
|
||||
|
||||
pinned.pin(screenHalfRight);
|
||||
assertRectEqual(pinned.frameGeometry, screenHalfRight);
|
||||
assertGrid(screenHalfLeft, [ [tiled1], [tiled2] ]);
|
||||
assertGrid(config, screenHalfLeft, [ [tiled1], [tiled2] ]);
|
||||
|
||||
pinned.unpin();
|
||||
assertRectEqual(pinned.frameGeometry, screenHalfRight);
|
||||
assertGrid(screenFull, [ [tiled1], [tiled2] ]);
|
||||
assertGrid(config, screenFull, [ [tiled1], [tiled2] ]);
|
||||
|
||||
pinned.pin(screenHalfRight);
|
||||
assertRectEqual(pinned.frameGeometry, screenHalfRight);
|
||||
assertGrid(screenHalfLeft, [ [tiled1], [tiled2] ]);
|
||||
assertGrid(config, screenHalfLeft, [ [tiled1], [tiled2] ]);
|
||||
|
||||
pinned.minimized = true;
|
||||
assertGrid(screenFull, [ [tiled1], [tiled2] ]);
|
||||
assertGrid(config, screenFull, [ [tiled1], [tiled2] ]);
|
||||
|
||||
pinned.minimized = false;
|
||||
assertRectEqual(pinned.frameGeometry, screenHalfRight);
|
||||
assertGrid(screenHalfLeft, [ [tiled1], [tiled2] ]);
|
||||
assertGrid(config, screenHalfLeft, [ [tiled1], [tiled2] ]);
|
||||
|
||||
workspaceMock.activeWindow = pinned;
|
||||
qtMock.fireShortcut("karousel-window-toggle-floating");
|
||||
assert(pinned.tile === null);
|
||||
pinned.frameGeometry = new MockQmlRect(10, 20, 100, 200); // This is needed because the window's preferredWidth can change when pinning, because frameGeometryChanged can fire before tileChanged. TODO: Ensure pinned window keeps its preferredWidth.
|
||||
assertGrid(screenFull, [ [tiled1], [tiled2], [pinned] ]);
|
||||
assertGrid(config, screenFull, [ [tiled1], [tiled2], [pinned] ]);
|
||||
});
|
||||
|
||||
@@ -35,6 +35,31 @@ Expected: ${expected}
|
||||
Actual: ${actual}`, skip+1);
|
||||
}
|
||||
|
||||
function assertRect(actual: QmlRect, x: number, y: number, width: number, height: number) {
|
||||
assertRectEqual(actual, new MockQmlRect(x, y, width, height), 1);
|
||||
function assertRect(actual: QmlRect, x: number, y: number, width: number, height: number, skip: number = 0) {
|
||||
assertRectEqual(actual, new MockQmlRect(x, y, width, height), skip+1);
|
||||
}
|
||||
|
||||
function assertGrid(config: Config, screen: QmlRect, grid: KwinClient[][], skip: number = 0) {
|
||||
// assumes uniformly sized columns and windows within columns
|
||||
function getRectInGrid(column: number, window: number, nColumns: number, nWindows: number) {
|
||||
const columnHeight = screen.height - config.gapsOuterTop - config.gapsOuterBottom;
|
||||
const columnsWidth = nColumns * 100 + (nColumns-1) * config.gapsInnerHorizontal;
|
||||
const windowHeight = (columnHeight - config.gapsInnerVertical * (nWindows-1)) / nWindows;
|
||||
return new MockQmlRect(
|
||||
screen.x + column * (100 + config.gapsInnerHorizontal) + (screen.width-columnsWidth) / 2,
|
||||
screen.y + config.gapsOuterTop + (windowHeight + config.gapsInnerVertical) * window,
|
||||
100,
|
||||
(columnHeight - config.gapsInnerVertical * (nWindows-1)) / nWindows,
|
||||
);
|
||||
}
|
||||
|
||||
const nColumns = grid.length;
|
||||
for (let iColumn = 0; iColumn < nColumns; iColumn++) {
|
||||
const column = grid[iColumn];
|
||||
const nWindows = column.length;
|
||||
for (let iWindow = 0; iWindow < nWindows; iWindow++) {
|
||||
const window = column[iWindow];
|
||||
assertRectEqual(window.frameGeometry, getRectInGrid(iColumn, iWindow, nColumns, nWindows), skip+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user