From d239ac24b3701e0b9b8e4e2551c6449714ebbb9e Mon Sep 17 00:00:00 2001 From: Peter Fajdiga Date: Sun, 15 Sep 2024 17:41:10 +0200 Subject: [PATCH] tests: setters for full screen and frame geometry --- src/tests/flows/maximization.ts | 17 ++++++++- src/tests/utils/mocks/KwinClient.ts | 50 +++++++++++++++++++++++-- src/tests/utils/mocks/QmlRect.ts | 58 +++++++++++++++++++++++++++-- src/tests/utils/mocks/Workspace.ts | 2 +- src/tests/utils/mocks/constants.ts | 4 ++ 5 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 src/tests/utils/mocks/constants.ts diff --git a/src/tests/flows/maximization.ts b/src/tests/flows/maximization.ts index 6661c77..ebb3009 100644 --- a/src/tests/flows/maximization.ts +++ b/src/tests/flows/maximization.ts @@ -4,10 +4,23 @@ Workspace = workspaceMock; const world = new World(getDefaultConfig()); - workspaceMock.createWindow(new Mocks.KwinClient( + const kwinClient = new Mocks.KwinClient( 1, "app1", "Application 1", new Mocks.QmlRect(0, 0, 200, 200), - )); + ); + + workspaceMock.createWindow(kwinClient); + kwinClient.fullScreen = true; + { + const frame = kwinClient.frameGeometry; + assert(frame.width === Mocks.screenWidth && frame.height === Mocks.screenHeight); + } + + kwinClient.fullScreen = false; + { + const frame = kwinClient.frameGeometry; + assert(frame.width === 200 && frame.height === 200); + } } diff --git a/src/tests/utils/mocks/KwinClient.ts b/src/tests/utils/mocks/KwinClient.ts index 9a50215..46dfa7e 100644 --- a/src/tests/utils/mocks/KwinClient.ts +++ b/src/tests/utils/mocks/KwinClient.ts @@ -18,7 +18,7 @@ namespace Mocks { public readonly managed: boolean = false; public readonly popupWindow: boolean = false; - public fullScreen: boolean = false; + private _fullScreen: boolean = false; public activities: string[] = []; public skipSwitcher: boolean = false; public keepAbove: boolean = false; @@ -40,12 +40,17 @@ namespace Mocks { public readonly interactiveMoveResizeFinished: QSignal<[]> = new QSignal(); public readonly frameGeometryChanged: QSignal<[oldGeometry: QmlRect]> = new QSignal(); + private windowedFrameGeometry: QmlRect; + private windowed: boolean = false; + constructor( public readonly pid: number, public readonly resourceClass: string, public readonly caption: string, - public frameGeometry: QmlRect, - ) {} + private _frameGeometry: QmlRect, + ) { + this.windowedFrameGeometry = _frameGeometry.clone(); + } setMaximize(vertically: boolean, horizontally: boolean) { this.maximizedAboutToChange.fire( @@ -58,6 +63,10 @@ namespace Mocks { } public get clientGeometry() { + if (this._fullScreen) { + return this.frameGeometry; + } + return new QmlRect( this.frameGeometry.x + KwinClient.borderThickness, this.frameGeometry.y + KwinClient.borderThickness, @@ -65,5 +74,40 @@ namespace Mocks { this.frameGeometry.height - 2 * KwinClient.borderThickness, ); } + + public get fullScreen() { + return this._fullScreen; + } + + public set fullScreen(fullScreen: boolean) { + this.windowed = !fullScreen; + this._fullScreen = fullScreen; + this.fullScreenChanged.fire(); + + if (fullScreen) { + this.frameGeometry = new QmlRect(0, 0, screenWidth, screenHeight); + } else { + this.frameGeometry = this.windowedFrameGeometry; + } + } + + public get frameGeometry() { + return this._frameGeometry; + } + + public set frameGeometry(frameGeometry: QmlRect) { + const oldFrameGeometry = this._frameGeometry; + this._frameGeometry = new QmlRect( + frameGeometry.x, + frameGeometry.y, + frameGeometry.width, + frameGeometry.height, + this.frameGeometryChanged.fire, + ); + if (this.windowed) { + this.windowedFrameGeometry = this._frameGeometry.clone(); + } + this.frameGeometryChanged.fire(oldFrameGeometry); + } } } diff --git a/src/tests/utils/mocks/QmlRect.ts b/src/tests/utils/mocks/QmlRect.ts index 08bd907..607dd94 100644 --- a/src/tests/utils/mocks/QmlRect.ts +++ b/src/tests/utils/mocks/QmlRect.ts @@ -1,12 +1,53 @@ namespace Mocks { export class QmlRect { constructor( - public x: number, - public y: number, - public width: number, - public height: number, + private _x: number, + private _y: number, + private _width: number, + private _height: number, + private readonly onChanged: (oldRect: QmlRect) => void = () => {}, ) {} + public get x() { + return this._x; + } + + public set x(x: number) { + const oldRect = this.clone(); + this._x = x; + this.onChanged(oldRect); + } + + public get y() { + return this._y; + } + + public set y(y: number) { + const oldRect = this.clone(); + this._y = y; + this.onChanged(oldRect); + } + + public get width() { + return this._width; + } + + public set width(width: number) { + const oldRect = this.clone(); + this._width = width; + this.onChanged(oldRect); + } + + public get height() { + return this._height; + } + + public set height(height: number) { + const oldRect = this.clone(); + this._height = height; + this.onChanged(oldRect); + } + public get top() { return this.y; } @@ -22,5 +63,14 @@ namespace Mocks { public get right() { return this.x + this.width; } + + public clone() { + return new QmlRect( + this._x, + this._y, + this._width, + this._height, + ); + } } } diff --git a/src/tests/utils/mocks/Workspace.ts b/src/tests/utils/mocks/Workspace.ts index 22824d5..fd2f2e6 100644 --- a/src/tests/utils/mocks/Workspace.ts +++ b/src/tests/utils/mocks/Workspace.ts @@ -21,7 +21,7 @@ namespace Mocks { public readonly virtualScreenSizeChanged = new Mocks.QSignal<[]>(); public clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop) { - return new QmlRect(0, 0, 800, 600); + return new QmlRect(0, 0, Mocks.screenWidth, Mocks.screenHeight); } public createWindow(kwinClient: KwinClient) { diff --git a/src/tests/utils/mocks/constants.ts b/src/tests/utils/mocks/constants.ts new file mode 100644 index 0000000..9e4644d --- /dev/null +++ b/src/tests/utils/mocks/constants.ts @@ -0,0 +1,4 @@ +namespace Mocks { + export const screenWidth = 800; + export const screenHeight = 600; +}