tests: introduce randomness in mocks
This commit is contained in:
@@ -90,28 +90,46 @@ class MockKwinClient {
|
||||
|
||||
public set fullScreen(fullScreen: boolean) {
|
||||
const oldFullScreen = this._fullScreen;
|
||||
|
||||
this.hasBorder = !fullScreen;
|
||||
|
||||
this._fullScreen = fullScreen;
|
||||
this.fullScreenChanged.fire();
|
||||
|
||||
if (oldFullScreen && !fullScreen) {
|
||||
// when switching from full-screen to windowed, Kwin sometimes first adds the frame before changing the frameGeometry to the final value
|
||||
this.frameGeometry = new MockQmlRect(
|
||||
-MockKwinClient.borderThickness,
|
||||
-MockKwinClient.borderThickness,
|
||||
screenWidth + 2 * MockKwinClient.borderThickness,
|
||||
screenHeight + 2 * MockKwinClient.borderThickness,
|
||||
);
|
||||
}
|
||||
|
||||
this.windowed = !fullScreen;
|
||||
if (fullScreen) {
|
||||
this.frameGeometry = new MockQmlRect(0, 0, screenWidth, screenHeight);
|
||||
} else {
|
||||
this.frameGeometry = this.windowedFrameGeometry;
|
||||
}
|
||||
runReorder(
|
||||
() => {
|
||||
this._fullScreen = fullScreen;
|
||||
this.fullScreenChanged.fire();
|
||||
},
|
||||
() => {
|
||||
if (oldFullScreen && !fullScreen) {
|
||||
// when switching from full-screen to windowed, Kwin sometimes first adds the frame before changing the frameGeometry to the final value
|
||||
runOneOf(
|
||||
() => {
|
||||
this.frameGeometry = new MockQmlRect(
|
||||
0,
|
||||
0,
|
||||
screenWidth + 2 * MockKwinClient.borderThickness,
|
||||
screenHeight + 2 * MockKwinClient.borderThickness,
|
||||
);
|
||||
},
|
||||
() => {
|
||||
this.frameGeometry = new MockQmlRect(
|
||||
-MockKwinClient.borderThickness,
|
||||
-MockKwinClient.borderThickness,
|
||||
screenWidth + 2 * MockKwinClient.borderThickness,
|
||||
screenHeight + 2 * MockKwinClient.borderThickness,
|
||||
);
|
||||
},
|
||||
() => {},
|
||||
);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
this.windowed = !fullScreen;
|
||||
if (fullScreen) {
|
||||
this.frameGeometry = new MockQmlRect(0, 0, screenWidth, screenHeight);
|
||||
} else {
|
||||
this.frameGeometry = this.windowedFrameGeometry;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public get frameGeometry() {
|
||||
|
||||
26
src/tests/utils/random.ts
Normal file
26
src/tests/utils/random.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
function runOneOf(...fs: (() => void)[]) {
|
||||
randomItem(fs)();
|
||||
}
|
||||
|
||||
function runReorder(...fs: (() => void)[]) {
|
||||
shuffle(fs);
|
||||
for (const f of fs) {
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
function randomInt(n: number) {
|
||||
return Math.floor(Math.random() * n);
|
||||
}
|
||||
|
||||
function randomItem<T>(items: T[]): T {
|
||||
return items[randomInt(items.length)];
|
||||
}
|
||||
|
||||
function shuffle(items: any[]) {
|
||||
for (let n = items.length; n > 1; n--) {
|
||||
const i = n-1;
|
||||
const j = randomInt(n);
|
||||
[items[i], items[j]] = [items[j], items[i]];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user