diff --git a/src/tests/flows/maximization.ts b/src/tests/flows/maximization.ts index ebb3009..09aa870 100644 --- a/src/tests/flows/maximization.ts +++ b/src/tests/flows/maximization.ts @@ -1,21 +1,21 @@ { - Qt = new Mocks.Qt(); - const workspaceMock = new Mocks.Workspace(); + Qt = new MockQt(); + const workspaceMock = new MockWorkspace(); Workspace = workspaceMock; const world = new World(getDefaultConfig()); - const kwinClient = new Mocks.KwinClient( + const kwinClient = new MockKwinClient( 1, "app1", "Application 1", - new Mocks.QmlRect(0, 0, 200, 200), + new MockQmlRect(0, 0, 200, 200), ); workspaceMock.createWindow(kwinClient); kwinClient.fullScreen = true; { const frame = kwinClient.frameGeometry; - assert(frame.width === Mocks.screenWidth && frame.height === Mocks.screenHeight); + assert(frame.width === screenWidth && frame.height === screenHeight); } kwinClient.fullScreen = false; diff --git a/src/tests/utils/constants.ts b/src/tests/utils/constants.ts new file mode 100644 index 0000000..241be0e --- /dev/null +++ b/src/tests/utils/constants.ts @@ -0,0 +1,2 @@ +const screenWidth = 800; +const screenHeight = 600; diff --git a/src/tests/utils/mocks/KwinClient.ts b/src/tests/utils/mocks/KwinClient.ts index 46dfa7e..9876f68 100644 --- a/src/tests/utils/mocks/KwinClient.ts +++ b/src/tests/utils/mocks/KwinClient.ts @@ -1,113 +1,111 @@ -namespace Mocks { - export class KwinClient { - private static readonly borderThickness = 10; +class MockKwinClient { + private static readonly borderThickness = 10; - public readonly shadeable: boolean = false; - public readonly minSize: Readonly = new QmlSize(0, 0); - public readonly transient: boolean = false; - public readonly transientFor: KwinClient | null = null; - public readonly move: boolean = false; - public readonly resize: boolean = false; - public readonly moveable: boolean = false; - public readonly resizeable: boolean = false; - public readonly fullScreenable: boolean = false; - public readonly maximizable: boolean = false; - public readonly output: Output = false; - public readonly dock: boolean = false; - public readonly normalWindow: boolean = false; - public readonly managed: boolean = false; - public readonly popupWindow: boolean = false; + public readonly shadeable: boolean = false; + public readonly minSize: Readonly = new MockQmlSize(0, 0); + public readonly transient: boolean = false; + public readonly transientFor: MockKwinClient | null = null; + public readonly move: boolean = false; + public readonly resize: boolean = false; + public readonly moveable: boolean = false; + public readonly resizeable: boolean = false; + public readonly fullScreenable: boolean = false; + public readonly maximizable: boolean = false; + public readonly output: Output = false; + public readonly dock: boolean = false; + public readonly normalWindow: boolean = false; + public readonly managed: boolean = false; + public readonly popupWindow: boolean = false; - private _fullScreen: boolean = false; - public activities: string[] = []; - public skipSwitcher: boolean = false; - public keepAbove: boolean = false; - public keepBelow: boolean = false; - public shade: boolean = false; - public minimized: boolean = false; - public desktops: KwinDesktop[] = []; - public tile: Tile = false; - public opacity: number = 1.0; + private _fullScreen: boolean = false; + public activities: string[] = []; + public skipSwitcher: boolean = false; + public keepAbove: boolean = false; + public keepBelow: boolean = false; + public shade: boolean = false; + public minimized: boolean = false; + public desktops: KwinDesktop[] = []; + public tile: Tile = false; + public opacity: number = 1.0; - public readonly fullScreenChanged: QSignal<[]> = new QSignal(); - public readonly desktopsChanged: QSignal<[]> = new QSignal(); - public readonly activitiesChanged: QSignal<[]> = new QSignal(); - public readonly minimizedChanged: QSignal<[]> = new QSignal(); - public readonly maximizedAboutToChange: QSignal<[MaximizedMode]> = new QSignal(); - public readonly captionChanged: QSignal<[]> = new QSignal(); - public readonly tileChanged: QSignal<[]> = new QSignal(); - public readonly interactiveMoveResizeStarted: QSignal<[]> = new QSignal(); - public readonly interactiveMoveResizeFinished: QSignal<[]> = new QSignal(); - public readonly frameGeometryChanged: QSignal<[oldGeometry: QmlRect]> = new QSignal(); + public readonly fullScreenChanged = new MockQSignal(); + public readonly desktopsChanged = new MockQSignal(); + public readonly activitiesChanged = new MockQSignal(); + public readonly minimizedChanged = new MockQSignal(); + public readonly maximizedAboutToChange = new MockQSignal<[MaximizedMode]>(); + public readonly captionChanged = new MockQSignal(); + public readonly tileChanged = new MockQSignal(); + public readonly interactiveMoveResizeStarted = new MockQSignal(); + public readonly interactiveMoveResizeFinished = new MockQSignal(); + public readonly frameGeometryChanged = new MockQSignal<[oldGeometry: QmlRect]>(); - private windowedFrameGeometry: QmlRect; - private windowed: boolean = false; + private windowedFrameGeometry: QmlRect; + private windowed: boolean = false; - constructor( - public readonly pid: number, - public readonly resourceClass: string, - public readonly caption: string, - private _frameGeometry: QmlRect, - ) { - this.windowedFrameGeometry = _frameGeometry.clone(); + constructor( + public readonly pid: number, + public readonly resourceClass: string, + public readonly caption: string, + private _frameGeometry: MockQmlRect, + ) { + this.windowedFrameGeometry = _frameGeometry.clone(); + } + + setMaximize(vertically: boolean, horizontally: boolean) { + this.maximizedAboutToChange.fire( + vertically ? ( + horizontally ? MaximizedMode.Maximized : MaximizedMode.Vertically + ) : ( + horizontally ? MaximizedMode.Horizontally : MaximizedMode.Unmaximized + ) + ); + } + + public get clientGeometry() { + if (this._fullScreen) { + return this.frameGeometry; } - setMaximize(vertically: boolean, horizontally: boolean) { - this.maximizedAboutToChange.fire( - vertically ? ( - horizontally ? MaximizedMode.Maximized : MaximizedMode.Vertically - ) : ( - horizontally ? MaximizedMode.Horizontally : MaximizedMode.Unmaximized - ) - ); - } + return new MockQmlRect( + this.frameGeometry.x + MockKwinClient.borderThickness, + this.frameGeometry.y + MockKwinClient.borderThickness, + this.frameGeometry.width - 2 * MockKwinClient.borderThickness, + this.frameGeometry.height - 2 * MockKwinClient.borderThickness, + ); + } - public get clientGeometry() { - if (this._fullScreen) { - return this.frameGeometry; - } + public get fullScreen() { + return this._fullScreen; + } - return new QmlRect( - this.frameGeometry.x + KwinClient.borderThickness, - this.frameGeometry.y + KwinClient.borderThickness, - this.frameGeometry.width - 2 * KwinClient.borderThickness, - this.frameGeometry.height - 2 * KwinClient.borderThickness, - ); - } + public set fullScreen(fullScreen: boolean) { + this.windowed = !fullScreen; + this._fullScreen = fullScreen; + this.fullScreenChanged.fire(); - 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); + if (fullScreen) { + this.frameGeometry = new MockQmlRect(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 MockQmlRect( + 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/QSignal.ts b/src/tests/utils/mocks/QSignal.ts index 4517e94..a1d0f58 100644 --- a/src/tests/utils/mocks/QSignal.ts +++ b/src/tests/utils/mocks/QSignal.ts @@ -1,19 +1,17 @@ -namespace Mocks { - export class QSignal { - private readonly handlers: Set<(...args: [...T]) => void> = new Set(); +class MockQSignal { + private readonly handlers: Set<(...args: [...T]) => void> = new Set(); - public connect(handler: (...args: [...T]) => void) { - this.handlers.add(handler); - }; + public connect(handler: (...args: [...T]) => void) { + this.handlers.add(handler); + }; - public disconnect(handler: (...args: [...T]) => void) { - this.handlers.delete(handler); - }; + public disconnect(handler: (...args: [...T]) => void) { + this.handlers.delete(handler); + }; - public fire(...args: [...T]) { - for (const handler of this.handlers) { - handler(...args); - } + public fire(...args: [...T]) { + for (const handler of this.handlers) { + handler(...args); } } } diff --git a/src/tests/utils/mocks/QmlPoint.ts b/src/tests/utils/mocks/QmlPoint.ts index 3a82818..485f603 100644 --- a/src/tests/utils/mocks/QmlPoint.ts +++ b/src/tests/utils/mocks/QmlPoint.ts @@ -1,8 +1,6 @@ -namespace Mocks { - export class QmlPoint { - constructor( - public x: number, - public y: number, - ) {} - } +class MockQmlPoint { + constructor( + public x: number, + public y: number, + ) {} } diff --git a/src/tests/utils/mocks/QmlRect.ts b/src/tests/utils/mocks/QmlRect.ts index 607dd94..915421c 100644 --- a/src/tests/utils/mocks/QmlRect.ts +++ b/src/tests/utils/mocks/QmlRect.ts @@ -1,76 +1,74 @@ -namespace Mocks { - export class QmlRect { - constructor( - private _x: number, - private _y: number, - private _width: number, - private _height: number, - private readonly onChanged: (oldRect: QmlRect) => void = () => {}, - ) {} +class MockQmlRect { + constructor( + private _x: number, + private _y: number, + private _width: number, + private _height: number, + private readonly onChanged: (oldRect: MockQmlRect) => void = () => {}, + ) {} - public get x() { - return this._x; - } + public get x() { + return this._x; + } - public set x(x: number) { - const oldRect = this.clone(); - this._x = x; - this.onChanged(oldRect); - } + public set x(x: number) { + const oldRect = this.clone(); + this._x = x; + this.onChanged(oldRect); + } - public get y() { - return this._y; - } + public get y() { + return this._y; + } - public set y(y: number) { - const oldRect = this.clone(); - this._y = y; - this.onChanged(oldRect); - } + public set y(y: number) { + const oldRect = this.clone(); + this._y = y; + this.onChanged(oldRect); + } - public get width() { - return this._width; - } + public get width() { + return this._width; + } - public set width(width: number) { - const oldRect = this.clone(); - this._width = width; - this.onChanged(oldRect); - } + public set width(width: number) { + const oldRect = this.clone(); + this._width = width; + this.onChanged(oldRect); + } - public get height() { - return this._height; - } + public get height() { + return this._height; + } - public set height(height: number) { - const oldRect = this.clone(); - this._height = height; - this.onChanged(oldRect); - } + public set height(height: number) { + const oldRect = this.clone(); + this._height = height; + this.onChanged(oldRect); + } - public get top() { - return this.y; - } + public get top() { + return this.y; + } - public get bottom() { - return this.y + this.height; - } + public get bottom() { + return this.y + this.height; + } - public get left() { - return this.x; - } + public get left() { + return this.x; + } - public get right() { - return this.x + this.width; - } + public get right() { + return this.x + this.width; + } - public clone() { - return new QmlRect( - this._x, - this._y, - this._width, - this._height, - ); - } + public clone() { + return new MockQmlRect( + this._x, + this._y, + this._width, + this._height, + ); } } diff --git a/src/tests/utils/mocks/QmlSize.ts b/src/tests/utils/mocks/QmlSize.ts index 1a6b257..5600a39 100644 --- a/src/tests/utils/mocks/QmlSize.ts +++ b/src/tests/utils/mocks/QmlSize.ts @@ -1,8 +1,6 @@ -namespace Mocks { - export class QmlSize { - constructor( - public width: number, - public height: number, - ) {} - } +class MockQmlSize { + constructor( + public width: number, + public height: number, + ) {} } diff --git a/src/tests/utils/mocks/QmlTimer.ts b/src/tests/utils/mocks/QmlTimer.ts index 2614c69..1b9aad7 100644 --- a/src/tests/utils/mocks/QmlTimer.ts +++ b/src/tests/utils/mocks/QmlTimer.ts @@ -1,13 +1,11 @@ -namespace Mocks { - export class QmlTimer { - public interval: number = 0; - public readonly triggered: QSignal<[]> = new QSignal(); +class MockQmlTimer { + public interval = 0; + public readonly triggered = new MockQSignal(); - public restart() { - // no need to wait in tests, just fire immediately - this.triggered.fire(); - }; + public restart() { + // no need to wait in tests, just fire immediately + this.triggered.fire(); + }; - public destroy() {} - } + public destroy() {} } diff --git a/src/tests/utils/mocks/Qt.ts b/src/tests/utils/mocks/Qt.ts index d349c18..fbee9c4 100644 --- a/src/tests/utils/mocks/Qt.ts +++ b/src/tests/utils/mocks/Qt.ts @@ -1,21 +1,19 @@ -namespace Mocks { - export class Qt { - public point(x: number, y: number) { - return new Mocks.QmlPoint(x, y); - } +class MockQt { + public point(x: number, y: number) { + return new MockQmlPoint(x, y); + } - public rect(x: number, y: number, width: number, height: number) { - return new Mocks.QmlRect(x, y, width, height); - } + public rect(x: number, y: number, width: number, height: number) { + return new MockQmlRect(x, y, width, height); + } - public createQmlObject(qml: string, parent: QmlObject) { - if (qml.includes("Timer")) { - return new QmlTimer(); - } else if (qml.includes("ShortcutHandler")) { - return new ShortcutHandler(); - } else { - assert(false, "Unexpected qml string: " + qml); - } + public createQmlObject(qml: string, parent: QmlObject) { + if (qml.includes("Timer")) { + return new MockQmlTimer(); + } else if (qml.includes("ShortcutHandler")) { + return new MockShortcutHandler(); + } else { + assert(false, "Unexpected qml string: " + qml); } } } diff --git a/src/tests/utils/mocks/ShortcutHandler.ts b/src/tests/utils/mocks/ShortcutHandler.ts index 78ec057..fb85b46 100644 --- a/src/tests/utils/mocks/ShortcutHandler.ts +++ b/src/tests/utils/mocks/ShortcutHandler.ts @@ -1,7 +1,5 @@ -namespace Mocks { - export class ShortcutHandler { - public readonly activated: QSignal<[]> = new QSignal(); +class MockShortcutHandler { + public readonly activated: MockQSignal<[]> = new MockQSignal(); - public destroy() {} - } + public destroy() {} } diff --git a/src/tests/utils/mocks/Workspace.ts b/src/tests/utils/mocks/Workspace.ts index fd2f2e6..573fc09 100644 --- a/src/tests/utils/mocks/Workspace.ts +++ b/src/tests/utils/mocks/Workspace.ts @@ -1,31 +1,29 @@ -namespace Mocks { - export class Workspace { - public activities = ["test-activity"]; - public desktops = [{id: "desktop1"}, {id: "desktop2"}]; - public currentDesktop = this.desktops[0]; - public currentActivity = this.activities[0]; - public activeScreen = {}; - public windows = []; - public cursorPos = new QmlPoint(0, 0); +class MockWorkspace { + public activities = ["test-activity"]; + public desktops = [{id: "desktop1"}, {id: "desktop2"}]; + public currentDesktop = this.desktops[0]; + public currentActivity = this.activities[0]; + public activeScreen = {}; + public windows = []; + public cursorPos = new MockQmlPoint(0, 0); - public activeWindow: any; + public activeWindow: any; - public readonly currentDesktopChanged = new Mocks.QSignal<[]>(); - public readonly windowAdded = new Mocks.QSignal<[KwinClient]>(); - public readonly windowRemoved = new Mocks.QSignal<[KwinClient]>(); - public readonly windowActivated = new Mocks.QSignal<[KwinClient]>(); - public readonly screensChanged = new Mocks.QSignal<[]>(); - public readonly activitiesChanged = new Mocks.QSignal<[]>(); - public readonly desktopsChanged = new Mocks.QSignal<[]>(); - public readonly currentActivityChanged = new Mocks.QSignal<[]>(); - public readonly virtualScreenSizeChanged = new Mocks.QSignal<[]>(); + public readonly currentDesktopChanged = new MockQSignal<[]>(); + public readonly windowAdded = new MockQSignal<[MockKwinClient]>(); + public readonly windowRemoved = new MockQSignal<[MockKwinClient]>(); + public readonly windowActivated = new MockQSignal<[MockKwinClient]>(); + public readonly screensChanged = new MockQSignal<[]>(); + public readonly activitiesChanged = new MockQSignal<[]>(); + public readonly desktopsChanged = new MockQSignal<[]>(); + public readonly currentActivityChanged = new MockQSignal<[]>(); + public readonly virtualScreenSizeChanged = new MockQSignal<[]>(); - public clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop) { - return new QmlRect(0, 0, Mocks.screenWidth, Mocks.screenHeight); - } + public clientArea(option: ClientAreaOption, output: Output, kwinDesktop: KwinDesktop) { + return new MockQmlRect(0, 0, screenWidth, screenHeight); + } - public createWindow(kwinClient: KwinClient) { - this.windowActivated.fire(kwinClient); - } + public createWindow(kwinClient: MockKwinClient) { + this.windowActivated.fire(kwinClient); } } diff --git a/src/tests/utils/mocks/constants.ts b/src/tests/utils/mocks/constants.ts deleted file mode 100644 index 9e4644d..0000000 --- a/src/tests/utils/mocks/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -namespace Mocks { - export const screenWidth = 800; - export const screenHeight = 600; -}