tests: add global variables and

This commit is contained in:
Peter Fajdiga
2024-10-04 23:22:35 +02:00
parent 5e7f191e95
commit f3cf45e5f3
9 changed files with 82 additions and 83 deletions

View File

@@ -1,7 +1,6 @@
tests.register("Focus and move windows", 1, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const client1 = new MockKwinClient(
1,
@@ -36,7 +35,6 @@ tests.register("Focus and move windows", 1, () => {
function testLayout(shortcutName: string, grid: KwinClient[][]) {
qtMock.fireShortcut(shortcutName);
const screen = new MockQmlRect(0, 0, screenWidth, screenHeight);
Assert.grid(config, screen, grid, { skip: 1 });
}

View File

@@ -1,7 +1,6 @@
tests.register("Maximization", 100, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const kwinClient = new MockKwinClient(
1,
@@ -15,31 +14,30 @@ tests.register("Maximization", 100, () => {
Assert.truth(clientManager.hasClient(kwinClient));
});
const columnLeftX = screenWidth/2 - 300/2;
const columnTopY = config.gapsOuterTop;
const columnHeight = screenHeight - config.gapsOuterTop - config.gapsOuterBottom;
const columnLeftX = screen.width/2 - 300/2;
const columnTopY = tilingArea.top;
const columnHeight = tilingArea.height;
Assert.rect(kwinClient.frameGeometry, columnLeftX, columnTopY, 300, columnHeight);
kwinClient.fullScreen = true;
Assert.rect(kwinClient.frameGeometry, 0, 0, screenWidth, screenHeight);
Assert.equalRects(kwinClient.frameGeometry, screen);
kwinClient.fullScreen = false;
Assert.rect(kwinClient.frameGeometry, columnLeftX, columnTopY, 300, columnHeight);
kwinClient.setMaximize(true, true);
Assert.rect(kwinClient.frameGeometry, 0, 0, screenWidth, screenHeight);
Assert.equalRects(kwinClient.frameGeometry, screen);
kwinClient.setMaximize(true, false);
Assert.rect(kwinClient.frameGeometry, columnLeftX, 0, 300, screenHeight);
Assert.rect(kwinClient.frameGeometry, columnLeftX, 0, 300, screen.height);
kwinClient.setMaximize(false, false);
Assert.rect(kwinClient.frameGeometry, columnLeftX, columnTopY, 300, columnHeight);
});
tests.register("Maximize with transient", 100, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const parent = new MockKwinClient(
1,
@@ -65,21 +63,20 @@ tests.register("Maximize with transient", 100, () => {
() => parent.fullScreen = true,
() => parent.setMaximize(true, true),
);
Assert.rect(parent.frameGeometry, 0, 0, screenWidth, screenHeight);
Assert.equalRects(parent.frameGeometry, screen);
workspaceMock.createWindow(child);
world.do((clientManager, desktopManager) => {
Assert.truth(clientManager.hasClient(child));
});
Assert.rect(child.frameGeometry, 14, 24, 50, 50);
Assert.rect(parent.frameGeometry, 0, 0, screenWidth, screenHeight);
Assert.equalRects(parent.frameGeometry, screen);
});
tests.register("Re-maximize disabled", 100, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
config.reMaximize = false;
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const client1 = new MockKwinClient(
1,
@@ -103,10 +100,10 @@ tests.register("Re-maximize disabled", 100, () => {
});
const columnsWidth = 300 + 400 + config.gapsInnerHorizontal;
const column1LeftX = screenWidth/2 - columnsWidth/2;
const column1LeftX = screen.width/2 - columnsWidth/2;
const column2LeftX = column1LeftX + 300 + config.gapsInnerHorizontal;
const columnTopY = config.gapsOuterTop;
const columnHeight = screenHeight - config.gapsOuterTop - config.gapsOuterBottom;
const columnTopY = tilingArea.top;
const columnHeight = tilingArea.height;
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
Assert.rect(client2.frameGeometry, column2LeftX, columnTopY, 400, columnHeight);
@@ -115,7 +112,7 @@ tests.register("Re-maximize disabled", 100, () => {
() => client2.setMaximize(true, true),
);
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
Assert.rect(client2.frameGeometry, 0, 0, screenWidth, screenHeight);
Assert.equalRects(client2.frameGeometry, screen);
runOneOf(
() => workspaceMock.activeWindow = client1,
@@ -137,10 +134,9 @@ tests.register("Re-maximize disabled", 100, () => {
});
tests.register("Re-maximize enabled", 100, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
config.reMaximize = true;
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const client1 = new MockKwinClient(
1,
@@ -164,10 +160,10 @@ tests.register("Re-maximize enabled", 100, () => {
});
const columnsWidth = 300 + 400 + config.gapsInnerHorizontal;
const column1LeftX = screenWidth/2 - columnsWidth/2;
const column1LeftX = screen.width/2 - columnsWidth/2;
const column2LeftX = column1LeftX + 300 + config.gapsInnerHorizontal;
const columnTopY = config.gapsOuterTop;
const columnHeight = screenHeight - config.gapsOuterTop - config.gapsOuterBottom;
const columnTopY = tilingArea.top;
const columnHeight = tilingArea.height;
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
Assert.rect(client2.frameGeometry, column2LeftX, columnTopY, 400, columnHeight);
@@ -176,7 +172,7 @@ tests.register("Re-maximize enabled", 100, () => {
() => client2.setMaximize(true, true),
);
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
Assert.rect(client2.frameGeometry, 0, 0, screenWidth, screenHeight);
Assert.equalRects(client2.frameGeometry, screen);
runOneOf(
() => workspaceMock.activeWindow = client1,
@@ -194,5 +190,5 @@ tests.register("Re-maximize enabled", 100, () => {
() => qtMock.fireShortcut("karousel-focus-end"),
);
Assert.rect(client1.frameGeometry, column1LeftX, columnTopY, 300, columnHeight);
Assert.rect(client2.frameGeometry, 0, 0, screenWidth, screenHeight);
Assert.equalRects(client2.frameGeometry, screen);
});

View File

@@ -1,11 +1,9 @@
tests.register("Pin", 20, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const screenFull = new MockQmlRect(0, 0, screenWidth, screenHeight);
const screenHalfLeft = new MockQmlRect(0, 0, screenWidth/2, screenHeight);
const screenHalfRight = new MockQmlRect(screenWidth/2, 0, screenWidth/2, screenHeight);
const screenHalfLeft = new MockQmlRect(0, 0, screen.width/2, screen.height);
const screenHalfRight = new MockQmlRect(screen.width/2, 0, screen.width/2, screen.height);
const tiled1 = new MockKwinClient(
1,
@@ -31,7 +29,7 @@ tests.register("Pin", 20, () => {
workspaceMock.createWindow(pinned);
workspaceMock.createWindow(tiled1);
workspaceMock.createWindow(tiled2);
Assert.grid(config, screenFull, [ [pinned], [tiled1], [tiled2] ]);
Assert.grid(config, screen, [ [pinned], [tiled1], [tiled2] ]);
pinned.pin(screenHalfLeft);
Assert.equalRects(pinned.frameGeometry, screenHalfLeft);
@@ -43,14 +41,14 @@ tests.register("Pin", 20, () => {
pinned.unpin();
Assert.equalRects(pinned.frameGeometry, screenHalfRight);
Assert.grid(config, screenFull, [ [tiled1], [tiled2] ]);
Assert.grid(config, screen, [ [tiled1], [tiled2] ]);
pinned.pin(screenHalfRight);
Assert.equalRects(pinned.frameGeometry, screenHalfRight);
Assert.grid(config, screenHalfLeft, [ [tiled1], [tiled2] ]);
pinned.minimized = true;
Assert.grid(config, screenFull, [ [tiled1], [tiled2] ]);
Assert.grid(config, screen, [ [tiled1], [tiled2] ]);
pinned.minimized = false;
Assert.equalRects(pinned.frameGeometry, screenHalfRight);
@@ -60,5 +58,5 @@ tests.register("Pin", 20, () => {
qtMock.fireShortcut("karousel-window-toggle-floating");
Assert.truth(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.
Assert.grid(config, screenFull, [ [tiled1], [tiled2], [pinned] ]);
Assert.grid(config, screen, [ [tiled1], [tiled2], [pinned] ]);
});

View File

@@ -1,9 +1,8 @@
tests.register("Preset Widths default", 1, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const maxWidth = screenWidth - config.gapsOuterLeft - config.gapsOuterRight;
const maxWidth = tilingArea.width;
const halfWidth = maxWidth/2 - config.gapsInnerHorizontal/2;
const kwinClient = new MockKwinClient(
@@ -15,10 +14,10 @@ tests.register("Preset Widths default", 1, () => {
function getRect(columnWidth: number) {
return new MockQmlRect(
(screenWidth - columnWidth) / 2,
config.gapsOuterTop,
(screen.width - columnWidth) / 2,
tilingArea.top,
columnWidth,
screenHeight - config.gapsOuterTop - config.gapsOuterBottom,
tilingArea.height,
);
}
@@ -36,12 +35,11 @@ tests.register("Preset Widths default", 1, () => {
});
tests.register("Preset Widths custom", 1, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
config.presetWidths = "500px, 250px, 100px, 50%";
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const maxWidth = screenWidth - config.gapsOuterLeft - config.gapsOuterRight;
const maxWidth = tilingArea.width;
const halfWidth = maxWidth/2 - config.gapsInnerHorizontal/2;
const kwinClient = new MockKwinClient(
@@ -53,10 +51,10 @@ tests.register("Preset Widths custom", 1, () => {
function getRect(columnWidth: number) {
return new MockQmlRect(
(screenWidth - columnWidth) / 2,
config.gapsOuterTop,
(screen.width - columnWidth) / 2,
tilingArea.top,
columnWidth,
screenHeight - config.gapsOuterTop - config.gapsOuterBottom,
tilingArea.height,
);
}
@@ -81,10 +79,9 @@ tests.register("Preset Widths custom", 1, () => {
tests.register("Preset Widths fill screen uniform", 1, () => {
for (let nColumns = 1; nColumns < 10; nColumns++) {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
config.presetWidths = String(1 / nColumns);
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
let firstClient, lastClient;
for (let i = 0; i < nColumns; i++) {
@@ -104,8 +101,8 @@ tests.register("Preset Widths fill screen uniform", 1, () => {
qtMock.fireShortcut("karousel-cycle-preset-widths");
}
const left = config.gapsOuterLeft;
const right = screenWidth - config.gapsOuterRight;
const left = tilingArea.left;
const right = tilingArea.right;
const maxLeftoverPx = nColumns - 1;
const eps = Math.ceil(maxLeftoverPx / 2);
Assert.between(firstClient!.frameGeometry.left, left, left+eps, { message: `nColumns: ${nColumns}` });
@@ -114,10 +111,9 @@ tests.register("Preset Widths fill screen uniform", 1, () => {
});
tests.register("Preset Widths fill screen non-uniform", 1, () => {
const { qtMock, workspaceMock } = initMocks();
const config = getDefaultConfig();
config.presetWidths = String("50%, 25%");
const world = new World(config);
const { qtMock, workspaceMock, world } = init(config);
const clientThin1 = new MockKwinClient(
1,
@@ -146,16 +142,16 @@ tests.register("Preset Widths fill screen non-uniform", 1, () => {
workspaceMock.createWindow(clientWide);
qtMock.fireShortcut("karousel-cycle-preset-widths");
const maxWidth = screenWidth - config.gapsOuterLeft - config.gapsOuterRight;
const maxWidth = tilingArea.width;
const halfWidth = maxWidth/2 - config.gapsInnerHorizontal/2;
const quarterWidth = halfWidth/2 - config.gapsInnerHorizontal/2;
const height = screenHeight - config.gapsOuterTop - config.gapsOuterBottom;
const left1 = config.gapsOuterLeft;
const height = tilingArea.height;
const left1 = tilingArea.left;
const left2 = left1 + config.gapsInnerHorizontal + quarterWidth;
const left3 = left2 + config.gapsInnerHorizontal + quarterWidth;
Assert.rect(clientThin1.frameGeometry, left1, config.gapsOuterTop, quarterWidth, height);
Assert.rect(clientThin2.frameGeometry, left2, config.gapsOuterTop, quarterWidth, height);
Assert.rect(clientWide.frameGeometry, left3, config.gapsOuterTop, halfWidth, height);
Assert.equal(clientWide.frameGeometry.right, screenWidth - config.gapsOuterRight);
Assert.rect(clientThin1.frameGeometry, left1, tilingArea.top, quarterWidth, height);
Assert.rect(clientThin2.frameGeometry, left2, tilingArea.top, quarterWidth, height);
Assert.rect(clientWide.frameGeometry, left3, tilingArea.top, halfWidth, height);
Assert.equal(clientWide.frameGeometry.right, tilingArea.right);
});

View File

@@ -1,2 +0,0 @@
const screenWidth = 800;
const screenHeight = 600;

View File

@@ -4,3 +4,25 @@ let Workspace: Workspace;
let qmlBase: QmlObject;
let notificationInvalidWindowRules: Notification;
let notificationInvalidPresetWidths: Notification;
let screen: QmlRect;
let tilingArea: QmlRect;
function init(config: Config) {
screen = new MockQmlRect(0, 0, 800, 600);
tilingArea = new MockQmlRect(
config.gapsOuterLeft,
config.gapsOuterTop,
screen.width - config.gapsOuterLeft - config.gapsOuterRight,
screen.height - config.gapsOuterTop - config.gapsOuterBottom,
);
const qtMock = new MockQt();
const workspaceMock = new MockWorkspace();
Qt = qtMock;
Workspace = workspaceMock;
const world = new World(config);
return { qtMock, workspaceMock, world };
}

View File

@@ -67,10 +67,10 @@ class MockKwinClient {
);
this.frameGeometry = new MockQmlRect(
horizontally ? 0 : this.windowedFrameGeometry.x,
vertically ? 0 : this.windowedFrameGeometry.y,
horizontally ? screenWidth : this.windowedFrameGeometry.width,
vertically ? screenHeight : this.windowedFrameGeometry.height,
horizontally ? 0 : this.windowedFrameGeometry.x,
vertically ? 0 : this.windowedFrameGeometry.y,
horizontally ? screen.width : this.windowedFrameGeometry.width,
vertically ? screen.height : this.windowedFrameGeometry.height,
);
}
@@ -111,14 +111,14 @@ class MockKwinClient {
() => this.frameGeometry = new MockQmlRect(
0,
0,
screenWidth + 2 * MockKwinClient.borderThickness,
screenHeight + 2 * MockKwinClient.borderThickness,
screen.width + 2 * MockKwinClient.borderThickness,
screen.height + 2 * MockKwinClient.borderThickness,
),
() => this.frameGeometry = new MockQmlRect(
-MockKwinClient.borderThickness,
-MockKwinClient.borderThickness,
screenWidth + 2 * MockKwinClient.borderThickness,
screenHeight + 2 * MockKwinClient.borderThickness,
screen.width + 2 * MockKwinClient.borderThickness,
screen.height + 2 * MockKwinClient.borderThickness,
),
() => {},
);
@@ -127,7 +127,7 @@ class MockKwinClient {
() => {
this.windowed = !fullScreen;
if (fullScreen) {
this.frameGeometry = new MockQmlRect(0, 0, screenWidth, screenHeight);
this.frameGeometry = screen;
} else {
this.frameGeometry = this.windowedFrameGeometry;
}

View File

@@ -25,7 +25,7 @@ class MockWorkspace {
public readonly virtualScreenSizeChanged = new MockQSignal<[]>();
public clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop) {
return new MockQmlRect(0, 0, screenWidth, screenHeight);
return screen;
}
public createWindow(kwinClient: MockKwinClient) {

View File

@@ -1,9 +0,0 @@
function initMocks() {
const qtMock = new MockQt();
const workspaceMock = new MockWorkspace();
Qt = qtMock;
Workspace = workspaceMock;
return {qtMock, workspaceMock};
}